mirror of
https://github.com/boostorg/build.git
synced 2026-02-15 13:02:11 +00:00
Modification of project handling and fixes.
* os.path.jam (basename, pwd, glob): New rules. Changed naming convention
for many other rules.
* project-root.jam: Use os.path everywhere.
* project.jam: Don't convert project paths to absolute paths. Use os.path.
* build-system.jam: Don't use absolute name when loading jamfile.
[SVN r13634]
This commit is contained in:
@@ -13,4 +13,4 @@ rule __dummy
|
||||
EXIT "don't call this rule" ;
|
||||
}
|
||||
|
||||
project.load [ PWD ] ;
|
||||
project.load "." ;
|
||||
|
||||
101
new/os.path.jam
101
new/os.path.jam
@@ -41,7 +41,7 @@ rule native ( path )
|
||||
#
|
||||
# Tests if a path is rooted
|
||||
#
|
||||
rule is_rooted ( path )
|
||||
rule is-rooted ( path )
|
||||
{
|
||||
return [ MATCH "^(/)" : $(path) ] ;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ rule is_rooted ( path )
|
||||
#
|
||||
# Tests if a path has a parent
|
||||
#
|
||||
rule has_parent ( path )
|
||||
rule has-parent ( path )
|
||||
{
|
||||
if $(path) != / {
|
||||
return 1 ;
|
||||
@@ -58,12 +58,20 @@ rule has_parent ( path )
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Returns the path without any directory components
|
||||
#
|
||||
rule basename ( path )
|
||||
{
|
||||
return [ MATCH "([^/]+)$" : $(path) ] ;
|
||||
}
|
||||
|
||||
#
|
||||
# Returns parent directory of the path. If no parent exists, error is issued.
|
||||
#
|
||||
rule parent ( path )
|
||||
{
|
||||
if [ has_parent $(path) ] {
|
||||
if [ has-parent $(path) ] {
|
||||
|
||||
if $(path) = . {
|
||||
return .. ;
|
||||
@@ -78,7 +86,7 @@ rule parent ( path )
|
||||
return $(path)/.. ;
|
||||
} else {
|
||||
if ! $(result[1]) {
|
||||
if [ is_rooted $(path) ] {
|
||||
if [ is-rooted $(path) ] {
|
||||
result = / ;
|
||||
} else {
|
||||
result = . ;
|
||||
@@ -101,7 +109,7 @@ rule reverse ( path )
|
||||
if $(path) = .
|
||||
{
|
||||
return $(path) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
local tokens = [ regex.split $(path) "/" ] ;
|
||||
@@ -125,7 +133,7 @@ rule join ( path1 path2 )
|
||||
else if $(path1) = /
|
||||
{
|
||||
return /$(path2) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
local parts = [ regex.match "((\.\./)*)(.*)" : $(path2) : 1 3 ] ;
|
||||
@@ -142,11 +150,11 @@ rule join ( path1 path2 )
|
||||
if $(path1) = .
|
||||
{
|
||||
return $(parts[2]) ;
|
||||
}
|
||||
else if $(path1) = /
|
||||
}
|
||||
else if $(path1) = /
|
||||
{
|
||||
return /$(parts[2]) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $(path1)/$(parts[2]) ;
|
||||
@@ -157,26 +165,42 @@ rule join ( path1 path2 )
|
||||
#
|
||||
# If 'path' is relative, it is rooted at 'root'. Otherwise, it's unchanged.
|
||||
#
|
||||
rule root_relative_path ( path root )
|
||||
rule root-relative-path ( path root )
|
||||
{
|
||||
if [ is_rooted $(path) ] {
|
||||
if [ is-rooted $(path) ] {
|
||||
return $(path) ;
|
||||
} else {
|
||||
return [ join $(root) $(path) ] ;
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Returns the current working directory
|
||||
#
|
||||
rule pwd ( )
|
||||
{
|
||||
return [ make [ PWD ] ] ;
|
||||
}
|
||||
|
||||
#
|
||||
# Returns the list of files matching the given pattern in the specified directory.
|
||||
#
|
||||
rule glob ( dir : pattern + )
|
||||
{
|
||||
return [ sequence.transform make : [ GLOB [ native $(dir) ] : $(pattern) ] ] ;
|
||||
}
|
||||
|
||||
#
|
||||
# Find out the absolute name of path and returns the list of all the parents,
|
||||
# starting with the immediate one. Parents are returned as relative names.
|
||||
# If 'upper_limit' is specified, directories above it will be pruned.
|
||||
#
|
||||
rule all_parents ( path : upper_limit ? : cwd ? )
|
||||
rule all-parents ( path : upper_limit ? : cwd ? )
|
||||
{
|
||||
cwd ?= [ make [ PWD ] ] ;
|
||||
cwd ?= [ pwd ] ;
|
||||
local rpath ;
|
||||
if ! [ is_rooted $(path) ] {
|
||||
rpath = [ root_relative_path $(path) $(cwd) ] ;
|
||||
if ! [ is-rooted $(path) ] {
|
||||
rpath = [ root-relative-path $(path) $(cwd) ] ;
|
||||
} else {
|
||||
rpath = $(path) ;
|
||||
}
|
||||
@@ -184,8 +208,8 @@ rule all_parents ( path : upper_limit ? : cwd ? )
|
||||
if ! $(upper_limit) {
|
||||
upper_limit = / ;
|
||||
} else {
|
||||
if ! [ is_rooted $(upper_limit) ] {
|
||||
upper_limit = [ root_relative_path $(upper_limit) $(cwd) ] ;
|
||||
if ! [ is-rooted $(upper_limit) ] {
|
||||
upper_limit = [ root-relative-path $(upper_limit) $(cwd) ] ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,15 +237,15 @@ rule make-NT ( native )
|
||||
{
|
||||
local tokens = [ regex.split $(native) "[/\\]" ] ;
|
||||
local result ;
|
||||
|
||||
|
||||
# Handle paths ending with slashes
|
||||
if $(tokens[-1]) = ""
|
||||
{
|
||||
tokens = $(tokens[1--2]) ; # discard the empty element
|
||||
}
|
||||
|
||||
|
||||
result = [ sequence.join $(tokens) : "/" ] ;
|
||||
|
||||
|
||||
if [ regex.match "(^.:)" : $(native) ]
|
||||
{
|
||||
result = /$(result) ;
|
||||
@@ -253,17 +277,24 @@ rule __test__ ( ) {
|
||||
|
||||
import assert ;
|
||||
|
||||
assert.true is_rooted "/" ;
|
||||
assert.true is_rooted "/foo" ;
|
||||
assert.true is_rooted "/foo/bar" ;
|
||||
assert.result : is_rooted "." ;
|
||||
assert.result : is_rooted "foo" ;
|
||||
assert.result : is_rooted "foo/bar" ;
|
||||
assert.true is-rooted "/" ;
|
||||
assert.true is-rooted "/foo" ;
|
||||
assert.true is-rooted "/foo/bar" ;
|
||||
assert.result : is-rooted "." ;
|
||||
assert.result : is-rooted "foo" ;
|
||||
assert.result : is-rooted "foo/bar" ;
|
||||
|
||||
assert.true has_parent "foo" ;
|
||||
assert.true has_parent "foo/bar" ;
|
||||
assert.true has_parent "." ;
|
||||
assert.result : has_parent "/" ;
|
||||
assert.true has-parent "foo" ;
|
||||
assert.true has-parent "foo/bar" ;
|
||||
assert.true has-parent "." ;
|
||||
assert.result : has-parent "/" ;
|
||||
|
||||
assert.result "." : basename "." ;
|
||||
assert.result ".." : basename ".." ;
|
||||
assert.result "foo" : basename "foo" ;
|
||||
assert.result "foo" : basename "bar/foo" ;
|
||||
assert.result "foo" : basename "gaz/bar/foo" ;
|
||||
assert.result "foo" : basename "/gaz/bar/foo" ;
|
||||
|
||||
assert.result "." : parent "foo" ;
|
||||
assert.result "/" : parent "/foo" ;
|
||||
@@ -287,13 +318,13 @@ rule __test__ ( ) {
|
||||
assert.result "/foo" : join "/bar" "../foo" ;
|
||||
|
||||
local CWD = "/home/ghost/build" ;
|
||||
assert.result . .. ../.. ../../.. : all_parents "Jamfile" : "" : $(CWD) ;
|
||||
assert.result foo . .. ../.. ../../.. : all_parents "foo/Jamfile" : "" : $(CWD) ;
|
||||
assert.result ../Work .. ../.. ../../.. : all_parents "../Work/Jamfile" : "" : $(CWD) ;
|
||||
assert.result . .. ../.. ../../.. : all-parents "Jamfile" : "" : $(CWD) ;
|
||||
assert.result foo . .. ../.. ../../.. : all-parents "foo/Jamfile" : "" : $(CWD) ;
|
||||
assert.result ../Work .. ../.. ../../.. : all-parents "../Work/Jamfile" : "" : $(CWD) ;
|
||||
|
||||
local CWD = "/home/ghost" ;
|
||||
assert.result . .. : all_parents "Jamfile" : "/home" : $(CWD) ;
|
||||
assert.result . : all_parents "Jamfile" : "/home/ghost" : $(CWD) ;
|
||||
assert.result . .. : all-parents "Jamfile" : "/home" : $(CWD) ;
|
||||
assert.result . : all-parents "Jamfile" : "/home/ghost" : $(CWD) ;
|
||||
|
||||
local os = NT ;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ rule load (
|
||||
# Find the project-root.jam corresponding to this directory.
|
||||
#
|
||||
local project-root-to-load = [ find-to-root $(dir) : project-root.jam ] ;
|
||||
|
||||
|
||||
# No project-root file found.
|
||||
#
|
||||
if ! $(project-root-to-load)
|
||||
@@ -32,29 +32,32 @@ rule load (
|
||||
"directories."
|
||||
"Please consult the documentation at 'http://www.boost.org'." ;
|
||||
}
|
||||
|
||||
local project-root-module = project-root<$(project-root-to-load:D)> ;
|
||||
|
||||
|
||||
local project-root-location = [ os.path.make $(project-root-to-load) ] ;
|
||||
local project-root-dir = [ os.path.parent $(project-root-location) ] ;
|
||||
local project-root-module = project-root<$(project-root-dir)> ;
|
||||
|
||||
# Only bother with the rest if the project-root isn't loaded yet.
|
||||
#
|
||||
if ! [ modules.binding $(project-root-module) ]
|
||||
{
|
||||
# Give the new module all the rules from project-root-context
|
||||
modules.clone-rules project-root-context $(project-root-module) ;
|
||||
|
||||
|
||||
# Remember the project-root, and some info about it.
|
||||
#
|
||||
.project-root += $(project-root-module) ;
|
||||
modules.poke $(project-root-module) : .module : $(project-root-module) ;
|
||||
modules.poke $(project-root-module) : .location : $(project-root-to-load:D) ;
|
||||
|
||||
modules.poke $(project-root-module) : .location : $(project-root-dir) ;
|
||||
|
||||
# Load it within a module specifically for the project root.
|
||||
# The module system handles checking for multiple includes.
|
||||
#
|
||||
modules.load $(project-root-module)
|
||||
: $(project-root-to-load:D=) : $(project-root-to-load:D) ;
|
||||
: [ os.path.basename $(project-root-location) ]
|
||||
: $(project-root-dir) ;
|
||||
}
|
||||
|
||||
|
||||
# Return the module for the project.
|
||||
#
|
||||
return $(project-root-module) ;
|
||||
@@ -66,7 +69,7 @@ rule print ( )
|
||||
{
|
||||
import sequence ;
|
||||
import print ;
|
||||
|
||||
|
||||
print.section "Project Roots" ;
|
||||
local project-roots = [ sequence.insertion-sort $(.project-root) ] ;
|
||||
for local project-root in $(projects-roots)
|
||||
@@ -124,7 +127,7 @@ rule register-project (
|
||||
}
|
||||
|
||||
# Declare and set a project global constant. Project global constants are
|
||||
# normal variables but should not be changed. They are applied to each
|
||||
# normal variables but should not be changed. They are applied to each
|
||||
# Jamfile that is loaded under it's corresponding project-root.
|
||||
#
|
||||
rule constant (
|
||||
@@ -157,7 +160,7 @@ rule print ( )
|
||||
{
|
||||
import sequence ;
|
||||
import print ;
|
||||
|
||||
|
||||
print.section "'"$(.location)"'" Module for project-root is "'"$(.module)"'" ;
|
||||
if $(.constants)
|
||||
{
|
||||
|
||||
@@ -42,7 +42,7 @@ rule load ( jamfile-location )
|
||||
if $(loaded)
|
||||
{
|
||||
.projects += $(jamfile-location) ;
|
||||
|
||||
|
||||
for local subinclude in [ $(module-name).subincludes ]
|
||||
{
|
||||
load [ os.path.join $(jamfile-location) $(subinclude) ] ;
|
||||
@@ -65,7 +65,7 @@ rule lookup ( id )
|
||||
local location = $(split[1]) ;
|
||||
local project-id = $(split[2]) ;
|
||||
|
||||
if [ os.path.is_rooted $(project-id) ]
|
||||
if [ os.path.is-rooted $(project-id) ]
|
||||
{
|
||||
return $($(project-id).jamfile-location) ;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ rule lookup ( id )
|
||||
{
|
||||
local module-name = [ module-name $(location) ] ;
|
||||
local base-id = [ $(module-name).id ] ;
|
||||
|
||||
|
||||
if $(base-id)
|
||||
{
|
||||
local rooted-id = $(base-id)/$(project-id) ;
|
||||
@@ -107,7 +107,7 @@ rule project ( id ? : option1 * : option2 * : option3 * )
|
||||
import targets ;
|
||||
targets.create-abstract-project-target [ location ] ;
|
||||
}
|
||||
|
||||
|
||||
if $(option1) {
|
||||
assign-option [ CALLER_MODULE ] : $(option1) ;
|
||||
}
|
||||
@@ -143,14 +143,7 @@ rule assign-option ( module : option + )
|
||||
#
|
||||
rule module-name ( jamfile-location )
|
||||
{
|
||||
local absolute
|
||||
= [ os.path.native
|
||||
[ os.path.root_relative_path
|
||||
[ os.path.make $(jamfile-location) ]
|
||||
[ os.path.make [ PWD ] ]
|
||||
] ] ;
|
||||
|
||||
return Jamfile<$(absolute)> ;
|
||||
return Jamfile<$(jamfile-location)> ;
|
||||
}
|
||||
|
||||
#
|
||||
@@ -175,6 +168,7 @@ rule dump ( )
|
||||
|
||||
local project-root = [ $(module-name).project-root ] ;
|
||||
local parent = [ $(module-name).parent ] ;
|
||||
parent ?= none ;
|
||||
local requirements = [ $(module-name).requirements ] ;
|
||||
local default-build = [ $(module-name).default-build ] ;
|
||||
local source-location = [ $(module-name).source-location ] ;
|
||||
@@ -212,11 +206,12 @@ local rule find-jamfile (
|
||||
local jamfile-glob = ;
|
||||
if $(parent-root)
|
||||
{
|
||||
jamfile-glob = [ find-to-root $(dir:P) : $(JAMFILE) ] ;
|
||||
jamfile-glob = [ os.path.make
|
||||
[ find-to-root [ os.path.native $(dir:P) ] : $(JAMFILE) ] ] ;
|
||||
}
|
||||
else
|
||||
{
|
||||
jamfile-glob = [ GLOB $(dir) : $(JAMFILE) ] ;
|
||||
jamfile-glob = [ os.path.glob $(dir) : $(JAMFILE) ] ;
|
||||
}
|
||||
|
||||
# Normalize the paths of each file found.
|
||||
@@ -228,22 +223,18 @@ local rule find-jamfile (
|
||||
}
|
||||
for local jamfile in $(jamfile-glob)
|
||||
{
|
||||
local normalized = [ os.path.make $(jamfile) ] ;
|
||||
|
||||
normalized = [ os.path.root_relative_path $(normalized) [ os.path.make [ PWD ] ] ] ;
|
||||
|
||||
# Filter out if the found file is above the target parent root.
|
||||
if $(parent-root)
|
||||
{
|
||||
if ! [ MATCH "$(parent-root)\\/(.*)" : $(normalized) ]
|
||||
if ! [ MATCH "$(parent-root)\\/(.*)" : $(jamfile) ]
|
||||
{
|
||||
normalized = ;
|
||||
jamfile = ;
|
||||
}
|
||||
}
|
||||
|
||||
if $(normalized)
|
||||
if $(jamfile)
|
||||
{
|
||||
jamfile-found += [ os.path.native $(normalized) ] ;
|
||||
jamfile-found += $(jamfile) ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,7 +267,7 @@ local rule load-jamfile (
|
||||
|
||||
# The module of the jamfile.
|
||||
#
|
||||
local jamfile-module = Jamfile<$(jamfile-to-load[1]:D)> ;
|
||||
local jamfile-module = [ module-name [ os.path.parent $(jamfile-to-load[1]) ] ] ;
|
||||
|
||||
# Don't even bother with the rest if we know the file is already loaded.
|
||||
#
|
||||
@@ -289,8 +280,9 @@ local rule load-jamfile (
|
||||
{
|
||||
ECHO
|
||||
"WARNING: Found multiple Jamfiles at this '"$(dir)"' location!"
|
||||
"Loading the first one: '"$(jamfile-to-load[1]:D=)"'." ;
|
||||
"Loading the first one: '" [ os.path.basename $(jamfile-to-load[1]) ] "'." ;
|
||||
}
|
||||
|
||||
jamfile-to-load = $(jamfile-to-load[1]) ;
|
||||
|
||||
# Initialize the jamfile module before loading.
|
||||
@@ -304,7 +296,7 @@ local rule load-jamfile (
|
||||
|
||||
# Now load the Jamfile in it's own context.
|
||||
#
|
||||
modules.load $(jamfile-module) : $(jamfile-to-load) : . ;
|
||||
modules.load $(jamfile-module) : [ os.path.native $(jamfile-to-load) ] : . ;
|
||||
|
||||
# Indicate we loaded the Jamfile.
|
||||
#
|
||||
@@ -329,14 +321,14 @@ local rule initialize (
|
||||
# Make sure we've loaded the project-root corresponding to this
|
||||
# Jamfile.
|
||||
#
|
||||
local project-root-module = [ project-root.load $(jamfile:D) ] ;
|
||||
local project-root-module = [ project-root.load [ os.path.parent $(jamfile) ] ] ;
|
||||
local project-root = [ $(project-root-module).location ] ;
|
||||
|
||||
local parent = [ find-jamfile $(jamfile:D) $(project-root) ] ;
|
||||
local parent = [ find-jamfile [ os.path.parent $(jamfile) ] $(project-root) ] ;
|
||||
local parent-module = ;
|
||||
if $(parent)
|
||||
{
|
||||
parent-module = [ load $(parent[1]:D) ] ;
|
||||
parent-module = [ load [ os.path.parent $(parent[1]) ] ] ;
|
||||
}
|
||||
|
||||
module $(module-name)
|
||||
@@ -352,9 +344,9 @@ local rule initialize (
|
||||
modules.poke $(module-name) : __source-location__ : $(jamfile-location) ;
|
||||
modules.poke $(module-name) : __project-root__ : $(project-root) ;
|
||||
modules.poke $(module-name) : __project-root-module__ : $(project-root-module) ;
|
||||
modules.poke $(module-name) : __parent__ : $(parent) ;
|
||||
if $(parent-module)
|
||||
{
|
||||
modules.poke $(module-name) : __parent__ : [ os.path.parent $(parent) ] ;
|
||||
modules.poke $(module-name) : __default-build__ : [ $(parent-module).default-build ] ;
|
||||
modules.poke $(module-name) : __requirements__ : [ $(parent-module).requirements ] ;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ rule load ( jamfile-location )
|
||||
if $(loaded)
|
||||
{
|
||||
.projects += $(jamfile-location) ;
|
||||
|
||||
|
||||
for local subinclude in [ $(module-name).subincludes ]
|
||||
{
|
||||
load [ os.path.join $(jamfile-location) $(subinclude) ] ;
|
||||
@@ -65,7 +65,7 @@ rule lookup ( id )
|
||||
local location = $(split[1]) ;
|
||||
local project-id = $(split[2]) ;
|
||||
|
||||
if [ os.path.is_rooted $(project-id) ]
|
||||
if [ os.path.is-rooted $(project-id) ]
|
||||
{
|
||||
return $($(project-id).jamfile-location) ;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ rule lookup ( id )
|
||||
{
|
||||
local module-name = [ module-name $(location) ] ;
|
||||
local base-id = [ $(module-name).id ] ;
|
||||
|
||||
|
||||
if $(base-id)
|
||||
{
|
||||
local rooted-id = $(base-id)/$(project-id) ;
|
||||
@@ -107,7 +107,7 @@ rule project ( id ? : option1 * : option2 * : option3 * )
|
||||
import targets ;
|
||||
targets.create-abstract-project-target [ location ] ;
|
||||
}
|
||||
|
||||
|
||||
if $(option1) {
|
||||
assign-option [ CALLER_MODULE ] : $(option1) ;
|
||||
}
|
||||
@@ -143,14 +143,7 @@ rule assign-option ( module : option + )
|
||||
#
|
||||
rule module-name ( jamfile-location )
|
||||
{
|
||||
local absolute
|
||||
= [ os.path.native
|
||||
[ os.path.root_relative_path
|
||||
[ os.path.make $(jamfile-location) ]
|
||||
[ os.path.make [ PWD ] ]
|
||||
] ] ;
|
||||
|
||||
return Jamfile<$(absolute)> ;
|
||||
return Jamfile<$(jamfile-location)> ;
|
||||
}
|
||||
|
||||
#
|
||||
@@ -175,6 +168,7 @@ rule dump ( )
|
||||
|
||||
local project-root = [ $(module-name).project-root ] ;
|
||||
local parent = [ $(module-name).parent ] ;
|
||||
parent ?= none ;
|
||||
local requirements = [ $(module-name).requirements ] ;
|
||||
local default-build = [ $(module-name).default-build ] ;
|
||||
local source-location = [ $(module-name).source-location ] ;
|
||||
@@ -212,11 +206,12 @@ local rule find-jamfile (
|
||||
local jamfile-glob = ;
|
||||
if $(parent-root)
|
||||
{
|
||||
jamfile-glob = [ find-to-root $(dir:P) : $(JAMFILE) ] ;
|
||||
jamfile-glob = [ os.path.make
|
||||
[ find-to-root [ os.path.native $(dir:P) ] : $(JAMFILE) ] ] ;
|
||||
}
|
||||
else
|
||||
{
|
||||
jamfile-glob = [ GLOB $(dir) : $(JAMFILE) ] ;
|
||||
jamfile-glob = [ os.path.glob $(dir) : $(JAMFILE) ] ;
|
||||
}
|
||||
|
||||
# Normalize the paths of each file found.
|
||||
@@ -228,22 +223,18 @@ local rule find-jamfile (
|
||||
}
|
||||
for local jamfile in $(jamfile-glob)
|
||||
{
|
||||
local normalized = [ os.path.make $(jamfile) ] ;
|
||||
|
||||
normalized = [ os.path.root_relative_path $(normalized) [ os.path.make [ PWD ] ] ] ;
|
||||
|
||||
# Filter out if the found file is above the target parent root.
|
||||
if $(parent-root)
|
||||
{
|
||||
if ! [ MATCH "$(parent-root)\\/(.*)" : $(normalized) ]
|
||||
if ! [ MATCH "$(parent-root)\\/(.*)" : $(jamfile) ]
|
||||
{
|
||||
normalized = ;
|
||||
jamfile = ;
|
||||
}
|
||||
}
|
||||
|
||||
if $(normalized)
|
||||
if $(jamfile)
|
||||
{
|
||||
jamfile-found += [ os.path.native $(normalized) ] ;
|
||||
jamfile-found += $(jamfile) ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,7 +267,7 @@ local rule load-jamfile (
|
||||
|
||||
# The module of the jamfile.
|
||||
#
|
||||
local jamfile-module = Jamfile<$(jamfile-to-load[1]:D)> ;
|
||||
local jamfile-module = [ module-name [ os.path.parent $(jamfile-to-load[1]) ] ] ;
|
||||
|
||||
# Don't even bother with the rest if we know the file is already loaded.
|
||||
#
|
||||
@@ -289,8 +280,9 @@ local rule load-jamfile (
|
||||
{
|
||||
ECHO
|
||||
"WARNING: Found multiple Jamfiles at this '"$(dir)"' location!"
|
||||
"Loading the first one: '"$(jamfile-to-load[1]:D=)"'." ;
|
||||
"Loading the first one: '" [ os.path.basename $(jamfile-to-load[1]) ] "'." ;
|
||||
}
|
||||
|
||||
jamfile-to-load = $(jamfile-to-load[1]) ;
|
||||
|
||||
# Initialize the jamfile module before loading.
|
||||
@@ -304,7 +296,7 @@ local rule load-jamfile (
|
||||
|
||||
# Now load the Jamfile in it's own context.
|
||||
#
|
||||
modules.load $(jamfile-module) : $(jamfile-to-load) : . ;
|
||||
modules.load $(jamfile-module) : [ os.path.native $(jamfile-to-load) ] : . ;
|
||||
|
||||
# Indicate we loaded the Jamfile.
|
||||
#
|
||||
@@ -329,14 +321,14 @@ local rule initialize (
|
||||
# Make sure we've loaded the project-root corresponding to this
|
||||
# Jamfile.
|
||||
#
|
||||
local project-root-module = [ project-root.load $(jamfile:D) ] ;
|
||||
local project-root-module = [ project-root.load [ os.path.parent $(jamfile) ] ] ;
|
||||
local project-root = [ $(project-root-module).location ] ;
|
||||
|
||||
local parent = [ find-jamfile $(jamfile:D) $(project-root) ] ;
|
||||
local parent = [ find-jamfile [ os.path.parent $(jamfile) ] $(project-root) ] ;
|
||||
local parent-module = ;
|
||||
if $(parent)
|
||||
{
|
||||
parent-module = [ load $(parent[1]:D) ] ;
|
||||
parent-module = [ load [ os.path.parent $(parent[1]) ] ] ;
|
||||
}
|
||||
|
||||
module $(module-name)
|
||||
@@ -352,9 +344,9 @@ local rule initialize (
|
||||
modules.poke $(module-name) : __source-location__ : $(jamfile-location) ;
|
||||
modules.poke $(module-name) : __project-root__ : $(project-root) ;
|
||||
modules.poke $(module-name) : __project-root-module__ : $(project-root-module) ;
|
||||
modules.poke $(module-name) : __parent__ : $(parent) ;
|
||||
if $(parent-module)
|
||||
{
|
||||
modules.poke $(module-name) : __parent__ : [ os.path.parent $(parent) ] ;
|
||||
modules.poke $(module-name) : __default-build__ : [ $(parent-module).default-build ] ;
|
||||
modules.poke $(module-name) : __requirements__ : [ $(parent-module).requirements ] ;
|
||||
}
|
||||
|
||||
101
v2/os.path.jam
101
v2/os.path.jam
@@ -41,7 +41,7 @@ rule native ( path )
|
||||
#
|
||||
# Tests if a path is rooted
|
||||
#
|
||||
rule is_rooted ( path )
|
||||
rule is-rooted ( path )
|
||||
{
|
||||
return [ MATCH "^(/)" : $(path) ] ;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ rule is_rooted ( path )
|
||||
#
|
||||
# Tests if a path has a parent
|
||||
#
|
||||
rule has_parent ( path )
|
||||
rule has-parent ( path )
|
||||
{
|
||||
if $(path) != / {
|
||||
return 1 ;
|
||||
@@ -58,12 +58,20 @@ rule has_parent ( path )
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Returns the path without any directory components
|
||||
#
|
||||
rule basename ( path )
|
||||
{
|
||||
return [ MATCH "([^/]+)$" : $(path) ] ;
|
||||
}
|
||||
|
||||
#
|
||||
# Returns parent directory of the path. If no parent exists, error is issued.
|
||||
#
|
||||
rule parent ( path )
|
||||
{
|
||||
if [ has_parent $(path) ] {
|
||||
if [ has-parent $(path) ] {
|
||||
|
||||
if $(path) = . {
|
||||
return .. ;
|
||||
@@ -78,7 +86,7 @@ rule parent ( path )
|
||||
return $(path)/.. ;
|
||||
} else {
|
||||
if ! $(result[1]) {
|
||||
if [ is_rooted $(path) ] {
|
||||
if [ is-rooted $(path) ] {
|
||||
result = / ;
|
||||
} else {
|
||||
result = . ;
|
||||
@@ -101,7 +109,7 @@ rule reverse ( path )
|
||||
if $(path) = .
|
||||
{
|
||||
return $(path) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
local tokens = [ regex.split $(path) "/" ] ;
|
||||
@@ -125,7 +133,7 @@ rule join ( path1 path2 )
|
||||
else if $(path1) = /
|
||||
{
|
||||
return /$(path2) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
local parts = [ regex.match "((\.\./)*)(.*)" : $(path2) : 1 3 ] ;
|
||||
@@ -142,11 +150,11 @@ rule join ( path1 path2 )
|
||||
if $(path1) = .
|
||||
{
|
||||
return $(parts[2]) ;
|
||||
}
|
||||
else if $(path1) = /
|
||||
}
|
||||
else if $(path1) = /
|
||||
{
|
||||
return /$(parts[2]) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $(path1)/$(parts[2]) ;
|
||||
@@ -157,26 +165,42 @@ rule join ( path1 path2 )
|
||||
#
|
||||
# If 'path' is relative, it is rooted at 'root'. Otherwise, it's unchanged.
|
||||
#
|
||||
rule root_relative_path ( path root )
|
||||
rule root-relative-path ( path root )
|
||||
{
|
||||
if [ is_rooted $(path) ] {
|
||||
if [ is-rooted $(path) ] {
|
||||
return $(path) ;
|
||||
} else {
|
||||
return [ join $(root) $(path) ] ;
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Returns the current working directory
|
||||
#
|
||||
rule pwd ( )
|
||||
{
|
||||
return [ make [ PWD ] ] ;
|
||||
}
|
||||
|
||||
#
|
||||
# Returns the list of files matching the given pattern in the specified directory.
|
||||
#
|
||||
rule glob ( dir : pattern + )
|
||||
{
|
||||
return [ sequence.transform make : [ GLOB [ native $(dir) ] : $(pattern) ] ] ;
|
||||
}
|
||||
|
||||
#
|
||||
# Find out the absolute name of path and returns the list of all the parents,
|
||||
# starting with the immediate one. Parents are returned as relative names.
|
||||
# If 'upper_limit' is specified, directories above it will be pruned.
|
||||
#
|
||||
rule all_parents ( path : upper_limit ? : cwd ? )
|
||||
rule all-parents ( path : upper_limit ? : cwd ? )
|
||||
{
|
||||
cwd ?= [ make [ PWD ] ] ;
|
||||
cwd ?= [ pwd ] ;
|
||||
local rpath ;
|
||||
if ! [ is_rooted $(path) ] {
|
||||
rpath = [ root_relative_path $(path) $(cwd) ] ;
|
||||
if ! [ is-rooted $(path) ] {
|
||||
rpath = [ root-relative-path $(path) $(cwd) ] ;
|
||||
} else {
|
||||
rpath = $(path) ;
|
||||
}
|
||||
@@ -184,8 +208,8 @@ rule all_parents ( path : upper_limit ? : cwd ? )
|
||||
if ! $(upper_limit) {
|
||||
upper_limit = / ;
|
||||
} else {
|
||||
if ! [ is_rooted $(upper_limit) ] {
|
||||
upper_limit = [ root_relative_path $(upper_limit) $(cwd) ] ;
|
||||
if ! [ is-rooted $(upper_limit) ] {
|
||||
upper_limit = [ root-relative-path $(upper_limit) $(cwd) ] ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,15 +237,15 @@ rule make-NT ( native )
|
||||
{
|
||||
local tokens = [ regex.split $(native) "[/\\]" ] ;
|
||||
local result ;
|
||||
|
||||
|
||||
# Handle paths ending with slashes
|
||||
if $(tokens[-1]) = ""
|
||||
{
|
||||
tokens = $(tokens[1--2]) ; # discard the empty element
|
||||
}
|
||||
|
||||
|
||||
result = [ sequence.join $(tokens) : "/" ] ;
|
||||
|
||||
|
||||
if [ regex.match "(^.:)" : $(native) ]
|
||||
{
|
||||
result = /$(result) ;
|
||||
@@ -253,17 +277,24 @@ rule __test__ ( ) {
|
||||
|
||||
import assert ;
|
||||
|
||||
assert.true is_rooted "/" ;
|
||||
assert.true is_rooted "/foo" ;
|
||||
assert.true is_rooted "/foo/bar" ;
|
||||
assert.result : is_rooted "." ;
|
||||
assert.result : is_rooted "foo" ;
|
||||
assert.result : is_rooted "foo/bar" ;
|
||||
assert.true is-rooted "/" ;
|
||||
assert.true is-rooted "/foo" ;
|
||||
assert.true is-rooted "/foo/bar" ;
|
||||
assert.result : is-rooted "." ;
|
||||
assert.result : is-rooted "foo" ;
|
||||
assert.result : is-rooted "foo/bar" ;
|
||||
|
||||
assert.true has_parent "foo" ;
|
||||
assert.true has_parent "foo/bar" ;
|
||||
assert.true has_parent "." ;
|
||||
assert.result : has_parent "/" ;
|
||||
assert.true has-parent "foo" ;
|
||||
assert.true has-parent "foo/bar" ;
|
||||
assert.true has-parent "." ;
|
||||
assert.result : has-parent "/" ;
|
||||
|
||||
assert.result "." : basename "." ;
|
||||
assert.result ".." : basename ".." ;
|
||||
assert.result "foo" : basename "foo" ;
|
||||
assert.result "foo" : basename "bar/foo" ;
|
||||
assert.result "foo" : basename "gaz/bar/foo" ;
|
||||
assert.result "foo" : basename "/gaz/bar/foo" ;
|
||||
|
||||
assert.result "." : parent "foo" ;
|
||||
assert.result "/" : parent "/foo" ;
|
||||
@@ -287,13 +318,13 @@ rule __test__ ( ) {
|
||||
assert.result "/foo" : join "/bar" "../foo" ;
|
||||
|
||||
local CWD = "/home/ghost/build" ;
|
||||
assert.result . .. ../.. ../../.. : all_parents "Jamfile" : "" : $(CWD) ;
|
||||
assert.result foo . .. ../.. ../../.. : all_parents "foo/Jamfile" : "" : $(CWD) ;
|
||||
assert.result ../Work .. ../.. ../../.. : all_parents "../Work/Jamfile" : "" : $(CWD) ;
|
||||
assert.result . .. ../.. ../../.. : all-parents "Jamfile" : "" : $(CWD) ;
|
||||
assert.result foo . .. ../.. ../../.. : all-parents "foo/Jamfile" : "" : $(CWD) ;
|
||||
assert.result ../Work .. ../.. ../../.. : all-parents "../Work/Jamfile" : "" : $(CWD) ;
|
||||
|
||||
local CWD = "/home/ghost" ;
|
||||
assert.result . .. : all_parents "Jamfile" : "/home" : $(CWD) ;
|
||||
assert.result . : all_parents "Jamfile" : "/home/ghost" : $(CWD) ;
|
||||
assert.result . .. : all-parents "Jamfile" : "/home" : $(CWD) ;
|
||||
assert.result . : all-parents "Jamfile" : "/home/ghost" : $(CWD) ;
|
||||
|
||||
local os = NT ;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ rule load (
|
||||
# Find the project-root.jam corresponding to this directory.
|
||||
#
|
||||
local project-root-to-load = [ find-to-root $(dir) : project-root.jam ] ;
|
||||
|
||||
|
||||
# No project-root file found.
|
||||
#
|
||||
if ! $(project-root-to-load)
|
||||
@@ -32,29 +32,32 @@ rule load (
|
||||
"directories."
|
||||
"Please consult the documentation at 'http://www.boost.org'." ;
|
||||
}
|
||||
|
||||
local project-root-module = project-root<$(project-root-to-load:D)> ;
|
||||
|
||||
|
||||
local project-root-location = [ os.path.make $(project-root-to-load) ] ;
|
||||
local project-root-dir = [ os.path.parent $(project-root-location) ] ;
|
||||
local project-root-module = project-root<$(project-root-dir)> ;
|
||||
|
||||
# Only bother with the rest if the project-root isn't loaded yet.
|
||||
#
|
||||
if ! [ modules.binding $(project-root-module) ]
|
||||
{
|
||||
# Give the new module all the rules from project-root-context
|
||||
modules.clone-rules project-root-context $(project-root-module) ;
|
||||
|
||||
|
||||
# Remember the project-root, and some info about it.
|
||||
#
|
||||
.project-root += $(project-root-module) ;
|
||||
modules.poke $(project-root-module) : .module : $(project-root-module) ;
|
||||
modules.poke $(project-root-module) : .location : $(project-root-to-load:D) ;
|
||||
|
||||
modules.poke $(project-root-module) : .location : $(project-root-dir) ;
|
||||
|
||||
# Load it within a module specifically for the project root.
|
||||
# The module system handles checking for multiple includes.
|
||||
#
|
||||
modules.load $(project-root-module)
|
||||
: $(project-root-to-load:D=) : $(project-root-to-load:D) ;
|
||||
: [ os.path.basename $(project-root-location) ]
|
||||
: $(project-root-dir) ;
|
||||
}
|
||||
|
||||
|
||||
# Return the module for the project.
|
||||
#
|
||||
return $(project-root-module) ;
|
||||
@@ -66,7 +69,7 @@ rule print ( )
|
||||
{
|
||||
import sequence ;
|
||||
import print ;
|
||||
|
||||
|
||||
print.section "Project Roots" ;
|
||||
local project-roots = [ sequence.insertion-sort $(.project-root) ] ;
|
||||
for local project-root in $(projects-roots)
|
||||
@@ -124,7 +127,7 @@ rule register-project (
|
||||
}
|
||||
|
||||
# Declare and set a project global constant. Project global constants are
|
||||
# normal variables but should not be changed. They are applied to each
|
||||
# normal variables but should not be changed. They are applied to each
|
||||
# Jamfile that is loaded under it's corresponding project-root.
|
||||
#
|
||||
rule constant (
|
||||
@@ -157,7 +160,7 @@ rule print ( )
|
||||
{
|
||||
import sequence ;
|
||||
import print ;
|
||||
|
||||
|
||||
print.section "'"$(.location)"'" Module for project-root is "'"$(.module)"'" ;
|
||||
if $(.constants)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user