mirror of
https://github.com/boostorg/build.git
synced 2026-02-02 08:42:13 +00:00
Expand command line properties as late as possible
This commit is contained in:
committed by
Vladimir Prus
parent
ece2f53819
commit
5843dec89c
@@ -585,26 +585,6 @@ local rule should-clean-project ( project )
|
||||
local properties = [ $(build-request).get-at 2 ] ;
|
||||
|
||||
|
||||
# Expand properties specified on the command line into multiple property
|
||||
# sets consisting of all legal property combinations. Each expanded property
|
||||
# set will be used for a single build run. E.g. if multiple toolsets are
|
||||
# specified then requested targets will be built with each of them.
|
||||
if $(properties)
|
||||
{
|
||||
expanded = [ build-request.expand-no-defaults $(properties) ] ;
|
||||
local xexpanded ;
|
||||
for local e in $(expanded)
|
||||
{
|
||||
xexpanded += [ property-set.create [ feature.split $(e) ] ] ;
|
||||
}
|
||||
expanded = $(xexpanded) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
expanded = [ property-set.empty ] ;
|
||||
}
|
||||
|
||||
|
||||
# Check that we actually found something to build.
|
||||
if ! $(current-project) && ! $(target-ids)
|
||||
{
|
||||
@@ -695,6 +675,29 @@ local rule should-clean-project ( project )
|
||||
configure.set-log-file $(first-build-build-dir)/config.log ;
|
||||
config-cache.load $(first-build-build-dir)/project-cache.jam ;
|
||||
|
||||
# Expand properties specified on the command line into multiple property
|
||||
# sets consisting of all legal property combinations. Each expanded property
|
||||
# set will be used for a single build run. E.g. if multiple toolsets are
|
||||
# specified then requested targets will be built with each of them.
|
||||
# The expansion is being performed as late as possible so that the feature
|
||||
# validation is performed after all necessary modules (including project targets
|
||||
# on the command line) have been loaded.
|
||||
if $(properties)
|
||||
{
|
||||
expanded += [ build-request.convert-command-line-elements $(properties) ] ;
|
||||
expanded = [ build-request.expand-no-defaults $(expanded) ] ;
|
||||
local xexpanded ;
|
||||
for local e in $(expanded)
|
||||
{
|
||||
xexpanded += [ property-set.create [ feature.split $(e) ] ] ;
|
||||
}
|
||||
expanded = $(xexpanded) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
expanded = [ property-set.empty ] ;
|
||||
}
|
||||
|
||||
# Now that we have a set of targets to build and a set of property sets to
|
||||
# build the targets with, we can start the main build process by using each
|
||||
# property set to generate virtual targets from all of our listed targets
|
||||
|
||||
@@ -150,8 +150,7 @@ rule from-command-line ( command-line * )
|
||||
if [ MATCH "(.*=.*)" : $(e) ]
|
||||
|| [ looks-like-implicit-value $(e:D=) : $(feature-space) ]
|
||||
{
|
||||
properties += [ convert-command-line-element $(e) :
|
||||
$(feature-space) ] ;
|
||||
properties += $(e) ;
|
||||
}
|
||||
else if $(e)
|
||||
{
|
||||
@@ -169,9 +168,22 @@ rule from-command-line ( command-line * )
|
||||
}
|
||||
|
||||
|
||||
# Converts one element of command line build request specification into internal
|
||||
# Converts a list of elements of command line build request specification into internal
|
||||
# form. Expects all the project files to already be loaded.
|
||||
#
|
||||
rule convert-command-line-elements ( elements * )
|
||||
{
|
||||
local result ;
|
||||
for local e in $(elements)
|
||||
{
|
||||
result += [ convert-command-line-element $(e) ] ;
|
||||
}
|
||||
return $(result) ;
|
||||
}
|
||||
|
||||
|
||||
# Converts one element of command line build request specification into internal
|
||||
# form.
|
||||
local rule convert-command-line-element ( e )
|
||||
{
|
||||
local result ;
|
||||
@@ -286,37 +298,60 @@ rule __test__ ( )
|
||||
|
||||
local r ;
|
||||
|
||||
r = [ build-request.from-command-line bjam debug runtime-link=dynamic ] ;
|
||||
assert.equal [ $(r).get-at 1 ] : ;
|
||||
assert.equal [ $(r).get-at 2 ] : debug <runtime-link>dynamic ;
|
||||
|
||||
try ;
|
||||
{
|
||||
build-request.from-command-line bjam gcc/debug runtime-link=dynamic/static ;
|
||||
r = [ build-request.from-command-line bjam gcc/debug runtime-link=dynamic/static ] ;
|
||||
build-request.convert-command-line-elements [ $(r).get-at 2 ] ;
|
||||
}
|
||||
catch \"static\" is not an implicit feature value ;
|
||||
|
||||
r = [ build-request.from-command-line bjam debug runtime-link=dynamic ] ;
|
||||
assert.equal [ $(r).get-at 1 ] : ;
|
||||
assert.equal [ $(r).get-at 2 ] : debug runtime-link=dynamic ;
|
||||
|
||||
assert.equal
|
||||
[ build-request.convert-command-line-elements debug runtime-link=dynamic ]
|
||||
: debug <runtime-link>dynamic ;
|
||||
|
||||
r = [ build-request.from-command-line bjam -d2 --debug debug target runtime-link=dynamic ] ;
|
||||
assert.equal [ $(r).get-at 1 ] : target ;
|
||||
assert.equal [ $(r).get-at 2 ] : debug <runtime-link>dynamic ;
|
||||
assert.equal [ $(r).get-at 2 ] : debug runtime-link=dynamic ;
|
||||
|
||||
assert.equal
|
||||
[ build-request.convert-command-line-elements debug runtime-link=dynamic ]
|
||||
: debug <runtime-link>dynamic ;
|
||||
|
||||
r = [ build-request.from-command-line bjam debug runtime-link=dynamic,static ] ;
|
||||
assert.equal [ $(r).get-at 1 ] : ;
|
||||
assert.equal [ $(r).get-at 2 ] : debug <runtime-link>dynamic <runtime-link>static ;
|
||||
assert.equal [ $(r).get-at 2 ] : debug runtime-link=dynamic,static ;
|
||||
|
||||
assert.equal
|
||||
[ build-request.convert-command-line-elements debug runtime-link=dynamic,static ]
|
||||
: debug <runtime-link>dynamic <runtime-link>static ;
|
||||
|
||||
r = [ build-request.from-command-line bjam debug gcc/runtime-link=dynamic,static ] ;
|
||||
assert.equal [ $(r).get-at 1 ] : ;
|
||||
assert.equal [ $(r).get-at 2 ] : debug gcc/<runtime-link>dynamic
|
||||
gcc/<runtime-link>static ;
|
||||
assert.equal [ $(r).get-at 2 ] : debug gcc/runtime-link=dynamic,static ;
|
||||
|
||||
assert.equal
|
||||
[ build-request.convert-command-line-elements debug gcc/runtime-link=dynamic,static ]
|
||||
: debug gcc/<runtime-link>dynamic gcc/<runtime-link>static ;
|
||||
|
||||
r = [ build-request.from-command-line bjam msvc gcc,borland/runtime-link=static ] ;
|
||||
assert.equal [ $(r).get-at 1 ] : ;
|
||||
assert.equal [ $(r).get-at 2 ] : msvc gcc/<runtime-link>static
|
||||
borland/<runtime-link>static ;
|
||||
assert.equal [ $(r).get-at 2 ] : msvc gcc,borland/runtime-link=static ;
|
||||
|
||||
assert.equal
|
||||
[ build-request.convert-command-line-elements msvc gcc,borland/runtime-link=static ]
|
||||
: msvc gcc/<runtime-link>static borland/<runtime-link>static ;
|
||||
|
||||
r = [ build-request.from-command-line bjam gcc-3.0 ] ;
|
||||
assert.equal [ $(r).get-at 1 ] : ;
|
||||
assert.equal [ $(r).get-at 2 ] : gcc-3.0 ;
|
||||
|
||||
assert.equal
|
||||
[ build-request.convert-command-line-elements gcc-3.0 ]
|
||||
: gcc-3.0 ;
|
||||
|
||||
feature.finish-test build-request-test-temp ;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ def from_command_line(command_line):
|
||||
# Build request spec either has "=" in it, or completely
|
||||
# consists of implicit feature values.
|
||||
if e.find("=") != -1 or looks_like_implicit_value(e.split("/")[0]):
|
||||
properties += convert_command_line_element(e)
|
||||
properties.append(e)
|
||||
elif e:
|
||||
targets.append(e)
|
||||
|
||||
|
||||
@@ -509,15 +509,6 @@ def main_real():
|
||||
# that all project files already be loaded.
|
||||
(target_ids, properties) = build_request.from_command_line(sys.argv[1:] + extra_properties)
|
||||
|
||||
# Expand properties specified on the command line into multiple property
|
||||
# sets consisting of all legal property combinations. Each expanded property
|
||||
# set will be used for a single build run. E.g. if multiple toolsets are
|
||||
# specified then requested targets will be built with each of them.
|
||||
if properties:
|
||||
expanded = build_request.expand_no_defaults(properties)
|
||||
else:
|
||||
expanded = [property_set.empty()]
|
||||
|
||||
# Check that we actually found something to build.
|
||||
if not current_project and not target_ids:
|
||||
get_manager().errors()("no Jamfile in current directory found, and no target references specified.")
|
||||
@@ -595,6 +586,22 @@ def main_real():
|
||||
|
||||
global results_of_main_targets
|
||||
|
||||
# Expand properties specified on the command line into multiple property
|
||||
# sets consisting of all legal property combinations. Each expanded property
|
||||
# set will be used for a single build run. E.g. if multiple toolsets are
|
||||
# specified then requested targets will be built with each of them.
|
||||
# The expansion is being performed as late as possible so that the feature
|
||||
# validation is performed after all necessary modules (including project targets
|
||||
# on the command line) have been loaded.
|
||||
if properties:
|
||||
expanded = []
|
||||
for p in properties:
|
||||
expanded.extend(build_request.convert_command_line_element(p))
|
||||
|
||||
expanded = build_request.expand_no_defaults(expanded)
|
||||
else:
|
||||
expanded = [property_set.empty()]
|
||||
|
||||
# Now that we have a set of targets to build and a set of property sets to
|
||||
# build the targets with, we can start the main build process by using each
|
||||
# property set to generate virtual targets from all of our listed targets
|
||||
|
||||
41
test/cli_property_expansion.py
Normal file
41
test/cli_property_expansion.py
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Copyright 2015 Aaron Boman
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# Test that free property inside.
|
||||
|
||||
import BoostBuild
|
||||
|
||||
t = BoostBuild.Tester(use_test_config=False)
|
||||
|
||||
t.write("jamroot.jam", "")
|
||||
t.write(
|
||||
"subdir/build.jam",
|
||||
"""
|
||||
import feature ;
|
||||
feature.feature my-feature : : free ;
|
||||
"""
|
||||
)
|
||||
t.write(
|
||||
"subdir/subsubdir/build.jam",
|
||||
"""
|
||||
exe hello : hello.c ;
|
||||
"""
|
||||
)
|
||||
t.write(
|
||||
"subdir/subsubdir/hello.c",
|
||||
r"""
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv){
|
||||
printf("%s\n", "Hello, World!");
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
# run from the root directory
|
||||
t.run_build_system(['subdir/subsubdir', 'my-feature="some value"'])
|
||||
|
||||
t.cleanup()
|
||||
Reference in New Issue
Block a user