From aabded28118faf73f6c2a19b9bfcc6e73e8ccdb5 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Fri, 3 Dec 2004 08:28:37 +0000 Subject: [PATCH] Refactor/improve support. * build/targets.jam (generate-realy): After applying tag, we used to 'temporary' change self.name, which is horrible. How pass the name to 'construct'. (construct): New parameter 'name'. (tag-name): New rule, extracted from basic-target. This needs to be separate rule so that we can call it from 'stage'. Check for a value of from '@something' and interpret 'something' as a rule which returns the new name. [SVN r26408] --- src/build/alias.jam | 2 +- src/build/targets.jam | 83 ++++++++++++++++++++++++++----------------- src/tools/make.jam | 2 +- src/tools/stage.jam | 2 +- src/tools/stlport.jam | 2 +- src/tools/symlink.jam | 2 +- 6 files changed, 56 insertions(+), 37 deletions(-) diff --git a/src/build/alias.jam b/src/build/alias.jam index 4fd1721a0..7253194df 100644 --- a/src/build/alias.jam +++ b/src/build/alias.jam @@ -41,7 +41,7 @@ class alias-target-class : basic-target : $(default-build) : $(usage-requirements) ; } - rule construct ( source-targets * : property-set ) + rule construct ( name : source-targets * : property-set ) { return [ property-set.empty ] $(source-targets) ; } diff --git a/src/build/targets.jam b/src/build/targets.jam index 97ceb2d79..48203431b 100644 --- a/src/build/targets.jam +++ b/src/build/targets.jam @@ -982,27 +982,6 @@ class basic-target : abstract-target return no-match ; } } - - # - # Allows the user to tag the name of the target, according to properties. - # - rule tag-name ( name : property-set ) - { - local properties = [ $(property-set).raw ] ; - - local tagged-name = $(name) ; - - if in $(properties:G) - { - local tags = [ $(property-set).get ] ; - for local tag in $(tags) - { - tagged-name = $(tagged-name)$(tag) ; - } - } - - return $(tagged-name) ; - } # Takes a target reference, which might be either target id # or a dependency property, and generates that target using @@ -1073,13 +1052,14 @@ class basic-target : abstract-target # usage requirements. source-targets = [ sequence.unique $(source-targets) ] ; - local tagged-name = [ tag-name $(self.name) : $(rproperties) ] ; - - local original-name = $(self.name) ; - self.name = $(tagged-name) ; - + # Compute the real name for generated targets, using + # the feature. + local tagged-name = [ + targets.tag-name $(self.name) : $(rproperties) ] ; + local result = - [ construct $(source-targets) : $(rproperties) ] ; + [ construct $(tagged-name) : + $(source-targets) : $(rproperties) ] ; local gur = $(result[1]) ; result = $(result[2-]) ; @@ -1091,8 +1071,6 @@ class basic-target : abstract-target ur = [ $(ur).add $(gur) ] ; $(s).set-usage-requirements $(ur) ; self.generated.$(property-set) = $(ur) $(result) ; - - self.name = $(original-name) ; } else { @@ -1182,7 +1160,7 @@ class basic-target : abstract-target # Constructs the virtual targets for this abstract targets and # the dependecy graph. Returns the list of virtual targets. # Should be overrided in derived classes. - rule construct ( source-targets * : properties * ) + rule construct ( name : source-targets * : properties * ) { errors.error "method should be defined in derived classes" ; } @@ -1206,9 +1184,9 @@ class typed-target : basic-target return $(self.type) ; } - rule construct ( source-targets * : property-set ) + rule construct ( name : source-targets * : property-set ) { - local r = [ generators.construct $(self.project) $(self.name) : $(self.type) + local r = [ generators.construct $(self.project) $(name) : $(self.type) : [ property-set.create [ $(property-set).raw ] # [ feature.expand $(self.type) ] # ] @@ -1222,6 +1200,47 @@ class typed-target : basic-target } } +# +# Given a base target name and a set of properties, returns the +# name which should be really used, by looking at the properties. +# The tag properties come in two flavour: +# - value, +# - @rule-name +# In the first case, value is just added to name +# In the second case, the specified rule is called with name and properties +# and should return the new name. +rule tag-name ( name : property-set ) +{ + local properties = [ $(property-set).raw ] ; + + local tagged-name = $(name) ; + + if in $(properties:G) + { + local tags = [ $(property-set).get ] ; + + local rule-name = [ MATCH ^@(.*) : $(tags) ] ; + if $(rule-name) + { + if $(tags[2]) + { + errors.error "@rulename is present but is the the only feature" ; + } + tagged-name = [ $(rule-name) $(name) : $(property-set) ] ; + } + else + { + for local tag in $(tags) + { + tagged-name = $(tagged-name)$(tag) ; + } + } + } + + return $(tagged-name) ; +} + + # Return the list of sources to use, if main target rule is invoked # with 'sources'. If there are any objects in 'sources', they are treated # as main target instances, and WRITEME. diff --git a/src/tools/make.jam b/src/tools/make.jam index 249fd69e2..b7b4046f3 100644 --- a/src/tools/make.jam +++ b/src/tools/make.jam @@ -28,7 +28,7 @@ class make-target-class : basic-target self.make-rule = $(make-rule) ; } - rule construct ( source-targets * : property-set ) + rule construct ( name : source-targets * : property-set ) { local t = [ new file-target $(self.name:S=) : [ type.type $(self.name) ] : $(self.project) ] ; diff --git a/src/tools/stage.jam b/src/tools/stage.jam index aef70c9ec..b96cc7a9f 100644 --- a/src/tools/stage.jam +++ b/src/tools/stage.jam @@ -104,7 +104,7 @@ class stage-target-class : basic-target return $(targets[2-]) ; } - rule construct ( source-targets * : property-set ) + rule construct ( name : source-targets * : property-set ) { local name = [ $(property-set).get ] ; if $(name) && $(source-targets[2]) diff --git a/src/tools/stlport.jam b/src/tools/stlport.jam index f8181270d..a9db490d3 100644 --- a/src/tools/stlport.jam +++ b/src/tools/stlport.jam @@ -120,7 +120,7 @@ class stlport-target-class : basic-target } - rule construct ( source-targets * : property-set ) + rule construct ( name : source-targets * : property-set ) { # Deduce the name of stlport library, based on toolset and # debug setting. diff --git a/src/tools/symlink.jam b/src/tools/symlink.jam index 35bdecdf2..beef6918d 100644 --- a/src/tools/symlink.jam +++ b/src/tools/symlink.jam @@ -51,7 +51,7 @@ class symlink-targets : basic-target self.virtual-targets = ; } - rule construct ( source-targets * : property-set ) + rule construct ( name : source-targets * : property-set ) { local i = 1 ; for local t in $(source-targets)