From b99efeaceacb6880773ab0b3d1bcb05724ba00dc Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Mon, 21 Jul 2003 06:21:27 +0000 Subject: [PATCH] Work on BB43 (hang on loop in main target references). * new/targets.jam (start-building, end-building): New rules. (main-target.generate): Call the above rules. * test/loop.py: New test. [SVN r19241] --- new/targets.jam | 29 +++++++++++++++++++++++++++++ test/loop.py | 28 ++++++++++++++++++++++++++++ test/test_all.py | 1 + v2/build/targets.jam | 29 +++++++++++++++++++++++++++++ v2/test/loop.py | 28 ++++++++++++++++++++++++++++ v2/test/test_all.py | 1 + 6 files changed, 116 insertions(+) create mode 100644 test/loop.py create mode 100644 v2/test/loop.py diff --git a/new/targets.jam b/new/targets.jam index ad740735c..bf9486f02 100644 --- a/new/targets.jam +++ b/new/targets.jam @@ -298,6 +298,32 @@ rule project-target ( name : project : requirements * : default-build * ) } class project-target : abstract-target ; + + +# Helper rules to detect cycles in main target references +local rule start-building ( main-target-instance ) +{ + if $(main-target-instance) in $(.targets-being-built) + { + local names ; + for local t in $(.targets-being-built) $(main-target-instance) + { + names += [ $(t).full-name ] ; + } + + errors.error "Recursion in main target references" + : "the following target are being built currently:" + : $(names) ; + } + .targets-being-built += $(main-target-instance) ; +} + +local rule end-building ( main-target-instance ) +{ + .targets-being-built = $(.targets-being-built[1--2]) ; +} + + # A named top-level target in Jamfile rule main-target ( name : project ) { @@ -309,6 +335,7 @@ rule main-target ( name : project ) import sequence ; import print ; import build-request feature property-set ; + import targets : start-building end-building ; # Add a new alternative for this target rule add-alternative ( target ) @@ -407,6 +434,7 @@ rule main-target ( name : project ) # Returns the result of calling 'generate' on that alternative. rule generate ( property-set ) { + start-building $(__name__) ; local all-property-sets = [ apply-default-build $(property-set) ] ; local usage-requirements = [ property-set.empty ] ; local result ; @@ -418,6 +446,7 @@ rule main-target ( name : project ) usage-requirements = [ $(usage-requirements).add $(r[1]) ] ; result += $(r[2-]) ; } + end-building $(__name__) ; return $(usage-requirements) $(result) ; } diff --git a/test/loop.py b/test/loop.py new file mode 100644 index 000000000..558e99cf8 --- /dev/null +++ b/test/loop.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +# Copyright (C) Vladimir Prus 2003. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +from BoostBuild import Tester, List +from string import find + +t = Tester() + + +t.write("project-root.jam", "") +t.write("Jamfile", """ + +lib main : main.cpp l ; +lib l : l.cpp main ; +""") + +t.write("main.cpp", "") +t.write("l.cpp", "") + +t.run_build_system("--no-error-backtrace", status=1) +t.fail_test(find(t.stdout(), "error: Recursion in main target references") == -1) +t.fail_test(find(t.stdout(), "./main ./l ./main") == -1) + +t.cleanup() diff --git a/test/test_all.py b/test/test_all.py index d3a3fde89..078e26804 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -100,6 +100,7 @@ tests = [ "project_test1", "inline", "conditionals2", "property_expansion", + "loop", ] if os.name == 'posix': diff --git a/v2/build/targets.jam b/v2/build/targets.jam index ad740735c..bf9486f02 100644 --- a/v2/build/targets.jam +++ b/v2/build/targets.jam @@ -298,6 +298,32 @@ rule project-target ( name : project : requirements * : default-build * ) } class project-target : abstract-target ; + + +# Helper rules to detect cycles in main target references +local rule start-building ( main-target-instance ) +{ + if $(main-target-instance) in $(.targets-being-built) + { + local names ; + for local t in $(.targets-being-built) $(main-target-instance) + { + names += [ $(t).full-name ] ; + } + + errors.error "Recursion in main target references" + : "the following target are being built currently:" + : $(names) ; + } + .targets-being-built += $(main-target-instance) ; +} + +local rule end-building ( main-target-instance ) +{ + .targets-being-built = $(.targets-being-built[1--2]) ; +} + + # A named top-level target in Jamfile rule main-target ( name : project ) { @@ -309,6 +335,7 @@ rule main-target ( name : project ) import sequence ; import print ; import build-request feature property-set ; + import targets : start-building end-building ; # Add a new alternative for this target rule add-alternative ( target ) @@ -407,6 +434,7 @@ rule main-target ( name : project ) # Returns the result of calling 'generate' on that alternative. rule generate ( property-set ) { + start-building $(__name__) ; local all-property-sets = [ apply-default-build $(property-set) ] ; local usage-requirements = [ property-set.empty ] ; local result ; @@ -418,6 +446,7 @@ rule main-target ( name : project ) usage-requirements = [ $(usage-requirements).add $(r[1]) ] ; result += $(r[2-]) ; } + end-building $(__name__) ; return $(usage-requirements) $(result) ; } diff --git a/v2/test/loop.py b/v2/test/loop.py new file mode 100644 index 000000000..558e99cf8 --- /dev/null +++ b/v2/test/loop.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +# Copyright (C) Vladimir Prus 2003. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +from BoostBuild import Tester, List +from string import find + +t = Tester() + + +t.write("project-root.jam", "") +t.write("Jamfile", """ + +lib main : main.cpp l ; +lib l : l.cpp main ; +""") + +t.write("main.cpp", "") +t.write("l.cpp", "") + +t.run_build_system("--no-error-backtrace", status=1) +t.fail_test(find(t.stdout(), "error: Recursion in main target references") == -1) +t.fail_test(find(t.stdout(), "./main ./l ./main") == -1) + +t.cleanup() diff --git a/v2/test/test_all.py b/v2/test/test_all.py index d3a3fde89..078e26804 100644 --- a/v2/test/test_all.py +++ b/v2/test/test_all.py @@ -100,6 +100,7 @@ tests = [ "project_test1", "inline", "conditionals2", "property_expansion", + "loop", ] if os.name == 'posix':