1 # Copyright 2002 Dave Abrahams
2 # Distributed under the Boost Software License, Version 1.0.
3 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.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 # Implementation of x-product, below. Expects all the project files to already
44 local rule x-product-aux ( property-sets + )
47 local p = [ feature.split $(property-sets[1]) ] ;
48 local f = [ set.difference $(p:G) : [ feature.free-features ] ] ;
50 # No conflict with things used at a higher level?
51 if ! [ set.intersection $(f) : $(x-product-used) ]
53 local x-product-seen ;
55 # Do not mix in any conflicting features.
56 local x-product-used = $(x-product-used) $(f) ;
58 if $(property-sets[2])
60 local rest = [ x-product-aux $(property-sets[2-]) : $(feature-space) ] ;
61 result = $(property-sets[1])/$(rest) ;
64 result ?= $(property-sets[1]) ;
67 # If we did not encounter a conflicting feature lower down, do not
69 if ! [ set.intersection $(f) : $(x-product-seen) ]
74 seen = $(x-product-seen) ;
77 if $(property-sets[2])
79 result += [ x-product-aux $(property-sets[2-]) : $(feature-space) ] ;
82 # Note that we have seen these features so that higher levels will recurse
83 # again without them set.
84 x-product-seen += $(f) $(seen) ;
89 # Return the cross-product of all elements of property-sets, less any that would
90 # contain conflicting values for single-valued features. Expects all the project
91 # files to already be loaded.
93 local rule x-product ( property-sets * )
95 if $(property-sets).non-empty
97 # Prepare some "scoped globals" that can be used by the implementation
98 # function, x-product-aux.
99 local x-product-seen x-product-used ;
100 return [ x-product-aux $(property-sets) : $(feature-space) ] ;
102 # Otherwise return empty.
106 # Returns true if either 'v' or the part of 'v' before the first '-' symbol is
107 # an implicit value. Expects all the project files to already be loaded.
109 local rule looks-like-implicit-value ( v )
111 if [ feature.is-implicit-value $(v) ]
117 local split = [ regex.split $(v) - ] ;
118 if [ feature.is-implicit-value $(split[1]) ]
126 # Takes the command line tokens (such as taken from the ARGV rule) and
127 # constructs a build request from them. Returns a vector of two vectors (where
128 # "vector" means container.jam's "vector"). First is the set of targets
129 # specified in the command line, and second is the set of requested build
130 # properties. Expects all the project files to already be loaded.
132 rule from-command-line ( command-line * )
137 command-line = $(command-line[2-]) ;
139 for local e in $(command-line)
145 else if ! [ MATCH ^(-) : $(e) ]
147 # Build request spec either has "=" in it or completely consists of
148 # implicit feature values.
149 local fs = feature-space ;
150 if [ MATCH "(.*=.*)" : $(e) ]
151 || [ looks-like-implicit-value $(e:D=) : $(feature-space) ]
160 else if [ MATCH "^(-[-ldjfsto])$" : $(e) ]
166 [ new vector $(targets) ]
167 [ new vector $(properties) ] ] ;
171 # Converts a list of elements of command line build request specification into internal
172 # form. Expects all the project files to already be loaded.
174 rule convert-command-line-elements ( elements * )
177 for local e in $(elements)
179 result += [ convert-command-line-element $(e) ] ;
185 # Converts one element of command line build request specification into internal
187 local rule convert-command-line-element ( e )
190 local parts = [ regex.split $(e) "/" ] ;
193 local p = $(parts[1]) ;
194 local m = [ MATCH "([^=]*)=(.*)" : $(p) ] ;
201 values = [ regex.split $(m[2]) "," ] ;
202 lresult = <$(feature)>$(values) ;
206 lresult = [ regex.split $(p) "," ] ;
209 if $(feature) && free in [ feature.attributes <$(feature)> ]
211 # If we have free feature, then the value is everything
212 # until the end of the command line token. Slashes in
213 # the following string are not taked to mean separation
214 # of properties. Commas are also not interpreted specially.
215 values = $(values:J=,) ;
216 values = $(values) $(parts[2-]) ;
217 values = $(values:J=/) ;
218 lresult = <$(feature)>$(values) ;
222 if ! [ MATCH (.*-.*) : $(p) ]
224 # property.validate cannot handle subfeatures, so we avoid the check
226 for local p in $(lresult)
228 property.validate $(p) : $(feature-space) ;
234 result = $(lresult) ;
238 result = $(result)/$(lresult) ;
241 parts = $(parts[2-]) ;
253 feature.prepare-test build-request-test-temp ;
255 import build-request ;
256 import build-request : expand-no-defaults : build-request.expand-no-defaults ;
257 import errors : try catch ;
258 import feature : feature subfeature ;
260 feature toolset : gcc msvc borland : implicit ;
261 subfeature toolset gcc : version : 2.95.2 2.95.3 2.95.4
262 3.0 3.0.1 3.0.2 : optional ;
264 feature variant : debug release : implicit composite ;
265 feature inlining : on off ;
266 feature "include" : : free ;
268 feature stdlib : native stlport : implicit ;
270 feature runtime-link : dynamic static : symmetric ;
272 # Empty build requests should expand to empty.
274 : build-request.expand-no-defaults ;
277 <toolset>gcc/<toolset-gcc:version>3.0.1/<stdlib>stlport/<variant>debug
278 <toolset>msvc/<stdlib>stlport/<variant>debug
279 <toolset>msvc/<variant>debug
280 : build-request.expand-no-defaults gcc-3.0.1/stlport msvc/stlport msvc debug ;
283 <toolset>gcc/<toolset-gcc:version>3.0.1/<stdlib>stlport/<variant>debug
284 <toolset>msvc/<variant>debug
285 <variant>debug/<toolset>msvc/<stdlib>stlport
286 : build-request.expand-no-defaults gcc-3.0.1/stlport msvc debug msvc/stlport ;
289 <toolset>gcc/<toolset-gcc:version>3.0.1/<stdlib>stlport/<variant>debug/<inlining>off
290 <toolset>gcc/<toolset-gcc:version>3.0.1/<stdlib>stlport/<variant>release/<inlining>off
291 : build-request.expand-no-defaults gcc-3.0.1/stlport debug release <inlining>off ;
294 <include>a/b/c/<toolset>gcc/<toolset-gcc:version>3.0.1/<stdlib>stlport/<variant>debug/<include>x/y/z
295 <include>a/b/c/<toolset>msvc/<stdlib>stlport/<variant>debug/<include>x/y/z
296 <include>a/b/c/<toolset>msvc/<variant>debug/<include>x/y/z
297 : build-request.expand-no-defaults <include>a/b/c gcc-3.0.1/stlport msvc/stlport msvc debug <include>x/y/z ;
303 r = [ build-request.from-command-line bjam gcc/debug runtime-link=dynamic/static ] ;
304 build-request.convert-command-line-elements [ $(r).get-at 2 ] ;
306 catch \"static\" is not an implicit feature value ;
308 r = [ build-request.from-command-line bjam debug runtime-link=dynamic ] ;
309 assert.equal [ $(r).get-at 1 ] : ;
310 assert.equal [ $(r).get-at 2 ] : debug runtime-link=dynamic ;
313 [ build-request.convert-command-line-elements debug runtime-link=dynamic ]
314 : debug <runtime-link>dynamic ;
316 r = [ build-request.from-command-line bjam -d2 --debug debug target runtime-link=dynamic ] ;
317 assert.equal [ $(r).get-at 1 ] : target ;
318 assert.equal [ $(r).get-at 2 ] : debug runtime-link=dynamic ;
321 [ build-request.convert-command-line-elements debug runtime-link=dynamic ]
322 : debug <runtime-link>dynamic ;
324 r = [ build-request.from-command-line bjam debug runtime-link=dynamic,static ] ;
325 assert.equal [ $(r).get-at 1 ] : ;
326 assert.equal [ $(r).get-at 2 ] : debug runtime-link=dynamic,static ;
329 [ build-request.convert-command-line-elements debug runtime-link=dynamic,static ]
330 : debug <runtime-link>dynamic <runtime-link>static ;
332 r = [ build-request.from-command-line bjam debug gcc/runtime-link=dynamic,static ] ;
333 assert.equal [ $(r).get-at 1 ] : ;
334 assert.equal [ $(r).get-at 2 ] : debug gcc/runtime-link=dynamic,static ;
337 [ build-request.convert-command-line-elements debug gcc/runtime-link=dynamic,static ]
338 : debug gcc/<runtime-link>dynamic gcc/<runtime-link>static ;
340 r = [ build-request.from-command-line bjam msvc gcc,borland/runtime-link=static ] ;
341 assert.equal [ $(r).get-at 1 ] : ;
342 assert.equal [ $(r).get-at 2 ] : msvc gcc,borland/runtime-link=static ;
345 [ build-request.convert-command-line-elements msvc gcc,borland/runtime-link=static ]
346 : msvc gcc/<runtime-link>static borland/<runtime-link>static ;
348 r = [ build-request.from-command-line bjam gcc-3.0 ] ;
349 assert.equal [ $(r).get-at 1 ] : ;
350 assert.equal [ $(r).get-at 2 ] : gcc-3.0 ;
353 [ build-request.convert-command-line-elements gcc-3.0 ]
356 feature.finish-test build-request-test-temp ;