1#!/usr/local/bin/python3.8
2
3# Copyright 2003 Vladimir Prus
4# Distributed under the Boost Software License, Version 1.0.
5# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6
7
8import BoostBuild
9
10t = BoostBuild.Tester(arguments=["--config="], pass_toolset=0)
11
12t.write("source.input", "")
13
14t.write("test-properties.jam", """
15import feature : feature ;
16import generators ;
17import toolset ;
18import type ;
19
20# We're not using the toolset at all, and we want to
21# suppress toolset initialization to avoid surprises.
22feature.extend toolset : null ;
23
24type.register CHECK : check ;
25type.register INPUT : input ;
26feature expected-define : : free ;
27feature unexpected-define : : free ;
28toolset.flags test-properties DEFINES : <define> ;
29toolset.flags test-properties EXPECTED : <expected-define> ;
30toolset.flags test-properties UNEXPECTED : <unexpected-define> ;
31generators.register-standard test-properties.check : INPUT : CHECK ;
32rule check ( target : source : properties * )
33{
34    local defines = [ on $(target) return $(DEFINES) ] ;
35    for local macro in [ on $(target) return $(EXPECTED) ]
36    {
37        if ! ( $(macro) in $(defines) )
38        {
39            EXIT expected $(macro) for $(target) in $(properties) : 1 ;
40        }
41    }
42    for local macro in [ on $(target) return $(UNEXPECTED) ]
43    {
44        if $(macro) in $(defines)
45        {
46            EXIT unexpected $(macro) for $(target) in $(properties) : 1 ;
47        }
48    }
49}
50actions check
51{
52    echo okay > $(<)
53}
54""")
55
56t.write("jamfile.jam", """
57import test-properties ;
58# See if default value of composite feature 'cf' will be expanded to
59# <define>CF_IS_OFF.
60check a : source.input : <expected-define>CF_IS_OFF ;
61
62# See if subfeature in requirements in expanded.
63check b : source.input : <cf>on-1
64    <expected-define>CF_1 <unexpected-define>CF_IS_OFF ;
65
66# See if conditional requirements are recursively expanded.
67check c : source.input : <toolset>null:<variant>release
68    <variant>release:<define>FOO <expected-define>FOO
69    ;
70
71# Composites specified in the default build should not
72# be expanded if they are overridden in the the requirements.
73check d : source.input : <cf>on <unexpected-define>CF_IS_OFF : <cf>off ;
74
75# Overriding a feature should clear subfeatures and
76# apply default values of subfeatures.
77check e : source.input : <cf>always
78    <unexpected-define>CF_IS_OFF <expected-define>CF_2 <unexpected-define>CF_1
79  : <cf>on-1  ;
80
81# Subfeatures should not be changed if the parent feature doesn't change
82check f : source.input : <cf>on <expected-define>CF_1 : <cf>on-1 ;
83
84# If a subfeature is not specific to the value of the parent feature,
85# then changing the parent value should not clear the subfeature.
86check g : source.input : <fopt>off <expected-define>FOPT_2 : <fopt>on-2 ;
87
88# If the default value of a composite feature adds an optional
89# feature which has a subfeature with a default, then that
90# default should be added.
91check h : source.input : <expected-define>CX_2 ;
92
93# If the default value of a feature is used, then the
94# default value of its subfeatures should also be used.
95check i : source.input : <expected-define>SF_1 ;
96
97# Subfeatures should be expanded when listed in a
98# target reference.
99check j-impl : source.input : <expected-define>CF_1 ;
100explicit j-impl ;
101alias j : j-impl/<cf>on-1 ;
102""")
103
104t.write("jamroot.jam", """
105import feature ;
106feature.feature cf : off on always : composite incidental ;
107feature.compose <cf>off : <define>CF_IS_OFF ;
108feature.subfeature cf on : version : 1 2 : composite optional incidental ;
109feature.compose <cf-on:version>1 : <define>CF_1 ;
110feature.subfeature cf always : version : 1 2 : composite incidental ;
111feature.compose <cf-always:version>1 : <define>CF_2 ;
112feature.feature fopt : on off : optional incidental ;
113feature.subfeature fopt : version : 1 2 : composite incidental ;
114feature.compose <fopt-version>2 : <define>FOPT_2 ;
115
116feature.feature cx1 : on : composite incidental ;
117feature.feature cx2 : on : optional incidental ;
118feature.subfeature cx2 on : sub : 1 : composite incidental ;
119feature.compose <cx1>on : <cx2>on ;
120feature.compose <cx2-on:sub>1 : <define>CX_2 ;
121
122feature.feature sf : a : incidental ;
123feature.subfeature sf a : sub : 1 : composite incidental ;
124feature.compose <sf-a:sub>1 : <define>SF_1 ;
125""")
126
127t.expand_toolset("jamfile.jam")
128
129t.run_build_system()
130t.expect_addition(["bin/debug/a.check",
131                   "bin/debug/b.check",
132                   "bin/null/release/c.check",
133                   "bin/debug/d.check",
134                   "bin/debug/e.check",
135                   "bin/debug/f.check",
136                   "bin/debug/g.check",
137                   "bin/debug/h.check",
138                   "bin/debug/i.check"])
139
140t.cleanup()
141