diff --git a/v2/build-system.jam b/v2/build-system.jam index 71a3b0e3a..fd57c1536 100644 --- a/v2/build-system.jam +++ b/v2/build-system.jam @@ -414,6 +414,8 @@ local rule load-configuration-files initialize-config-module project-config : $(file:D) ; load-config project-config : project-config.jam : $(file:D) ; } + + project.end-load ; } diff --git a/v2/build/project.jam b/v2/build/project.jam index 48a61d1a3..4a8db2155 100644 --- a/v2/build/project.jam +++ b/v2/build/project.jam @@ -280,6 +280,8 @@ local rule load-jamfile ( dir : jamfile-module ) # second attempt from messing things up. if ! $(jamfile-module) in $(.jamfile-modules) { + local previous-project = $(.current-project) ; + # Initialize the Jamfile module before loading. initialize $(jamfile-module) : [ path.parent $(jamfile-to-load) ] : $(jamfile-to-load:BS) ; @@ -315,6 +317,8 @@ local rule load-jamfile ( dir : jamfile-module ) : actual value $(.current-project) ; } + end-load $(previous-project) ; + if $(.global-build-dir) { if [ attribute $(jamfile-module) location ] && ! [ attribute @@ -336,6 +340,31 @@ local rule load-jamfile ( dir : jamfile-module ) } +# Called when done loading a project module. Restores the current project to its +# previous value and does some additional checking to make sure our 'currently +# loaded project' identifier does not get left with an invalid value. +# +rule end-load ( previous-project ? ) +{ + if ! $(.current-project) + { + import errors ; + errors.error Ending project loading requested when there was no project + currently being loaded. ; + } + + if ! $(previous-project) && $(.saved-current-project) + { + import errors ; + errors.error Ending project loading requested with no 'previous project' + when there were other projects still marked as being loaded + recursively. ; + } + + .current-project = $(previous-project) ; +} + + rule mark-as-user ( module-name ) { if USER_MODULE in [ RULENAMES ] @@ -702,6 +731,12 @@ class project-attributes # rule current ( ) { + if ! $(.current-project) + { + import errors ; + errors.error Reference to the project currently being loaded requested + when there was no project module being loaded. ; + } return $(.current-project) ; } @@ -757,7 +792,6 @@ rule target ( project-module ) # rule use ( id : location ) { - local saved-project = $(.current-project) ; local project-module = [ project.load $(location) ] ; local declared-id = [ project.attribute $(project-module) id ] ; @@ -774,7 +808,6 @@ rule use ( id : location ) } $(id).jamfile-module = $(project-module) ; } - .current-project = $(saved-project) ; } diff --git a/v2/test/indirect_conditional.py b/v2/test/indirect_conditional.py index 7011e662a..52e3bf67d 100644 --- a/v2/test/indirect_conditional.py +++ b/v2/test/indirect_conditional.py @@ -64,8 +64,10 @@ rule a3-rule-2 ( properties * ) def test_glob_in_indirect_conditional(): """ - Regression test: glob run inside an indirect conditional should work in - the correct project context, i.e. in the correct folder. + Regression test: project-rules.glob rule run from inside an indirect + conditional should report an error as it depends on the 'currently loaded + project' concept and indirect conditional rules get called only after all + the project modules have already finished loading. """ t = BoostBuild.Tester() @@ -91,8 +93,10 @@ rule print-my-sources ( properties * ) lib bar : bar.cpp : @print-my-sources ; """) - t.run_build_system() - t.expect_output_lines("My sources:\nbar.cpp") + t.run_build_system(status=1) + t.expect_output_lines(["My sources:", "bar.cpp"], False) + t.expect_output_lines("error: Reference to the project currently being " + "loaded requested when there was no project module being loaded.") t.cleanup()