From 74468b59ac4feac8b074b9db1971e125bdf64165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Sun, 5 Aug 2012 15:12:58 +0000 Subject: [PATCH] Made Boost Build clear its 'current project' reference after it is done with loading project modules. Any request for the 'current project' reference when there is no project module currently being loaded will now be treated as an error. Updated the related indirect_conditional.py internal Boost Build test case accordingly. Additional implementation notes: - internal worker project.load-jamfile() rule now resets the current project when done - project.use() no longer needs to reset the current project since project.load-jamfile() does that now [SVN r79874] --- v2/build-system.jam | 2 ++ v2/build/project.jam | 37 +++++++++++++++++++++++++++++++-- v2/test/indirect_conditional.py | 12 +++++++---- 3 files changed, 45 insertions(+), 6 deletions(-) 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()