2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-16 01:12:13 +00:00

Make default values of features really work. Now a feature with

default value will always be present in build properties of all
main targets. The change moves adding default value into main
targets --- it was done at the top level.

* new/build-request.jam
    (expand-no-defaults): No longer local.

* new/build-system.jam
    Use 'build-request.expand-no-defaults', not 'expand'.

* new/feature.jam
    (add-defaults): Tolerate conditional properties
        (e.g <variant>debug:<define>DEBUG)

* new/property-set.jam
    (property-set.add-defaults): New method.

* new/targets.jam
    (basic-target.final-properties): Add defaults.

* test/default_features.py: New test.


[SVN r17753]
This commit is contained in:
Vladimir Prus
2003-03-07 08:45:37 +00:00
parent 85e0c6668b
commit 3b46c3ac8a
13 changed files with 157 additions and 13 deletions

View File

@@ -21,7 +21,7 @@ local rule apply-to-property-set ( f property-set )
# expand the given build request by combining all property-sets which don't
# specify conflicting non-free features.
local rule expand-no-defaults ( property-sets * : feature-space ? )
rule expand-no-defaults ( property-sets * : feature-space ? )
{
feature-space ?= feature ;

View File

@@ -72,7 +72,7 @@ properties = [ $(build-request).get-at 2 ] ;
if $(properties)
{
expanded = [ build-request.expand $(properties) ] ;
expanded = [ build-request.expand-no-defaults $(properties) ] ;
}

View File

@@ -710,7 +710,13 @@ rule add-defaults ( properties * )
but \"$(v)\" appears to be the value of an un-expanded implicit feature ;
}
}
local missing = [ set.difference $(.all-features) : $(properties:G) ] ;
# We don't add default for elements with ":" inside. This catches:
# 1. Conditional properties --- we don't want <variant>debug:<define>DEBUG
# to be takes as specified value for <variant>
# 2. Free properties with ":" in values. We don't care, since free properties
# don't have defaults.
local xproperties = [ MATCH "^([^:]+)$" : $(properties) ] ;
local missing = [ set.difference $(.all-features) : $(xproperties:G) ] ;
return $(properties) [ defaults $(missing) ] ;
}
@@ -884,9 +890,9 @@ local rule __test__ ( )
: defaults <runtime-link> <define> <optimization>
;
assert.result <runtime-link>static <define>foobar <optimization>on <toolset>gcc <variant>debug
<stdlib>native <dummy>dummy1
: add-defaults <runtime-link>static <define>foobar <optimization>on
assert.result <runtime-link>static <define>foobar <optimization>on <toolset>gcc:<define>FOO
<toolset>gcc <variant>debug <stdlib>native <dummy>dummy1
: add-defaults <runtime-link>static <define>foobar <optimization>on <toolset>gcc:<define>FOO
;
assert.result <toolset>gcc <define>foo <stdlib>stlport <magic>3 <include>/path/to/stlport <define>MAGIC=3

View File

@@ -128,6 +128,17 @@ local rule property-set ( raw-properties * )
return $(self.run) ;
}
rule add-defaults ( )
{
if ! $(self.defaults)
{
self.defaults = [ property-set.create
[ feature.add-defaults $(self.raw) ] ] ;
}
return $(self.defaults) ;
}
rule as-path ( )
{
if ! $(self.as-path)

View File

@@ -516,6 +516,10 @@ rule basic-target ( name : project
# come from dependencies, the value is not target id, but rather
# virtual target names, so generators.construct can use them.
# defaults should be added as soon as possible. For example, conditionals
# might have "<variant>debug:..." and won't work if defaults are not
# applied.
rproperties = [ $(rproperties).add-defaults ] ;
rproperties = [ $(rproperties).evaluate-conditionals ] ;
rproperties =
@@ -563,7 +567,7 @@ rule basic-target ( name : project
{
if ! $(self.generated.$(property-set))
{
local rproperties = [ final-properties $(property-set) ] ;
local rproperties = [ final-properties $(property-set) ] ;
if $(rproperties[1]) != "@error"
{
local source-targets = [ generate-sources $(rproperties) ] ;

50
test/default_features.py Normal file
View File

@@ -0,0 +1,50 @@
#!/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.
# Test that features with default values are always present
# in build properties of any target.
from BoostBuild import Tester, List
t = Tester()
# Declare *non-propagated* feature foo.
t.write("project-root.jam", """
import feature : feature ;
feature foo : on off ;
""")
# Note that '<foo>on' won't be propagated
# to 'd/l'.
t.write("Jamfile", """
exe hello : hello.cpp d/l ;
""")
t.write("hello.cpp", """
void foo();
int main()
{
foo();
return 1;
}
""")
t.write("d/Jamfile", """
lib l : l.cpp : <foo>on:<define>FOO ;
""")
t.write("l.cpp", """
#ifdef FOO
void foo() {}
#endif
""")
t.run_build_system()
t.expect_addition("bin/$toolset/debug/hello.exe")
t.cleanup()

View File

@@ -84,6 +84,7 @@ tests = [ "project_test1",
"alias",
"alternatives",
"unused",
"default_features",
]
if os.name == 'posix':

View File

@@ -21,7 +21,7 @@ local rule apply-to-property-set ( f property-set )
# expand the given build request by combining all property-sets which don't
# specify conflicting non-free features.
local rule expand-no-defaults ( property-sets * : feature-space ? )
rule expand-no-defaults ( property-sets * : feature-space ? )
{
feature-space ?= feature ;

View File

@@ -710,7 +710,13 @@ rule add-defaults ( properties * )
but \"$(v)\" appears to be the value of an un-expanded implicit feature ;
}
}
local missing = [ set.difference $(.all-features) : $(properties:G) ] ;
# We don't add default for elements with ":" inside. This catches:
# 1. Conditional properties --- we don't want <variant>debug:<define>DEBUG
# to be takes as specified value for <variant>
# 2. Free properties with ":" in values. We don't care, since free properties
# don't have defaults.
local xproperties = [ MATCH "^([^:]+)$" : $(properties) ] ;
local missing = [ set.difference $(.all-features) : $(xproperties:G) ] ;
return $(properties) [ defaults $(missing) ] ;
}
@@ -884,9 +890,9 @@ local rule __test__ ( )
: defaults <runtime-link> <define> <optimization>
;
assert.result <runtime-link>static <define>foobar <optimization>on <toolset>gcc <variant>debug
<stdlib>native <dummy>dummy1
: add-defaults <runtime-link>static <define>foobar <optimization>on
assert.result <runtime-link>static <define>foobar <optimization>on <toolset>gcc:<define>FOO
<toolset>gcc <variant>debug <stdlib>native <dummy>dummy1
: add-defaults <runtime-link>static <define>foobar <optimization>on <toolset>gcc:<define>FOO
;
assert.result <toolset>gcc <define>foo <stdlib>stlport <magic>3 <include>/path/to/stlport <define>MAGIC=3

View File

@@ -128,6 +128,17 @@ local rule property-set ( raw-properties * )
return $(self.run) ;
}
rule add-defaults ( )
{
if ! $(self.defaults)
{
self.defaults = [ property-set.create
[ feature.add-defaults $(self.raw) ] ] ;
}
return $(self.defaults) ;
}
rule as-path ( )
{
if ! $(self.as-path)

View File

@@ -516,6 +516,10 @@ rule basic-target ( name : project
# come from dependencies, the value is not target id, but rather
# virtual target names, so generators.construct can use them.
# defaults should be added as soon as possible. For example, conditionals
# might have "<variant>debug:..." and won't work if defaults are not
# applied.
rproperties = [ $(rproperties).add-defaults ] ;
rproperties = [ $(rproperties).evaluate-conditionals ] ;
rproperties =
@@ -563,7 +567,7 @@ rule basic-target ( name : project
{
if ! $(self.generated.$(property-set))
{
local rproperties = [ final-properties $(property-set) ] ;
local rproperties = [ final-properties $(property-set) ] ;
if $(rproperties[1]) != "@error"
{
local source-targets = [ generate-sources $(rproperties) ] ;

View File

@@ -0,0 +1,50 @@
#!/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.
# Test that features with default values are always present
# in build properties of any target.
from BoostBuild import Tester, List
t = Tester()
# Declare *non-propagated* feature foo.
t.write("project-root.jam", """
import feature : feature ;
feature foo : on off ;
""")
# Note that '<foo>on' won't be propagated
# to 'd/l'.
t.write("Jamfile", """
exe hello : hello.cpp d/l ;
""")
t.write("hello.cpp", """
void foo();
int main()
{
foo();
return 1;
}
""")
t.write("d/Jamfile", """
lib l : l.cpp : <foo>on:<define>FOO ;
""")
t.write("l.cpp", """
#ifdef FOO
void foo() {}
#endif
""")
t.run_build_system()
t.expect_addition("bin/$toolset/debug/hello.exe")
t.cleanup()

View File

@@ -84,6 +84,7 @@ tests = [ "project_test1",
"alias",
"alternatives",
"unused",
"default_features",
]
if os.name == 'posix':