|
|
|
|
|
|
|
|
|
|
|
|
|
.loaded ?= ; |
|
|
|
|
|
|
|
.loading ?= ; |
|
|
|
|
|
.untested ?= ; |
|
|
|
|
|
.tested ?= ; |
|
|
|
|
|
|
|
|
|
|
|
|
|
local rule run-module-test ( m ) |
|
{ |
|
local tested-modules = [ modules.peek modules : .tested ] ; |
|
|
|
if ( ! $(m) in $(tested-modules) ) |
|
&& ( ( --debug in $(argv) ) || ( --debug-module=$(m) in $(argv) ) ) |
|
{ |
|
modules.poke modules : .tested : $(tested-modules) $(m) ; |
|
|
|
if ! ( __test__ in [ RULENAMES $(m) ] ) |
|
{ |
|
local argv = [ peek : ARGV ] ; |
|
if ! ( --quiet in $(argv) ) && ( --debug-tests in $(argv) ) |
|
{ |
|
ECHO warning: no __test__ rule defined in module $(m) ; |
|
} |
|
} |
|
else |
|
{ |
|
if ! ( --quiet in $(argv) ) |
|
{ |
|
ECHO testing module $(m)... ; |
|
} |
|
|
|
local test-module = __test-$(m)__ ; |
|
IMPORT $(m) : [ RULENAMES $(m) ] : $(test-module) : [ RULENAMES $(m) ] ; |
|
IMPORT $(m) : __test__ : $(test-module) : __test__ : LOCALIZE ; |
|
module $(test-module) |
|
{ |
|
__test__ ; |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
rule binding ( module ) |
|
{ |
|
return $($(module).__binding__) ; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
rule poke ( module-name ? : variables + : value * ) |
|
{ |
|
module $(<) |
|
{ |
|
$(>) = $(3) ; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
rule peek ( module-name ? : variables + ) |
|
{ |
|
module $(<) |
|
{ |
|
return $($(>)) ; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rule call-in ( module-name ? : rule-name args * : * ) |
|
{ |
|
module $(module-name) |
|
{ |
|
return [ $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ] ; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rule call-locally ( qualified-rule-name args * : * ) |
|
{ |
|
local module-rule = [ MATCH (.*)\\.(.*) : $(qualified-rule-name) ] ; |
|
local rule-name = $(module-rule[2]) ; |
|
rule-name ?= $(qualified-rule-name) ; |
|
|
|
|
|
|
|
return [ call-in $(module-rule[1]) : $(rule-name) $(args) : $(2) : $(3) : |
|
$(4) : $(5) : $(6) : $(7) : $(8) ] ; |
|
} |
|
|
|
|
|
|
|
|
|
rule load ( |
|
module-name |
|
|
|
: filename ? |
|
: search * |
|
|
|
) |
|
{ |
|
|
|
if ! ( $(module-name) in $(.loaded) ) |
|
{ |
|
filename ?= $(module-name).jam ; |
|
|
|
|
|
.loaded += $(module-name) ; |
|
|
|
|
|
local suppress-test = $(.loading[1]) ; |
|
|
|
|
|
.loading += $(module-name) ; |
|
|
|
|
|
.untested += $(module-name) ; |
|
|
|
|
|
poke $(module-name) : __name__ : $(module-name) ; |
|
poke $(module-name) : __file__ : $(filename) ; |
|
|
|
module $(module-name) |
|
{ |
|
|
|
local module-target = $(__file__:G=module@) ; |
|
|
|
local search = $(3) ; |
|
search ?= [ modules.peek : BOOST_BUILD_PATH ] ; |
|
SEARCH on $(module-target) = $(search) ; |
|
BINDRULE on $(module-target) = modules.record-binding ; |
|
|
|
include $(module-target) ; |
|
|
|
|
|
local rules = [ RULENAMES $(__name__) ] ; |
|
IMPORT $(__name__) : $(rules) : $(__name__) : $(__name__).$(rules) ; |
|
} |
|
|
|
if $(module-name) != modules && ! [ binding $(module-name) ] |
|
{ |
|
import errors ; |
|
errors.error "Could not find module" $(module-name) in $(search) ; |
|
} |
|
|
|
|
|
|
|
.loading = $(.loading[1--2]) ; |
|
|
|
|
|
if ! $(suppress-test) |
|
{ |
|
local argv = [ peek : ARGV ] ; |
|
for local m in $(.untested) |
|
{ |
|
run-module-test $(m) ; |
|
} |
|
.untested = ; |
|
} |
|
} |
|
else if $(module-name) in $(.loading) |
|
{ |
|
import errors ; |
|
errors.error loading \"$(module-name)\" |
|
: circular module loading dependency: |
|
: $(.loading)" ->" $(module-name) ; |
|
} |
|
} |
|
|
|
|
|
# This helper is used by load (above) to record the binding (path) of each |
|
# loaded module. |
|
# |
|
rule record-binding ( module-target : binding ) |
|
{ |
|
$(.loading[-1]).__binding__ = $(binding) ; |
|
} |
|
|
|
|
|
# Transform each path in the list, with all backslashes converted to forward |
|
# slashes and all detectable redundancy removed. Something like this is probably |
|
# needed in path.jam, but I am not sure of that, I do not understand it, and I |
|
# am not ready to move all of path.jam into the kernel. |
|
# |
|
local rule normalize-raw-paths ( paths * ) |
|
{ |
|
local result ; |
|
for p in $(paths:T) |
|
{ |
|
result += [ NORMALIZE_PATH $(p) ] ; |
|
} |
|
return $(result) ; |
|
} |
|
|
|
|
|
.cwd = [ PWD ] ; |
|
|
|
|
|
# Load the indicated module and import rule names into the current module. Any |
|
# members of rules-opt will be available without qualification in the caller's |
|
# module. Any members of rename-opt will be taken as the names of the rules in |
|
# the caller's module, in place of the names they have in the imported module. |
|
# If rules-opt = '*', all rules from the indicated module are imported into the |
|
# caller's module. If rename-opt is supplied, it must have the same number of |
|
# elements as rules-opt. |
|
# |
|
rule import ( module-names + : rules-opt * : rename-opt * ) |
|
{ |
|
if ( $(rules-opt) = * || ! $(rules-opt) ) && $(rename-opt) |
|
{ |
|
import errors ; |
|
errors.error "Rule aliasing is only available for explicit imports." ; |
|
} |
|
|
|
if $(module-names[2]) && ( $(rules-opt) || $(rename-opt) ) |
|
{ |
|
import errors ; |
|
errors.error "When loading multiple modules, no specific rules or" |
|
"renaming is allowed" ; |
|
} |
|
|
|
local caller = [ CALLER_MODULE ] ; |
|
|
|
# Import each specified module |
|
for local m in $(module-names) |
|
{ |
|
if ! $(m) in $(.loaded) |
|
{ |
|
# If the importing module isn't already in the BOOST_BUILD_PATH, |
|
# prepend it to the path. We don't want to invert the search order |
|
# of modules that are already there. |
|
|
|
local caller-location ; |
|
if $(caller) |
|
{ |
|
caller-location = [ binding $(caller) ] ; |
|
caller-location = $(caller-location:D) ; |
|
caller-location = [ normalize-raw-paths $(caller-location:R=$(.cwd)) ] ; |
|
} |
|
|
|
local search = [ peek : BOOST_BUILD_PATH ] ; |
|
search = [ normalize-raw-paths $(search:R=$(.cwd)) ] ; |
|
|
|
if $(caller-location) && ! $(caller-location) in $(search) |
|
{ |
|
search = $(caller-location) $(search) ; |
|
} |
|
|
|
load $(m) : : $(search) ; |
|
} |
|
|
|
IMPORT_MODULE $(m) : $(caller) ; |
|
|
|
if $(rules-opt) |
|
{ |
|
local source-names ; |
|
if $(rules-opt) = * |
|
{ |
|
local all-rules = [ RULENAMES $(m) ] ; |
|
source-names = $(all-rules) ; |
|
} |
|
else |
|
{ |
|
source-names = $(rules-opt) ; |
|
} |
|
local target-names = $(rename-opt) ; |
|
target-names ?= $(source-names) ; |
|
IMPORT $(m) : $(source-names) : $(caller) : $(target-names) ; |
|
} |
|
} |
|
} |
|
|
|
|
|
# Define exported copies in $(target-module) of all rules exported from |
|
# $(source-module). Also make them available in the global module with |
|
# qualification, so that it is just as though the rules were defined originally |
|
# in $(target-module). |
|
# |
|
rule clone-rules ( source-module target-module ) |
|
{ |
|
local rules = [ RULENAMES $(source-module) ] ; |
|
|
|
IMPORT $(source-module) : $(rules) : $(target-module) : $(rules) : LOCALIZE ; |
|
EXPORT $(target-module) : $(rules) ; |
|
IMPORT $(target-module) : $(rules) : : $(target-module).$(rules) ; |
|
} |
|
|
|
|
|
# These rules need to be available in all modules to implement module loading |
|
# itself and other fundamental operations. |
|
local globalize = peek poke record-binding ; |
|
IMPORT modules : $(globalize) : : modules.$(globalize) ; |
|
|
|
|
|
rule __test__ ( ) |
|
{ |
|
import assert ; |
|
import modules : normalize-raw-paths ; |
|
|
|
module modules.__test__ |
|
{ |
|
foo = bar ; |
|
} |
|
|
|
assert.result bar : peek modules.__test__ : foo ; |
|
|
|
poke modules.__test__ : foo : bar baz ; |
|
assert.result bar baz : peek modules.__test__ : foo ; |
|
|
|
assert.result c:/foo/bar : normalize-raw-paths c:/x/../foo/./xx/yy/../../bar ; |
|
assert.result . : normalize-raw-paths . ; |
|
assert.result .. : normalize-raw-paths .. ; |
|
assert.result ../.. : normalize-raw-paths ../.. ; |
|
assert.result .. : normalize-raw-paths ./.. ; |
|
assert.result / / : normalize-raw-paths / \\ ; |
|
assert.result a : normalize-raw-paths a ; |
|
assert.result a : normalize-raw-paths a/ ; |
|
assert.result /a : normalize-raw-paths /a/ ; |
|
assert.result / : normalize-raw-paths /a/.. ; |
|
} |
|
|