Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52319 - in trunk: . tools/build/v2/build
From: ghost_at_[hidden]
Date: 2009-04-11 03:22:29


Author: vladimir_prus
Date: 2009-04-11 03:22:28 EDT (Sat, 11 Apr 2009)
New Revision: 52319
URL: http://svn.boost.org/trac/boost/changeset/52319

Log:
Improve handling of 'complete' build type.

Previous code used default-build attribute to cause a number
of property sets be requested, and then used indirect
conditional requirements to filter out inappropriate ones,
using the <build>no feature. This worked but is messy, and resulted
in a pile of unclear messages about <build>no. This patch
introduces custom main target class that handles filtering,
so we don't ever try to build with undesired property sets.

Text files modified:
   trunk/Jamroot | 118 +++++++++++++++++++++++++-------
   trunk/tools/build/v2/build/targets.jam | 143 +++++++++++++++++++++++----------------
   2 files changed, 173 insertions(+), 88 deletions(-)

Modified: trunk/Jamroot
==============================================================================
--- trunk/Jamroot (original)
+++ trunk/Jamroot 2009-04-11 03:22:28 EDT (Sat, 11 Apr 2009)
@@ -124,6 +124,8 @@
 import common ;
 import sequence ;
 import symlink ;
+import targets ;
+import project ;
 
 path-constant BOOST_ROOT : . ;
 constant BOOST_VERSION : 1.39.0 ;
@@ -147,32 +149,6 @@
     EXIT ;
 }
 
-# Specify the build variants keyed on the build-type.
-local default-build,minimal =
- release
- <threading>multi
- <link>shared <link>static
- <runtime-link>shared
- ;
-local default-build,complete =
- debug release
- <threading>single <threading>multi
- <link>shared <link>static
- <runtime-link>shared <runtime-link>static
- ;
-
-# Set the default build.
-local default-build = $(default-build,$(build-type)) ;
-
-# We only use the default build when building at the root to avoid having it
-# impact the default regression testing of "debug".
-# TODO: Consider having a "testing" build type instead of this check.
-if $(__file__:D) != ""
-{
- default-build = debug ;
-}
-
-
 rule handle-static-runtime ( properties * )
 {
     # This property combination is dangerous. Ideally, we would add a constraint
@@ -202,7 +178,6 @@
       <toolset>sun:<stdlib>sun-stlport
     : usage-requirements <include>.
     : build-dir bin.v2
- : default-build $(default-build)
     ;
 
 
@@ -515,8 +490,95 @@
     explicit install-unversioned ;
 }
 
+# This is a special metatarget class that handles the --build-type=complete
+# option.
+class top-level-target : alias-target-class
+{
+ import modules ;
+ import errors ;
+
+ rule __init__ ( name : project : sources * : requirements *
+ : default-build * : usage-requirements * )
+ {
+ alias-target-class.__init__ $(name) : $(project) : $(sources) :
+ $(requirements) : $(default-build) : $(usage-requirements) ;
+
+ local m = [ $(project).project-module ] ;
+ self.build-type = [ modules.peek $(m) : build-type ] ;
+ self.minimal-properties = [ property-set.create
+ <variant>release <threading>multi <link>shared <link>static <runtime-link>shared ] ;
+ self.complete-properties = [ property-set.create
+ <variant>debug <variant>release
+ <threading>single <threading>multi
+ <link>shared <link>static
+ <runtime-link>shared <runtime-link>static ] ;
+ }
+
+ rule generate ( property-set )
+ {
+ if $(self.build-type) = minimal
+ {
+ local expanded = [ targets.apply-default-build $(property-set)
+ : $(self.minimal-properties) ] ;
+ return [ build-multiple $(expanded) ] ;
+ }
+ else if $(self.build-type) = complete
+ {
+ local expanded = [ targets.apply-default-build $(property-set)
+ : $(self.complete-properties) ] ;
+
+ # Filter inappopriate combinations
+ local filtered ;
+ for local p in $(expanded)
+ {
+ # See comment in handle-static-runtime regarding this logic.
+ if [ $(p).get <link> ] = shared && [ $(p).get <runtime-link> ] = static
+ && [ $(p).get <toolset> ] != cw
+ {
+ # Skip this
+ }
+ else
+ {
+ filtered += $(p) ;
+ }
+ }
+ return [ build-multiple $(filtered) ] ;
+ }
+ else
+ {
+ errors.error "Unknown build type" ;
+ }
+ }
+
+ rule build-multiple ( property-sets * )
+ {
+ local usage-requirements = [ property-set.empty ] ;
+ local result ;
+ for local p in $(property-sets)
+ {
+ local r = [ alias-target-class.generate $(p) ] ;
+ if $(r)
+ {
+ usage-requirements = [ $(usage-requirements).add $(r[1]) ] ;
+ result += $(r[2-]) ;
+ }
+ }
+ return $(usage-requirements) [ sequence.unique $(result) ] ;
+ }
+
+}
+
 alias install : install-proper install-unversioned ;
-alias stage : stage-proper stage-unversioned ;
+
+targets.create-metatarget top-level-target : [ project.current ]
+ : install
+ : install-proper install-unversioned
+ ;
+targets.create-metatarget top-level-target : [ project.current ]
+ : stage
+ : stage-proper stage-unversioned
+ ;
+
 explicit install ;
 explicit stage ;
 

Modified: trunk/tools/build/v2/build/targets.jam
==============================================================================
--- trunk/tools/build/v2/build/targets.jam (original)
+++ trunk/tools/build/v2/build/targets.jam 2009-04-11 03:22:28 EDT (Sat, 11 Apr 2009)
@@ -78,6 +78,7 @@
 import sequence ;
 import set ;
 import toolset ;
+import build-request ;
 
 
 # Base class for all abstract targets.
@@ -557,7 +558,6 @@
 class main-target : abstract-target
 {
     import assert ;
- import build-request ;
     import errors ;
     import feature ;
     import print ;
@@ -657,65 +657,8 @@
 
     rule apply-default-build ( property-set )
     {
- # 1. First, see what properties from default-build are already present
- # in property-set.
-
- local raw = [ $(property-set).raw ] ;
- local specified-features = $(raw:G) ;
-
- local defaults-to-apply ;
- for local d in [ $(self.default-build).raw ]
- {
- if ! $(d:G) in $(specified-features)
- {
- defaults-to-apply += $(d) ;
- }
- }
-
- # 2. If there are any defaults to be applied, form a new build request.
- # Pass it through to 'expand-no-defaults' since default-build might
- # contain "release debug" resulting in two property-sets.
- local result ;
- if $(defaults-to-apply)
- {
- properties = [
- build-request.expand-no-defaults
-
- # We have to compress subproperties here to prevent property
- # lists like:
- #
- # <toolset>msvc <toolset-msvc:version>7.1 <threading>multi
- #
- # from being expanded into:
- #
- # <toolset-msvc:version>7.1/<threading>multi
- # <toolset>msvc/<toolset-msvc:version>7.1/<threading>multi
- #
- # due to a cross-product property combination. That may be an
- # indication that build-request.expand-no-defaults is the wrong
- # rule to use here.
- [ feature.compress-subproperties $(raw) ]
- $(defaults-to-apply)
- ] ;
-
- if $(properties)
- {
- for local p in $(properties)
- {
- result += [ property-set.create
- [ feature.expand [ feature.split $(p) ] ] ] ;
- }
- }
- else
- {
- result = [ property-set.empty ] ;
- }
- }
- else
- {
- result = $(property-set) ;
- }
- return $(result) ;
+ return [ targets.apply-default-build $(property-set)
+ : $(self.default-build) ] ;
     }
 
     # Select an alternative for this main target, by finding all alternatives
@@ -883,6 +826,69 @@
     return [ $(target).generate $(rproperties) ] ;
 }
 
+rule apply-default-build ( property-set : default-build )
+{
+ # 1. First, see what properties from default-build are already present
+ # in property-set.
+
+ local raw = [ $(property-set).raw ] ;
+ local specified-features = $(raw:G) ;
+
+ local defaults-to-apply ;
+ for local d in [ $(default-build).raw ]
+ {
+ if ! $(d:G) in $(specified-features)
+ {
+ defaults-to-apply += $(d) ;
+ }
+ }
+
+ # 2. If there are any defaults to be applied, form a new build request.
+ # Pass it through to 'expand-no-defaults' since default-build might
+ # contain "release debug" resulting in two property-sets.
+ local result ;
+ if $(defaults-to-apply)
+ {
+ properties = [
+ build-request.expand-no-defaults
+
+ # We have to compress subproperties here to prevent property
+ # lists like:
+ #
+ # <toolset>msvc <toolset-msvc:version>7.1 <threading>multi
+ #
+ # from being expanded into:
+ #
+ # <toolset-msvc:version>7.1/<threading>multi
+ # <toolset>msvc/<toolset-msvc:version>7.1/<threading>multi
+ #
+ # due to a cross-product property combination. That may be an
+ # indication that build-request.expand-no-defaults is the wrong
+ # rule to use here.
+ [ feature.compress-subproperties $(raw) ]
+ $(defaults-to-apply)
+ ] ;
+
+ if $(properties)
+ {
+ for local p in $(properties)
+ {
+ result += [ property-set.create
+ [ feature.expand [ feature.split $(p) ] ] ] ;
+ }
+ }
+ else
+ {
+ result = [ property-set.empty ] ;
+ }
+ }
+ else
+ {
+ result = $(property-set) ;
+ }
+ return $(result) ;
+}
+
 
 # Given a build request and requirements, return properties common to dependency
 # build request and target requirements.
@@ -1559,6 +1565,23 @@
     return $(target) ;
 }
 
+# Creates a new metargets with the specified properties, using 'klass' as
+# the class. The 'name', 'sources',
+# 'requirements', 'default-build' and 'usage-requirements' are assumed to be in
+# the form specified by the user in Jamfile corresponding to 'project'.
+#
+rule create-metatarget ( klass : project : name : sources * : requirements * :
+ default-build * : usage-requirements * )
+{
+ return [
+ targets.main-target-alternative
+ [ new $(klass) $(name) : $(project)
+ : [ targets.main-target-sources $(sources) : $(name) ]
+ : [ targets.main-target-requirements $(requirements) : $(project) ]
+ : [ targets.main-target-default-build $(default-build) : $(project) ]
+ : [ targets.main-target-usage-requirements $(usage-requirements) : $(project) ]
+ ] ] ;
+}
 
 # Creates a typed-target with the specified properties. The 'name', 'sources',
 # 'requirements', 'default-build' and 'usage-requirements' are assumed to be in


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk