From 4c1960e7740e03f289009edd710f68fa35ebd8d8 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Tue, 7 Feb 2006 10:26:17 +0000 Subject: [PATCH] Implement 'indirect conditional requirements', which are simular to V1's convention that rules used in requiremenst are called to provide extra features. [SVN r32694] --- v2/build/targets.jam | 29 +++++++++++- v2/test/indirect_conditional.py | 84 +++++++++++++++++++++++++++++++++ v2/test/test_all.py | 1 + v2/tools/builtin.jam | 3 ++ 4 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 v2/test/indirect_conditional.py diff --git a/v2/build/targets.jam b/v2/build/targets.jam index f2dd0d986..b55cc9de3 100644 --- a/v2/build/targets.jam +++ b/v2/build/targets.jam @@ -79,6 +79,7 @@ import virtual-target ; import path ; import set ; import assert ; +import indirect ; # Base class for all abstract targets. class abstract-target @@ -934,23 +935,47 @@ rule common-properties2 ( build-request requirements ) local raw = [ $(build-request).raw ] ; raw = [ property.refine $(raw) : [ feature.expand [ $(requirements).non-conditional ] ] ] ; - + # We've collected properties that surely must be present in common # properties. We now try to figure out what other properties # should be added in order to satisfy rules (4)-(6) from the docs. local conditionals = [ $(requirements).conditional ] ; - local count = $(conditionals) and-once-more ; + # The 'count' variable has one element for each conditional feature + # and for each occurence of '' feature. + # It's used as a loop counter: for each iteration of the loop + # before we remove one element and the property set should + # stabilize before we've done. It's supposed to #conditionals iterations + # should be enough for properties to propagate along conditions in any + # direction. + local count = $(conditionals) + [ $(requirements).get ] + and-once-more ; local prev ; local current = $(raw) ; + # It's assumed that ordinary conditional requirements can't add + # properties, and that rules refered + # by properties can't add new + # properties. So the list of indirect conditionals + # does not change. + local indirect = [ $(requirements).get ] ; + indirect = [ MATCH @(.*) : $(indirect) ] ; + local ok ; while $(count) { # Evaluate conditionals in context of current properties local e = [ property.evaluate-conditionals-in-context $(conditionals) : $(current) ] ; + + # Evaluate indirect conditionals. + for local i in $(indirect) + { + e += [ indirect.call $(i) $(current) ] ; + } + if $(e) = $(prev) { # If we got the same result, we've found final properties. diff --git a/v2/test/indirect_conditional.py b/v2/test/indirect_conditional.py new file mode 100644 index 000000000..0b16b1b61 --- /dev/null +++ b/v2/test/indirect_conditional.py @@ -0,0 +1,84 @@ +#!/usr/bin/python + +# Copyright (C) Vladimir Prus 2006. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +from BoostBuild import Tester, List +import string + +t = Tester() + +t.write("Jamroot", """ +exe a1 : a1.cpp : @a1-rule ; + +rule a1-rule ( properties * ) +{ + if debug in $(properties) + { + return OK ; + } +} + +exe a2 : a2.cpp : @$(__name__).a2-rule debug:speed ; + +rule a2-rule ( properties * ) +{ + if speed in $(properties) + { + return OK ; + } +} + +exe a3 : a3.cpp : @$(__name__).a3-rule-1 @$(__name__).a3-rule-2 ; + +rule a3-rule-1 ( properties * ) +{ + if speed in $(properties) + { + return OK ; + } +} + +rule a3-rule-2 ( properties * ) +{ + if debug in $(properties) + { + return speed ; + } +} + +""") + +t.write("a1.cpp", """ +#ifdef OK +int main() {} +#endif + +""") + +t.write("a2.cpp", """ +#ifdef OK +int main() {} +#endif + +""") + +t.write("a3.cpp", """ +#ifdef OK +int main() {} +#endif + +""") + + + +t.run_build_system() + +t.expect_addition("bin/$toolset/debug/a1.exe") +t.expect_addition("bin/$toolset/debug/optimization-speed/a2.exe") +t.expect_addition("bin/$toolset/debug/optimization-speed/a3.exe") + +t.cleanup() + diff --git a/v2/test/test_all.py b/v2/test/test_all.py index 037bcb3e8..4cd502500 100644 --- a/v2/test/test_all.py +++ b/v2/test/test_all.py @@ -134,6 +134,7 @@ tests = [ "rebuilds", "project_root_rule", "resolution", "build_file", + "indirect_conditional", ] if os.name == 'posix': diff --git a/v2/tools/builtin.jam b/v2/tools/builtin.jam index 83c66a7ea..e3b3254f3 100644 --- a/v2/tools/builtin.jam +++ b/v2/tools/builtin.jam @@ -177,6 +177,9 @@ feature instruction-set : vr4100 vr4111 vr4120 vr4130 vr4300 vr5000 vr5400 vr5500 # : propagated optional ; + + +feature conditional : : incidental free ; # Windows-specific features