1 # Copyright 2002 Dave Abrahams
2 # Distributed under the Boost Software License, Version 1.0.
3 # (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
15 # Transform property-set by applying f to each component property.
17 local rule apply-to-property-set ( f property-set )
19 local properties = [ feature.split $(property-set) ] ;
20 return [ string.join [ $(f) $(properties) ] : / ] ;
24 # Expand the given build request by combining all property-sets which do not
25 # specify conflicting non-free features. Expects all the project files to
28 rule expand-no-defaults ( property-sets * )
30 # First make all features and subfeatures explicit.
31 local expanded-property-sets = [ sequence.transform apply-to-property-set
32 feature.expand-subfeatures : $(property-sets) ] ;
34 # Now combine all of the expanded property-sets
35 local product = [ x-product $(expanded-property-sets) : $(feature-space) ] ;
41 # Update the list of expected conflicts based on the new
44 local rule remove-conflicts ( conflicts * : features * )
47 for local c in $(conflicts)
49 if ! [ set.intersection [ regex.split $(c) "/" ] : $(features) ]
58 # Implementation of x-product, below. Expects all the project files to already
61 local rule x-product-aux ( property-sets + )
64 local p = [ feature.split $(property-sets[1]) ] ;
65 local f = [ set.difference $(p:G) : [ feature.free-features ] ] ;
67 local extra-conflicts ;
69 # No conflict with things used at a higher level?
70 if ! [ set.intersection $(f) : $(x-product-used) ]
72 local x-product-seen ;
73 local x-product-conflicts =
74 [ remove-conflicts $(x-product-conflicts) : $(f) ] ;
76 # Do not mix in any conflicting features.
77 local x-product-used = $(x-product-used) $(f) ;
79 if $(property-sets[2])
81 local rest = [ x-product-aux $(property-sets[2-]) ] ;
82 result = $(property-sets[1])/$(rest) ;
84 if ! $(x-product-conflicts)
86 result ?= $(property-sets[1]) ;
90 # If we did not encounter a conflicting feature lower down, do not
92 if ! [ set.intersection $(f) : $(x-product-seen) ]
93 || [ remove-conflicts $(x-product-conflicts) : $(x-product-seen) ]
99 # A property is only allowed to be absent if it conflicts
100 # with either a higher or lower layer. We don't need to
101 # bother setting this if we already know that we don't need
103 extra-conflicts = $(f:J=/) ;
106 seen = $(x-product-seen) ;
109 if $(property-sets[2])
111 # Lower layers expansion must conflict with this
112 local x-product-conflicts = $(x-product-conflicts) $(extra-conflicts) ;
114 result += [ x-product-aux $(property-sets[2-]) ] ;
117 # Note that we have seen these features so that higher levels will recurse
118 # again without them set.
119 x-product-seen += $(f) $(seen) ;
124 # Return the cross-product of all elements of property-sets, less any that would
125 # contain conflicting values for single-valued features. Expects all the project
126 # files to already be loaded.
129 # Returns all maximum non-conflicting subsets of property-sets.
130 # The result is a list of all property-sets p such that
131 # 1. p is composed by joining a subset of property-sets without removing
133 # 2. p contains at most one instance of every single-valued feature
134 # 3. Adding any additional element of property-sets to p be would
136 local rule x-product ( property-sets * )
138 if $(property-sets).non-empty
140 # Prepare some "scoped globals" that can be used by the implementation
141 # function, x-product-aux.
142 local x-product-seen x-product-used x-product-conflicts ;
143 return [ x-product-aux $(property-sets) : $(feature-space) ] ;
145 # Otherwise return empty.
149 # Returns true if either 'v' or the part of 'v' before the first '-' symbol is
150 # an implicit value. Expects all the project files to already be loaded.
152 local rule looks-like-implicit-value ( v )
154 if [ feature.is-implicit-value $(v) ]
160 local split = [ regex.split $(v) - ] ;
161 if [ feature.is-implicit-value $(split[1]) ]
169 # Takes the command line tokens (such as taken from the ARGV rule) and
170 # constructs a build request from them. Returns a vector of two vectors (where
171 # "vector" means container.jam's "vector"). First is the set of targets
172 # specified in the command line, and second is the set of requested build
173 # properties. Expects all the project files to already be loaded.
175 rule from-command-line ( command-line * )
180 command-line = $(command-line[2-]) ;
182 for local e in $(command-line)
188 else if ! [ MATCH ^(-) : $(e) ]
190 # Build request spec either has "=" in it or completely consists of
191 # implicit feature values.
192 local fs = feature-space ;
193 if [ MATCH "(.*=.*)" : $(e) ]
194 || [ looks-like-implicit-value $(e:D=) : $(feature-space) ]
203 else if [ MATCH "^(-[-ldjfsto])$" : $(e) ]
209 [ new vector $(targets) ]
210 [ new vector $(properties) ] ] ;
214 # Converts a list of elements of command line build request specification into internal
215 # form. Expects all the project files to already be loaded.
217 rule convert-command-line-elements ( elements * )
220 for local e in $(elements)
222 result += [ convert-command-line-element $(e) ] ;
228 # Converts one element of command line build request specification into internal
230 local rule convert-command-line-element ( e )
233 local parts = [ regex.split $(e) "/" ] ;
236 local p = $(parts[1]) ;
237 local m = [ MATCH "([^=]*)=(.*)" : $(p) ] ;
244 values = [ regex.split $(m[2]) "," ] ;
245 lresult = <$(feature)>$(values) ;
249 lresult = [ regex.split $(p) "," ] ;
252 if $(feature) && free in [ feature.attributes <$(feature)> ]
254 # If we have free feature, then the value is everything
255 # until the end of the command line token. Slashes in
256 # the following string are not taked to mean separation
257 # of properties. Commas are also not interpreted specially.
258 values = $(values:J=,) ;
259 values = $(values) $(parts[2-]) ;
260 values = $(values:J=/) ;
262 # Optional free features will ignore empty value arguments.
263 if optional in [ feature.attributes <$(feature)> ]
265 for local v in $(values)
269 lresult += <$(feature)>$(v) ;
275 lresult = <$(feature)>$(values) ;
280 if ! [ MATCH (.*-.*) : $(p) ]
282 # property.validate cannot handle subfeatures, so we avoid the check
284 for local p in $(lresult)
286 property.validate $(p) : $(feature-space) ;
294 result = $(lresult) ;
298 result = $(result)/$(lresult) ;
302 parts = $(parts[2-]) ;
314 feature.prepare-test build-request-test-temp ;
316 import build-request ;
317 import build-request : expand-no-defaults : build-request.expand-no-defaults ;
318 import errors : try catch ;
319 import feature : feature subfeature ;
321 feature toolset : gcc msvc borland : implicit ;
322 subfeature toolset gcc : version : 2.95.2 2.95.3 2.95.4
323 3.0 3.0.1 3.0.2 : optional ;
325 feature variant : debug release : implicit composite ;
326 feature inlining : on off ;
327 feature "include" : : free ;
329 feature stdlib : native stlport : implicit ;
331 feature runtime-link : dynamic static : symmetric ;
333 # Empty build requests should expand to empty.
335 : build-request.expand-no-defaults ;
338 <toolset>gcc/<toolset-gcc:version>3.0.1/<stdlib>stlport/<variant>debug
339 <toolset>msvc/<stdlib>stlport/<variant>debug
340 <toolset>msvc/<variant>debug
341 : build-request.expand-no-defaults gcc-3.0.1/stlport msvc/stlport msvc debug ;
344 <toolset>gcc/<toolset-gcc:version>3.0.1/<stdlib>stlport/<variant>debug
345 <toolset>msvc/<variant>debug
346 <variant>debug/<toolset>msvc/<stdlib>stlport
347 : build-request.expand-no-defaults gcc-3.0.1/stlport msvc debug msvc/stlport ;
350 <toolset>gcc/<toolset-gcc:version>3.0.1/<stdlib>stlport/<variant>debug/<inlining>off
351 <toolset>gcc/<toolset-gcc:version>3.0.1/<stdlib>stlport/<variant>release/<inlining>off
352 : build-request.expand-no-defaults gcc-3.0.1/stlport debug release <inlining>off ;
355 <include>a/b/c/<toolset>gcc/<toolset-gcc:version>3.0.1/<stdlib>stlport/<variant>debug/<include>x/y/z
356 <include>a/b/c/<toolset>msvc/<stdlib>stlport/<variant>debug/<include>x/y/z
357 <include>a/b/c/<toolset>msvc/<variant>debug/<include>x/y/z
358 : build-request.expand-no-defaults <include>a/b/c gcc-3.0.1/stlport msvc/stlport msvc debug <include>x/y/z ;
364 r = [ build-request.from-command-line bjam gcc/debug runtime-link=dynamic/static ] ;
365 build-request.convert-command-line-elements [ $(r).get-at 2 ] ;
367 catch \"static\" is not an implicit feature value ;
369 r = [ build-request.from-command-line bjam debug runtime-link=dynamic ] ;
370 assert.equal [ $(r).get-at 1 ] : ;
371 assert.equal [ $(r).get-at 2 ] : debug runtime-link=dynamic ;
374 [ build-request.convert-command-line-elements debug runtime-link=dynamic ]
375 : debug <runtime-link>dynamic ;
377 r = [ build-request.from-command-line bjam -d2 --debug debug target runtime-link=dynamic ] ;
378 assert.equal [ $(r).get-at 1 ] : target ;
379 assert.equal [ $(r).get-at 2 ] : debug runtime-link=dynamic ;
382 [ build-request.convert-command-line-elements debug runtime-link=dynamic ]
383 : debug <runtime-link>dynamic ;
385 r = [ build-request.from-command-line bjam debug runtime-link=dynamic,static ] ;
386 assert.equal [ $(r).get-at 1 ] : ;
387 assert.equal [ $(r).get-at 2 ] : debug runtime-link=dynamic,static ;
390 [ build-request.convert-command-line-elements debug runtime-link=dynamic,static ]
391 : debug <runtime-link>dynamic <runtime-link>static ;
393 r = [ build-request.from-command-line bjam debug gcc/runtime-link=dynamic,static ] ;
394 assert.equal [ $(r).get-at 1 ] : ;
395 assert.equal [ $(r).get-at 2 ] : debug gcc/runtime-link=dynamic,static ;
398 [ build-request.convert-command-line-elements debug gcc/runtime-link=dynamic,static ]
399 : debug gcc/<runtime-link>dynamic gcc/<runtime-link>static ;
401 r = [ build-request.from-command-line bjam msvc gcc,borland/runtime-link=static ] ;
402 assert.equal [ $(r).get-at 1 ] : ;
403 assert.equal [ $(r).get-at 2 ] : msvc gcc,borland/runtime-link=static ;
406 [ build-request.convert-command-line-elements msvc gcc,borland/runtime-link=static ]
407 : msvc gcc/<runtime-link>static borland/<runtime-link>static ;
409 r = [ build-request.from-command-line bjam gcc-3.0 ] ;
410 assert.equal [ $(r).get-at 1 ] : ;
411 assert.equal [ $(r).get-at 2 ] : gcc-3.0 ;
414 [ build-request.convert-command-line-elements gcc-3.0 ]
417 feature.finish-test build-request-test-temp ;