From 5c18848ccdecbaa147ae527562fe673caec89385 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Fri, 15 Nov 2002 07:20:23 +0000 Subject: [PATCH] Cleanup main target alternative creationg. * new/targets.jam (abstract-target.name): New method. (abstract-target.project): New method. (main-target-alternative): Simplify. Only register main target alternative. Don't to fancy processing of arguments. (main-target-requirements): New rule. (main-target-use-requirements): New rule. (main-target-default-build): New rule. [SVN r16249] --- src/build/targets.jam | 149 +++++++++++++++++++++++------------------ src/build/type.jam | 15 ++++- src/tools/make.jam | 14 ++-- src/tools/prebuilt.jam | 12 +++- src/tools/stage.jam | 11 ++- src/tools/testing.jam | 12 ++-- 6 files changed, 127 insertions(+), 86 deletions(-) diff --git a/src/build/targets.jam b/src/build/targets.jam index 32a1b6f0e..cc7292966 100644 --- a/src/build/targets.jam +++ b/src/build/targets.jam @@ -48,7 +48,19 @@ rule abstract-target ( name # name of the target in Jamfile self.name = $(name) ; self.project = $(project) ; - + + # Returns the name of this target. + rule name ( ) + { + return $(self.name) ; + } + + # Returns the project for this target. + rule project ( ) + { + return $(self.project) ; + } + # Returns a user-readable name for this target. rule full-name ( ) { @@ -496,72 +508,6 @@ rule basic-target ( name : project class basic-target : abstract-target ; -.args = 5 6 7 8 9 ; - -# Creates a main target alternative of type 'class-name'. The ctor will be -# passed 'target-name', 'project' and all trailing arguments. -# If 'requirements-pos' and 'default-build-pos' are specified, the corresponding -# trailing arguments will be specially processed. -rule main-target-alternative ( target-name project class-name - : requirements-pos ? : use-requirements-pos ? : default-build-pos ? - : * ) -{ - for local i in $(.args) - { - a$(i) = $($(i)) ; - } - - if $(requirements-pos) - { - local real-pos = $(.args[$(requirements-pos)]) ; - local real-pos2 = $(.args[$(use-requirements-pos)]) ; - local project-requirements = [ project.attribute $(project) requirements ] ; - local project-use-requirements = [ project.attribute $(project) use-requirements ] ; - - local loc = [ project.attribute $(project) location ] ; - local requirements = - [ property.translate-paths $($(real-pos)) : $(loc) ] ; - # Should have only free properties - if [ property.remove free : $($(real-pos2)) ] - { - errors.error "use-requirements" $($(real-pos2)) "have non-free properties" ; - } - - local use-requirements = - [ property.translate-paths $($(real-pos2)) : $(loc) ] ; - use-requirements += $(project-use-requirements) ; - - requirements = [ property.refine $(project-requirements) : $(requirements) ] ; - if $(requirements[1]) = "@error" - { - error "Conflicting requirements for target:" $(requirements) ; - } - else - { - a$(real-pos) = $(requirements) ; - } - a$(real-pos2) = $(use-requirements) ; - } - - if $(default-build-pos) - { - local real-pos = $(.args[$(default-build-pos)]) ; - if ! $(a$(real-pos)) - { - a$(real-pos) = [ project.attribute $(project) default-build ] ; - } - } - - local location = [ project.attribute $(project) location ] ; - local ptarget = [ project.target $(location) ] ; - local target = [ $(ptarget).main-target $(target-name) ] ; - - $(target).add-alternative - [ new $(class-name) $(target-name) : $(project) - : $(a5) : $(a6) : $(a7) : $(a8) : $(a9) ] ; -} - - rule typed-target ( name : project : type : sources * : requirements * : default-build * : use-requirements * ) { @@ -587,3 +533,72 @@ rule typed-target ( name : project : type } class typed-target : basic-target ; + +# Returns the requirement to use when declaring a main target, +# which are obtained by +# - translating all specified property paths, and +# - refining project requirements with the one specified for the target +rule main-target-requirements ( + specification * # Properties explicitly specified for a main target + : project # Project where the main target is to be declared + ) +{ + local loc = [ project.attribute $(project) location ] ; + local requirements = [ property.translate-paths $(specification) : $(loc) ] ; + local project-requirements = [ project.attribute $(project) requirements ] ; + requirements = [ property.refine $(project-requirements) : $(specification) ] ; + if $(requirements[1]) = "@error" + { + errors.error "Conflicting requirements for target:" $(requirements) ; + } + return $(requirements) ; +} + +# Returns the use requirement to use when declaraing a main target, +# which are obtained by +# - translating all specified property paths, and +# - adding project's use requirements +rule main-target-use-requirements ( + specification * # Use-properties explicitly specified for a main target + : project # Project where the main target is to be declared + ) +{ + local loc = [ project.attribute $(project) location ] ; + local project-use-requirements = [ project.attribute $(project) use-requirements ] ; + + local use-requirements = [ property.translate-paths $(specification) : $(loc) ] ; + use-requirements += $(project-use-requirements) ; + + return $(use-requirements) ; +} + +# Return the default build value to use when declaring a main target, +# which is obtained by using specified value if not empty and parent's +# default build attribute otherwise. +rule main-target-default-build ( + specification * # Default build explicitly specified for a main target + : project # Project where the main target is to be declared + ) +{ + if $(specification) + { + return $(specification) ; + } + else + { + return [ project.attribute $(project) default-build ] ; + } +} + +# Registers the specified target as a main target alternatives. +# Gets project and name for 'target', obtains main target +# from them, and adds targets to the list of alternatives for +# the main target. +rule main-target-alternative ( target ) +{ + local location = [ project.attribute [ $(target).project ] location ] ; + local ptarget = [ project.target $(location) ] ; + local mtarget = [ $(ptarget).main-target [ $(target).name ] ] ; + + $(mtarget).add-alternative $(target) ; +} diff --git a/src/build/type.jam b/src/build/type.jam index 8661d60b9..b4c507a0c 100644 --- a/src/build/type.jam +++ b/src/build/type.jam @@ -139,8 +139,17 @@ rule main-target-rule ( name : sources * : requirements * : default-build * local bt = [ BACKTRACE 1 ] ; local rulename = $(bt[4]) ; - targets.main-target-alternative $(name) [ CALLER_MODULE ] typed-target : 3 : 5 : 4 - : $(.main-target-type.$(rulename)) : $(sources) : $(requirements) : $(default-build) : $(use-requirements) - ; + # This rule may be only called from Jamfile, and therefore, + # CALLER_MODULE is Jamfile module, which is used to denote + # a project. + local project = [ CALLER_MODULE ] ; + + targets.main-target-alternative + [ new typed-target $(name) : $(project) : $(.main-target-type.$(rulename)) + : $(sources) + : [ targets.main-target-requirements $(requirements) : $(project) ] + : [ targets.main-target-default-build $(default-build) : $(project) ] + : [ targets.main-target-use-requirements $(use-requirements) : $(project) ] + ] ; } diff --git a/src/tools/make.jam b/src/tools/make.jam index fb0605d76..4b0ad1a36 100644 --- a/src/tools/make.jam +++ b/src/tools/make.jam @@ -36,9 +36,6 @@ class make-target-class : basic-target ; rule make ( target-name : sources * : generating-rule : requirements * ) { - # Default build is not specified: 'main-target-alternative' will take - # care of it. - local caller = [ CALLER_MODULE ] ; local rules = [ RULENAMES $(caller) ] ; if $(generating-rule) in $(rules) @@ -49,9 +46,14 @@ rule make ( target-name : sources * : generating-rule : requirements * ) generating-rule = $(n) ; } - targets.main-target-alternative - $(target-name) [ CALLER_MODULE ] make-target-class : 2 : : 4 - : $(sources) : $(requirements) : $(generating-rule) : $(default-build) ; + targets.main-target-alternative + [ new make-target-class $(target-name) : $(caller) : $(sources) : + [ targets.main-target-requirements $(requirements) : $(caller) ] : + $(generating-rule) : + : + [ targets.main-target-default-build : $(caller) ] + ] ; + } IMPORT $(__name__) : make : : make ; diff --git a/src/tools/prebuilt.jam b/src/tools/prebuilt.jam index 9609ea6a4..673d7f191 100644 --- a/src/tools/prebuilt.jam +++ b/src/tools/prebuilt.jam @@ -46,9 +46,15 @@ class prebuilt-target-class : abstract-target ; rule prebuilt ( type target-name : file : requirements * : use-requirements * ) { - targets.main-target-alternative - $(target-name) [ CALLER_MODULE ] prebuilt-target-class : 2 : 3 : - : $(type) $(file) : $(requirements) : $(use-requirements) ; + local project = [ CALLER_MODULE ] ; + + targets.main-target-alternative + [ new prebuilt-target-class $(target-name) : $(project) : + $(type) $(file) + : [ targets.main-target-requirements $(requirements) : $(project) ] + : [ targets.main-target-use-requirements $(use-requirements) : $(project) ] + ] ; + } IMPORT $(__name__) : prebuilt : : prebuilt ; diff --git a/src/tools/stage.jam b/src/tools/stage.jam index 6adaed9c4..f55ef8645 100644 --- a/src/tools/stage.jam +++ b/src/tools/stage.jam @@ -45,9 +45,14 @@ rule stage ( directory : sources * : requirements * : default-build * ) { # FIXME: for now, just use directory as target name. We really # need to implement unnamed main targets. - targets.main-target-alternative - $(directory) [ CALLER_MODULE ] stage-target-class : 2 : : 3 - : $(sources) : $(requirements) : $(default-build) ; + + local project = [ CALLER_MODULE ] ; + + targets.main-target-alternative + [ new stage-target-class $(directory) : $(project) : $(sources) + : [ targets.main-target-requirements $(requirements) : $(project) ] + : [ targets.main-target-default-build $(default-build) : $(project) ] + ] ; } IMPORT $(__name__) : stage : : stage ; diff --git a/src/tools/testing.jam b/src/tools/testing.jam index a59cc1add..0fa8a2058 100644 --- a/src/tools/testing.jam +++ b/src/tools/testing.jam @@ -20,13 +20,13 @@ rule unit-test-target-class ( name : project : sources * : requirements * local result = [ typed-target.construct $(source-targets) : $(properties) ] ; local exe = $(result[1]) ; - local exe-action = [ $(exe).action ] ; + local exe-action = [ $(exe).action ] ; local timestamp = [ new virtual-target $(self.name) : : $(self.project) ] ; $(timestamp).suffix "passed" ; local a = [ new action $(timestamp) : $(exe) : testing.run : - [ $(exe-action).properties ] ] ; + [ $(exe-action).properties ] ] ; $(timestamp).action $(a) ; return $(timestamp) ; } @@ -47,10 +47,14 @@ actions run rule unit-test ( target-name : sources * : requirements * ) { + local project = [ CALLER_MODULE ] ; + # TODO: what to do with default build? targets.main-target-alternative - $(target-name) [ CALLER_MODULE ] unit-test-target-class : 2 : : 3 - : $(sources) : $(requirements) : $(default-build) ; + [ new unit-test-target-class $(target-name) : $(project) : $(sources) + : [ targets.main-target-requirements $(requirements) : $(project) ] + : [ targets.main-target-default-build $(default-build) : $(project) ] + ] ; } IMPORT $(__name__) : unit-test : : unit-test ;