2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-20 14:42:14 +00:00
Files
build/new/indirect.jam
Dave Abrahams 44b48fc7df * Restored the printing of qualified names from invoked actions.
Consequently rolled back the workaround in make_rule.py

* Added new indirect rule invocation module for encoding the module to
  invoke a rule from as well as the exact name to invoke it by, and
  for subsequent invocation.

* Fixed module __test__ rules so they really do execute in a separate
  module.  Associated tweaks to __test__ in path.jam


[SVN r18427]
2003-05-16 16:30:13 +00:00

100 lines
2.7 KiB
Plaintext
Executable File

# Copyright David Abrahams 2003. Permission to copy, use,
# modify, sell and distribute this software is granted provided this
# copyright notice appears in all copies. This software is provided
# "as is" without express or implied warranty, and with no claim as
# to its suitability for any purpose.
import modules ;
import numbers ;
# The pattern that indirect rules must match: module$rule
.pattern = ^([^%]*)%([^%]+)$ ;
#
# Type checking rules.
#
local rule indirect-rule ( x )
{
if ! [ MATCH $(.pattern) : $(x) ]
{
return "expected a string of the form module$rule, but got \""$(x)"\" for argument" ;
}
}
# make an indirect rule which calls the given rule; if context is
# supplied it is expected to be the module in which to invoke the rule
# by the 'call' rule below. Otherwise, the rule will be invoked in
# the module of this rule's caller.
rule make ( rulename bound-args * : context ? )
{
context ?= [ CALLER_MODULE ] ;
context ?= "" ;
return $(context)%$(rulename) $(bound-args) ;
}
# make an indirect rule which calls the given rule. rulename may be a
# qualified rule; if so it is returned unchanged. Otherwise, if
# frames is not supplied, the result will be invoked (by 'call',
# below) in the module of the caller. Otherwise, frames > 1
# specifies additional call frames to back up in order to find the
# module context.
rule make-qualified ( rulename bound-args * : frames ? )
{
if [ MATCH $(.pattern) : $(rulename) ]
{
return $(rulename) $(bound-args) ;
}
else
{
frames ?= 1 ;
local module-context = [ MATCH ^(.*)\\..* : $(rulename) ] ;
module-context ?= [ CALLER_MODULE $(frames) ] ;
return [ make $(rulename) $(bound-args) : $(module-context) ] ;
}
}
# return the module name in which the given indirect rule will be
# invoked.
rule get-module ( [indirect-rule] x )
{
local m = [ MATCH $(.pattern) : $(x) ] ;
if ! $(m[1])
{
m = ;
}
return $(m[1]) ;
}
# return the rulename that will be called when x is invoked
rule get-rule ( [indirect-rule] x )
{
local m = [ MATCH $(.pattern) : $(x) ] ;
return $(m[2]) ;
}
# Invoke the given indirect-rule.
rule call ( [indirect-rule] r args * : * )
{
return [
modules.call-in [ get-module $(r) ]
: [ get-rule $(r) ] $(args) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9)
] ;
}
rule __test__
{
import assert ;
rule foo-barr! ( x )
{
assert.equal $(x) : x ;
}
assert.equal [ get-rule [ make foo-barr! ] ] : foo-barr! ;
assert.equal [ get-module [ make foo-barr! ] ] : [ CALLER_MODULE ] ;
call [ make foo-barr! ] x ;
call [ make foo-barr! x ] ;
call [ make foo-barr! : [ CALLER_MODULE ] ] x ;
}