]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/util/indirect.jam
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / tools / build / src / util / indirect.jam
1 # Copyright 2003 Dave Abrahams
2 # Copyright 2003 Vladimir Prus
3 # Distributed under the Boost Software License, Version 1.0.
4 # (See accompanying file LICENSE_1_0.txt or copy at
5 # http://www.boost.org/LICENSE_1_0.txt)
6
7 import modules ;
8 import numbers ;
9
10
11 # The pattern that indirect rules must match: module%rule
12 .pattern = ^([^%]*)%([^%]+)$ ;
13
14
15 #
16 # Type checking rules.
17 #
18 local rule indirect-rule ( x )
19 {
20 if ! [ MATCH $(.pattern) : $(x) ]
21 {
22 return "expected a string of the form module%rule, but got \""$(x)"\" for argument" ;
23 }
24 }
25
26
27 # Make an indirect rule which calls the given rule. If context is supplied it is
28 # expected to be the module in which to invoke the rule by the 'call' rule
29 # below. Otherwise, the rule will be invoked in the module of this rule's
30 # caller.
31 #
32 rule make ( rulename bound-args * : context ? )
33 {
34 context ?= [ CALLER_MODULE ] ;
35 context ?= "" ;
36 return $(context)%$(rulename) $(bound-args) ;
37 }
38
39
40 # Make an indirect rule which calls the given rule. 'rulename' may be a
41 # qualified rule; if so it is returned unchanged. Otherwise, if frames is not
42 # supplied, the result will be invoked (by 'call', below) in the module of the
43 # caller. Otherwise, frames > 1 specifies additional call frames to back up in
44 # order to find the module context.
45 #
46 rule make-qualified ( rulename bound-args * : frames ? )
47 {
48 if [ MATCH $(.pattern) : $(rulename) ]
49 {
50 return $(rulename) $(bound-args) ;
51 }
52 else
53 {
54 frames ?= 1 ;
55 # If the rule name includes a Jamfile module, grab it.
56 local module-context = [ MATCH ^(Jamfile<[^>]*>)\\..* : $(rulename) ] ;
57
58 if ! $(module-context)
59 {
60 # Take the first dot-separated element as module name. This disallows
61 # module names with dots, but allows rule names with dots.
62 module-context = [ MATCH ^([^.]*)\\..* : $(rulename) ] ;
63 }
64 module-context ?= [ CALLER_MODULE $(frames) ] ;
65 return [ make $(rulename) $(bound-args) : $(module-context) ] ;
66 }
67 }
68
69
70 # Returns the module name in which the given indirect rule will be invoked.
71 #
72 rule get-module ( [indirect-rule] x )
73 {
74 local m = [ MATCH $(.pattern) : $(x) ] ;
75 if ! $(m[1])
76 {
77 m = ;
78 }
79 return $(m[1]) ;
80 }
81
82
83 # Returns the rulename that will be called when x is invoked.
84 #
85 rule get-rule ( [indirect-rule] x )
86 {
87 local m = [ MATCH $(.pattern) : $(x) ] ;
88 return $(m[2]) ;
89 }
90
91
92 # Invoke the given indirect-rule.
93 #
94 rule call ( [indirect-rule] r args * : * )
95 {
96 return [ modules.call-in [ get-module $(r) ] : [ get-rule $(r) ] $(args) :
97 $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) : $(10) : $(11) :
98 $(12) : $(13) : $(14) : $(15) : $(16) : $(17) : $(18) : $(19) ] ;
99 }
100
101
102 rule __test__
103 {
104 import assert ;
105
106 rule foo-barr! ( x )
107 {
108 assert.equal $(x) : x ;
109 }
110
111 assert.equal [ get-rule [ make foo-barr! ] ] : foo-barr! ;
112 assert.equal [ get-module [ make foo-barr! ] ] : [ CALLER_MODULE ] ;
113
114 call [ make foo-barr! ] x ;
115 call [ make foo-barr! x ] ;
116 call [ make foo-barr! : [ CALLER_MODULE ] ] x ;
117 }