2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-20 02:32:13 +00:00

No functional changes but only stylistic changes such as: comment typo corrections, wrapping lines to 80 characters, indentations, removing trailing spaces, removing empty lines, made tests use Jamfile.jam and Jamroot.jam Boost Build script names, removed unnecessary module imports, etc.

[SVN r42506]
This commit is contained in:
Jurko Gospodnetić
2008-01-06 00:25:48 +00:00
parent 034e54f68d
commit d96735566f
10 changed files with 192 additions and 204 deletions

View File

@@ -222,6 +222,7 @@ rule nearest-user-location ( )
return $(result) ;
}
# If optimized rule is available in Jam, use it.
if NEAREST_USER_LOCATION in [ RULENAMES ]
{
@@ -233,7 +234,6 @@ if NEAREST_USER_LOCATION in [ RULENAMES ]
}
rule __test__ ( )
{
# Show that we can correctly catch an expected error.

View File

@@ -1,55 +1,47 @@
#!/usr/bin/python
# Copyright 2003 Dave Abrahams
# Copyright 2002, 2003, 2004 Vladimir Prus
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
# Copyright 2003 Dave Abrahams
# Copyright 2002, 2003, 2004 Vladimir Prus
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
# Test conditional properties
# Test conditional properties.
from BoostBuild import Tester, List
import os
from string import strip
import BoostBuild
t = Tester()
t = BoostBuild.Tester()
# Arrange a project which will build only if
# 'a.cpp' is compiled with "STATIC" define.
t.write("project-root.jam", "import gcc ;")
# Arrange a project which will build only if 'a.cpp' is compiled with "STATIC"
# define.
t.write("a.cpp", """
#ifdef STATIC
int main() { return 0; }
int main() { return 0; }
#endif
""")
t.write("Jamfile", "exe a : a.cpp : <link>static:<define>STATIC ;")
# Test conditionals in target requirements.
t.write("Jamroot.jam", "exe a : a.cpp : <link>static:<define>STATIC ;")
t.run_build_system("link=static")
t.expect_addition("bin/$toolset/debug/link-static/a.exe")
t.rm("bin")
t.write("Jamfile", """
# Test conditionals in project requirements.
t.write("Jamroot.jam", """
project : requirements <link>static:<define>STATIC ;
exe a : a.cpp ;
""")
t.rm("bin")
t.run_build_system("link=static")
t.expect_addition("bin/$toolset/debug/link-static/a.exe")
t.rm("bin")
# Regression test for a bug found by Ali Azarbayejani.
# Conditionals inside usage requirement were not evaluated.
# This breaks
t.write("Jamfile", """
# Regression test for a bug found by Ali Azarbayejani. Conditionals inside usage
# requirement were not being evaluated.
t.write("Jamroot.jam", """
lib l : l.cpp : : : <link>static:<define>STATIC ;
exe a : a.cpp l ;
""")
t.write("l.cpp", "")
t.write("l.cpp", """
int i;
""")
t.rm("bin")
t.write("l.cpp", "int i;")
t.run_build_system("link=static")
t.expect_addition("bin/$toolset/debug/link-static/a.exe")
t.cleanup()

View File

@@ -1,35 +1,33 @@
#!/usr/bin/python
# Copyright 2003 Vladimir Prus
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
# Copyright 2003 Vladimir Prus
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
# Regression test: it was possible that due to evaluation of conditional
# requirements, two different values of non-free features were present in
# property set.
from BoostBuild import Tester, List
import BoostBuild
t = Tester()
t.write("project-root.jam", "")
t = BoostBuild.Tester()
t.write("a.cpp", "")
t.write("Jamfile", """
import feature : feature ;
import common : file-creation-command ;
t.write("Jamroot.jam", """
import feature ;
import common ;
feature the_feature : false true : propagated ;
feature.feature the_feature : false true : propagated ;
rule maker ( targets * : sources * : properties * )
{
if <the_feature>false in $(properties)
&& <the_feature>true in $(properties)
if <the_feature>false in $(properties) &&
<the_feature>true in $(properties)
{
EXIT "Oops, two different values of non-free feature" ;
}
CMD on $(targets) = [ file-creation-command ] ;
}
CMD on $(targets) = [ common.file-creation-command ] ;
}
actions maker
@@ -37,12 +35,9 @@ actions maker
$(CMD) $(<) ;
}
make a : a.cpp : maker : <variant>debug:<the_feature>true ;
make a : a.cpp : maker : <variant>debug:<the_feature>true ;
""")
t.run_build_system()
t.cleanup()

View File

@@ -1,19 +1,17 @@
#!/usr/bin/python
# Copyright 2003 Vladimir Prus
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
# Copyright 2003 Vladimir Prus
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
# Test that conditional properties work, even if property is free, and
# value includes colon.
from BoostBuild import Tester, List
# Test that conditional properties work, even if property is free, and value
# includes a colon.
import BoostBuild
t = Tester()
t = BoostBuild.Tester()
# Create the needed files
t.write("project-root.jam", "")
t.write("Jamfile", """
t.write("Jamroot.jam", """
exe hello : hello.cpp : <variant>debug:<define>CLASS=Foo::Bar ;
""")
t.write("hello.cpp", """
@@ -21,12 +19,11 @@ namespace Foo { class Bar { } ; }
int main()
{
CLASS c;
c; // Disables the unused variable warning.
return 0;
}
""")
# Don't check stderr, which can include warning about unused 'c'.
t.run_build_system(stdout=None, stderr=None)
t.expect_addition("bin/$toolset/debug/hello.exe")

View File

@@ -106,6 +106,9 @@ tests = [ "rebuilds",
"default_build",
"use_requirements",
"conditionals",
"conditionals2",
"conditionals3",
"indirect_conditional",
"stage",
"prebuilt",
"project_dependencies",
@@ -124,10 +127,8 @@ tests = [ "rebuilds",
"bad_dirname",
"c_file",
"inline",
"conditionals2",
"property_expansion",
"loop",
"conditionals3",
"tag",
"suffix",
"inherit_toolset",
@@ -154,7 +155,6 @@ tests = [ "rebuilds",
"project_root_rule",
"resolution",
"build_file",
"indirect_conditional",
"build_no",
"disambiguation",
"clean",

View File

@@ -30,6 +30,5 @@ rule init ( * : * )
{
toolset.using intel-win :
$(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
}
}

View File

@@ -9,17 +9,16 @@
# License Version 1.0. (See accompanying file LICENSE_1_0.txt or
# http://www.boost.org/LICENSE_1_0.txt)
import "class" : new ;
import property ;
import generators ;
import os ;
import type ;
import toolset : flags ;
import errors : error ;
import feature : feature get-values ;
import errors ;
import feature ;
import path ;
import sequence : unique ;
import common ;
import "class" : new ;
import rc ;
import midl ;
import mc ;
@@ -126,10 +125,10 @@ rule configure ( version ? : options * )
case all :
if $(options)
{
error "msvc: options should be empty when 'all' is specified" ;
errors.error "msvc: options should be empty when 'all' is specified" ;
}
# use all detected versions
# Use all detected versions.
for local v in [ $(.versions).all ]
{
configure-really $(v) ;
@@ -190,7 +189,7 @@ local rule configure-really ( version ? : options * )
# if the identical sets of options are used
if $(options) && ( $(options) != [ $(.versions).get $(version) : options ] )
{
error "msvc: the toolset version '$(version)' is configured already" ;
errors.error "msvc: the toolset version '$(version)' is configured already" ;
}
}
else
@@ -209,7 +208,7 @@ local rule configure-really ( version ? : options * )
$(.versions).set $(version) : condition : $(condition) ;
local command = [ get-values <command> : $(options) ] ;
local command = [ feature.get-values <command> : $(options) ] ;
# If version is specified, we try to search first in default paths, and
# only then in PATH.
@@ -265,9 +264,9 @@ local rule configure-really ( version ? : options * )
parent = [ path.parent $(parent) ] ;
parent = [ path.native $(parent) ] ;
# setup will be used if the script name has been specified. If setup
# Setup will be used if the script name has been specified. If setup
# is not specified, a default script will be used instead.
setup = [ get-values <setup> : $(options) ] ;
setup = [ feature.get-values <setup> : $(options) ] ;
if ! $(setup)
{
@@ -325,32 +324,32 @@ local rule configure-really ( version ? : options * )
command = $(prefix)$(setup)" "$(setup-option:E="")$(suffix) ;
# Setup script is not required in some configurations
# Setup script is not required in some configurations.
command ?= "" ;
# Get tool names (if any) and finish setup.
compiler = [ get-values <compiler> : $(options) ] ;
compiler = [ feature.get-values <compiler> : $(options) ] ;
compiler ?= cl ;
linker = [ get-values <linker> : $(options) ] ;
linker = [ feature.get-values <linker> : $(options) ] ;
linker ?= link ;
resource-compiler = [ get-values <resource-compiler> : $(options) ] ;
resource-compiler = [ feature.get-values <resource-compiler> : $(options) ] ;
resource-compiler ?= rc ;
assembler = [ get-values <assembler> : $(options) ] ;
assembler = [ feature.get-values <assembler> : $(options) ] ;
assembler ?= ml ;
idl-compiler = [ get-values <idl-compiler> : $(options) ] ;
idl-compiler = [ feature.get-values <idl-compiler> : $(options) ] ;
idl-compiler ?= midl ;
mc-compiler = [ get-values <mc-compiler> : $(options) ] ;
mc-compiler = [ feature.get-values <mc-compiler> : $(options) ] ;
mc-compiler ?= mc ;
manifest-tool = mt ;
local cc-filter = [ get-values <compiler-filter> : $(options) ] ;
local cc-filter = [ feature.get-values <compiler-filter> : $(options) ] ;
for local i in 1 2 3
{
@@ -366,30 +365,30 @@ local rule configure-really ( version ? : options * )
"command: '$(command[$(i)])'" ;
}
flags msvc.compile .CC $(cond) : $(command[$(i)])$(compiler) /Zm800 -nologo ;
flags msvc.compile .RC $(cond) : $(command[$(i)])$(resource-compiler) ;
flags msvc.compile .ASM $(cond) : $(command[$(i)])$(assembler) ;
flags msvc.link .LD $(cond) : $(command[$(i)])$(linker) /NOLOGO /INCREMENTAL:NO ;
flags msvc.archive .LD $(cond) : $(command[$(i)])$(linker) /lib /NOLOGO ;
flags msvc.compile .IDL $(cond) : $(command[$(i)])$(idl-compiler) ;
flags msvc.compile .MC $(cond) : $(command[$(i)])$(mc-compiler) ;
toolset.flags msvc.compile .CC $(cond) : $(command[$(i)])$(compiler) /Zm800 -nologo ;
toolset.flags msvc.compile .RC $(cond) : $(command[$(i)])$(resource-compiler) ;
toolset.flags msvc.compile .ASM $(cond) : $(command[$(i)])$(assembler) ;
toolset.flags msvc.link .LD $(cond) : $(command[$(i)])$(linker) /NOLOGO /INCREMENTAL:NO ;
toolset.flags msvc.archive .LD $(cond) : $(command[$(i)])$(linker) /lib /NOLOGO ;
toolset.flags msvc.compile .IDL $(cond) : $(command[$(i)])$(idl-compiler) ;
toolset.flags msvc.compile .MC $(cond) : $(command[$(i)])$(mc-compiler) ;
if ! [ os.name ] in NT
{
flags msvc.link .MT $(cond) : $(command[$(i)])$(manifest-tool) -nologo ;
toolset.flags msvc.link .MT $(cond) : $(command[$(i)])$(manifest-tool) -nologo ;
}
else
{
flags msvc.link .MT $(cond) : $(manifest-tool) -nologo ;
toolset.flags msvc.link .MT $(cond) : $(manifest-tool) -nologo ;
}
if $(cc-filter)
{
flags msvc .CC.FILTER $(cond) : "|" $(cc-filter) ;
toolset.flags msvc .CC.FILTER $(cond) : "|" $(cc-filter) ;
}
}
}
# Set version-specific flags
# Set version-specific flags.
configure-version-specific msvc : $(version) : $(condition) ;
}
}
@@ -430,14 +429,14 @@ rule configure-version-specific ( toolset : version : condition )
# 7.* explicitly, or if the installation path contain 7.* (checked above).
if ! [ MATCH ^(6\\.) : $(version) ]
{
flags $(toolset).compile CFLAGS $(condition) : /Zc:forScope /Zc:wchar_t ;
flags $(toolset).compile.c++ C++FLAGS $(condition) : /wd4675 ;
toolset.flags $(toolset).compile CFLAGS $(condition) : /Zc:forScope /Zc:wchar_t ;
toolset.flags $(toolset).compile.c++ C++FLAGS $(condition) : /wd4675 ;
# disable the function is deprecated warning
# Some version of msvc have a bug, that cause deprecation
# warning to be emitted even with /W0
flags $(toolset).compile CFLAGS $(condition)/<warnings>off : /wd4996 ;
toolset.flags $(toolset).compile CFLAGS $(condition)/<warnings>off : /wd4996 ;
# 64-bit compatibility warning
flags $(toolset).compile CFLAGS $(condition)/<warnings>all : /Wp64 ;
toolset.flags $(toolset).compile CFLAGS $(condition)/<warnings>all : /Wp64 ;
}
#
@@ -447,35 +446,35 @@ rule configure-version-specific ( toolset : version : condition )
if [ MATCH ^([67]) : $(version) ]
{
# 8.0 deprecates some of the options.
flags $(toolset).compile CFLAGS $(condition)/<optimization>speed $(condition)/<optimization>space : /Ogiy /Gs ;
flags $(toolset).compile CFLAGS $(condition)/<optimization>speed : /Ot ;
flags $(toolset).compile CFLAGS $(condition)/<optimization>space : /Os ;
toolset.flags $(toolset).compile CFLAGS $(condition)/<optimization>speed $(condition)/<optimization>space : /Ogiy /Gs ;
toolset.flags $(toolset).compile CFLAGS $(condition)/<optimization>speed : /Ot ;
toolset.flags $(toolset).compile CFLAGS $(condition)/<optimization>space : /Os ;
flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set> : /GB ;
flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>i386 : /G3 ;
flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>i486 : /G4 ;
flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>$(cpu-type-g5) : /G5 ;
flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>$(cpu-type-g6) : /G6 ;
flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>$(cpu-type-g7) : /G7 ;
toolset.flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set> : /GB ;
toolset.flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>i386 : /G3 ;
toolset.flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>i486 : /G4 ;
toolset.flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>$(cpu-type-g5) : /G5 ;
toolset.flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>$(cpu-type-g6) : /G6 ;
toolset.flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-i386)/<instruction-set>$(cpu-type-g7) : /G7 ;
# Improve floating-point accuracy. Otherwise, some of C++ Boost's "math"
# tests will fail.
flags $(toolset).compile CFLAGS $(condition) : /Op ;
toolset.flags $(toolset).compile CFLAGS $(condition) : /Op ;
# 7.1 and below have single-threaded static RTL.
flags $(toolset).compile CFLAGS $(condition)/<runtime-debugging>off/<runtime-link>static/<threading>single : /ML ;
flags $(toolset).compile CFLAGS $(condition)/<runtime-debugging>on/<runtime-link>static/<threading>single : /MLd ;
toolset.flags $(toolset).compile CFLAGS $(condition)/<runtime-debugging>off/<runtime-link>static/<threading>single : /ML ;
toolset.flags $(toolset).compile CFLAGS $(condition)/<runtime-debugging>on/<runtime-link>static/<threading>single : /MLd ;
}
else
{
# 8.0 and above adds some more options.
flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-amd64)/<instruction-set> : /favor:blend ;
flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-amd64)/<instruction-set>$(cpu-type-em64t) : /favor:EM64T ;
flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-amd64)/<instruction-set>$(cpu-type-amd64) : /favor:AMD64 ;
toolset.flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-amd64)/<instruction-set> : /favor:blend ;
toolset.flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-amd64)/<instruction-set>$(cpu-type-em64t) : /favor:EM64T ;
toolset.flags $(toolset).compile CFLAGS $(condition)/$(cpu-arch-amd64)/<instruction-set>$(cpu-type-amd64) : /favor:AMD64 ;
# 8.0 and above only has multi-threaded static RTL.
flags $(toolset).compile CFLAGS $(condition)/<runtime-debugging>off/<runtime-link>static/<threading>single : /MT ;
flags $(toolset).compile CFLAGS $(condition)/<runtime-debugging>on/<runtime-link>static/<threading>single : /MTd ;
toolset.flags $(toolset).compile CFLAGS $(condition)/<runtime-debugging>off/<runtime-link>static/<threading>single : /MT ;
toolset.flags $(toolset).compile CFLAGS $(condition)/<runtime-debugging>on/<runtime-link>static/<threading>single : /MTd ;
}
toolset.pop-checking-for-flags-module ;
}
@@ -485,7 +484,7 @@ rule configure-version-specific ( toolset : version : condition )
local rule default-path ( version )
{
# Use auto-detected path if possible
local path = [ get-values <command> :
local path = [ feature.get-values <command> :
[ $(.versions).get $(version) : options ] ] ;
if $(path)
@@ -565,7 +564,7 @@ generators.override msvc.compile.mc : mc.compile ;
# pch support
feature pch-source : : free dependency ;
feature.feature pch-source : : free dependency ;
class msvc-pch-generator : pch-generator
{
@@ -595,24 +594,18 @@ class msvc-pch-generator : pch-generator
errors.user-error "can't build pch without pch-header" ;
}
# If we don't have PCH source, it's fine, we'll
# create temporary .cpp file in the action.
# If we don't have PCH source - that's fine. We'll just create a
# temporary .cpp file in the action.
local generated =
[
# Passing of <pch-source> is a dirty trick,
# needed because non-composing generators
# with multiple inputs are subtly broken:
# https://zigzag.cs.msu.su:7813/boost.build/ticket/111
generator.run $(project) $(name)
: [
property-set.create
<pch-source>$(pch-source)
[ $(property-set).raw ]
]
: $(pch-header)
]
;
local generated = [ generator.run $(project) $(name)
: [ property-set.create
# Passing of <pch-source> is a dirty trick, needed because
# non-composing generators with multiple inputs are subtly
# broken. For more detailed information see:
# https://zigzag.cs.msu.su:7813/boost.build/ticket/111
<pch-source>$(pch-source)
[ $(property-set).raw ] ]
: $(pch-header) ] ;
local pch-file ;
for local g in $(generated)
@@ -623,14 +616,8 @@ class msvc-pch-generator : pch-generator
}
}
return
[
property-set.create
<pch-header>$(pch-header)
<pch-file>$(pch-file)
]
$(generated)
;
return [ property-set.create <pch-header>$(pch-header)
<pch-file>$(pch-file) ] $(generated) ;
}
}

View File

@@ -311,8 +311,7 @@ local rule print-help-usage ( )
print.section "Debug Levels"
Each debug level shows a different set of information. Usually with
higher levels producing more verbose information. The following levels
are supported:
;
are supported: ;
print.list-start ;
print.list-item 0;
Turn off all diagnostic output. Only errors are reported. ;

View File

@@ -7,17 +7,20 @@
import modules ;
import string ;
# Return the value(s) of the given environment variable(s) at the time
# bjam was invoked.
# Return the value(s) of the given environment variable(s) at the time bjam was
# invoked.
rule environ ( variable-names + )
{
return [ modules.peek .ENVIRON : $(variable-names) ] ;
}
.name = [ modules.peek : OS ] ;
.platform = [ modules.peek : OSPLAT ] ;
.version = [ modules.peek : OSVER ] ;
local rule constant ( c : os ? )
{
os ?= $(.name) ;
@@ -27,10 +30,10 @@ local rule constant ( c : os ? )
return $(result[1]) ;
}
rule get-constant ( os ? )
rule get-constant ( os ? )
{
# Find the name of the constant being accessed, which is
# equal to the name used to invoke us.
# Find the name of the constant being accessed, which is equal to the name
# used to invoke us.
local bt = [ BACKTRACE 1 ] ;
local rulename = [ MATCH ([^.]*)$ : $(bt[4]) ] ;
return [ constant $(rulename) : $(os) ] ;
@@ -46,8 +49,8 @@ for local constant in $(.constants)
EXPORT $(__name__) : $(.constants) ;
.executable-path-variable-NT = PATH ;
# On Windows the case and capitalization of PATH is not always
# predictable, so let's find out what variable name was really set.
# On Windows the case and capitalization of PATH is not always predictable, so
# let's find out what variable name was really set.
if $(.name) = NT
{
for local n in [ VARNAMES .ENVIRON ]
@@ -59,8 +62,8 @@ if $(.name) = NT
}
}
# Specific constants for various platforms. There's no need to define
# any constant whose value would be the same as the default, below.
# Specific constants for various platforms. There's no need to define any
# constant whose value would be the same as the default, below.
.shared-library-path-variable-NT = $(.executable-path-variable-NT) ;
.path-separator-NT = ";" ;
.expand-variable-prefix-NT = % ;

View File

@@ -6,7 +6,7 @@
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
# Performs various path manipulations. Path are always in a 'normilized'
# Performs various path manipulations. Paths are always in a 'normalized'
# representation. In it, a path may be either:
#
# - '.', or
@@ -17,10 +17,10 @@
# at the beginning, and it never ends in slash, except for path consisting
# of slash only.
import errors ;
import modules ;
import sequence ;
import regex ;
import errors : error ;
import sequence ;
import set ;
@@ -30,15 +30,11 @@ if [ modules.peek : UNIX ]
local uname = [ modules.peek : JAMUNAME ] ;
switch $(uname)
{
case CYGWIN* :
os = CYGWIN ;
case * :
os = UNIX ;
case CYGWIN* : os = CYGWIN ;
case * : os = UNIX ;
}
}
#
# Converts the native path into normalized form.
#
rule make ( native )
@@ -46,7 +42,7 @@ rule make ( native )
return [ make-$(os) $(native) ] ;
}
#
# Builds native representation of the path.
#
rule native ( path )
@@ -54,7 +50,7 @@ rule native ( path )
return [ native-$(os) $(path) ] ;
}
#
# Tests if a path is rooted.
#
rule is-rooted ( path )
@@ -62,19 +58,22 @@ rule is-rooted ( path )
return [ MATCH "^(/)" : $(path) ] ;
}
#
# Tests if a path has a parent.
#
rule has-parent ( path )
{
if $(path) != / {
if $(path) != /
{
return 1 ;
} else {
}
else
{
return ;
}
}
#
# Returns the path without any directory components.
#
rule basename ( path )
@@ -82,41 +81,52 @@ 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 $(path) = . {
if [ has-parent $(path) ]
{
if $(path) = .
{
return .. ;
} else {
}
else
{
# Strip everything at the end of path up to and including
# the last slash
local result = [ regex.match "((.*)/)?([^/]+)" : $(path) : 2 3 ] ;
# Did we strip what we shouldn't?
if $(result[2]) = ".." {
if $(result[2]) = ".."
{
return $(path)/.. ;
} else {
if ! $(result[1]) {
if [ is-rooted $(path) ] {
}
else
{
if ! $(result[1])
{
if [ is-rooted $(path) ]
{
result = / ;
} else {
}
else
{
result = . ;
}
}
return $(result[1]) ;
}
}
} else {
error "Path '$(path)' has no parent" ;
}
else
{
errors.error "Path '$(path)' has no parent" ;
}
}
#
# Returns path2 such that "[ join path path2 ] = .".
# The path may not contain ".." element or be rooted.
#
@@ -130,14 +140,15 @@ rule reverse ( path )
{
local tokens = [ regex.split $(path) "/" ] ;
local tokens2 ;
for local i in $(tokens) {
for local i in $(tokens)
{
tokens2 += .. ;
}
return [ sequence.join $(tokens2) : "/" ] ;
}
}
#
# Auxillary rule: does all the semantic of 'join', except for error cheching.
# The error checking is separated because this rule is recursive, and I don't
# like the idea of checking the same input over and over.
@@ -156,7 +167,7 @@ local rule join-imp ( elements + )
return $(result) ;
}
#
# Contanenates the passed path elements. Generates an error if
# any element other than the first one is rooted.
#
@@ -172,7 +183,7 @@ rule join ( elements + )
{
if [ is-rooted $(e) ]
{
error only first element may be rooted ;
errors.error only first element may be rooted ;
}
}
return [ join-imp $(elements) ] ;
@@ -180,7 +191,6 @@ rule join ( elements + )
}
#
# If 'path' is relative, it is rooted at 'root'. Otherwise, it's unchanged.
#
rule root ( path root )
@@ -192,7 +202,7 @@ rule root ( path root )
}
}
#
# Returns the current working directory.
#
rule pwd ( )
@@ -208,7 +218,7 @@ rule pwd ( )
}
}
#
# Returns the list of files matching the given pattern in the
# specified directory. Both directories and patterns are
# supplied as portable paths. Each pattern should be non-absolute
@@ -251,6 +261,7 @@ rule glob ( dirs * : patterns + : exclude-patterns * )
[ set.difference $(inc) : $(exc) ] ] ;
}
# Recursive version of GLOB. Builds the glob of files while
# also searching in the subdirectories of the given roots. An
# optional set of exclusion patterns will filter out the
@@ -267,6 +278,7 @@ rule glob-tree ( roots * : patterns + : exclude-patterns * )
] ] ;
}
local rule .glob-tree ( roots * : patterns * : exclude-patterns * )
{
local excluded ;
@@ -290,7 +302,6 @@ local rule .glob-tree ( roots * : patterns * : exclude-patterns * )
}
#
# Returns true is the specified file exists.
#
rule exists ( file )
@@ -300,8 +311,6 @@ rule exists ( file )
NATIVE_RULE path : exists ;
#
# 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.
@@ -323,7 +332,8 @@ rule all-parents ( path : upper_limit ? : cwd ? )
}
# All upper elements removed ?
if ! $(upper_ele) {
if ! $(upper_ele)
{
# Create the relative paths to parents, number of elements in 'path_ele'
local result ;
for local i in $(path_ele) {
@@ -332,13 +342,13 @@ rule all-parents ( path : upper_limit ? : cwd ? )
}
return $(result) ;
}
else {
error "$(upper_limit) is not prefix of $(path)" ;
else
{
errors.error "$(upper_limit) is not prefix of $(path)" ;
}
}
#
# Search for 'pattern' in parent directories of 'dir', up till and including
# 'upper_limit', if it is specified, or till the filesystem root otherwise.
#
@@ -355,7 +365,7 @@ rule glob-in-parents ( dir : patterns + : upper-limit ? )
return $(result) ;
}
#
# Assuming 'child' is a subdirectory of 'parent', return the relative
# path from 'parent' to 'child'
#
@@ -393,6 +403,7 @@ rule relative ( child parent )
}
}
# Returns the minimal path to path2 that is relative path1.
#
rule relative-to ( path1 path2 )
@@ -417,6 +428,7 @@ rule relative-to ( path1 path2 )
return [ join . $(root_1) $(split2) ] ;
}
# Returns the list of paths which are used by the operating system
# for looking up programs
rule programs-path ( )
@@ -433,6 +445,7 @@ rule programs-path ( )
return $(result) ;
}
rule make-NT ( native )
{
local tokens = [ regex.split $(native) "[/\\]" ] ;
@@ -459,6 +472,7 @@ rule make-NT ( native )
return $(result) ;
}
rule native-NT ( path )
{
local result = [ MATCH "^/?(.*)" : $(path) ] ;
@@ -466,6 +480,7 @@ rule native-NT ( path )
return $(result) ;
}
rule make-UNIX ( native )
{
# VP: I have no idea now 'native' can be empty here! But it can!
@@ -479,16 +494,19 @@ rule make-UNIX ( native )
}
}
rule native-UNIX ( path )
{
return $(path) ;
}
rule make-CYGWIN ( path )
{
return [ make-NT $(path) ] ;
}
rule native-CYGWIN ( path )
{
local result = $(path) ;
@@ -499,7 +517,7 @@ rule native-CYGWIN ( path )
return [ native-UNIX $(result) ] ;
}
#
# split-VMS: splits input native path into
# device dir file (each part is optional),
# example:
@@ -516,7 +534,7 @@ rule split-path-VMS ( native )
return $(device) $(dir) $(file) ;
}
#
# Converts a native VMS path into a portable path spec.
#
# Does not handle current-device absolute paths such
@@ -592,7 +610,7 @@ rule make-VMS ( native )
return $(portable) ;
}
#
# Converts a portable path spec into a native VMS path.
#
# Relies on having at least one dot (".") included in the file
@@ -663,8 +681,8 @@ rule native-VMS ( path )
}
rule __test__ ( ) {
rule __test__ ( )
{
import assert ;
import errors : try catch ;
@@ -694,7 +712,6 @@ rule __test__ ( ) {
assert.result ".." : parent "../foo" ;
assert.result "../../foo" : parent "../../foo/bar" ;
assert.result "." : reverse "." ;
assert.result ".." : reverse "foo" ;
assert.result "../../.." : reverse "foo/bar/giz" ;
@@ -820,5 +837,4 @@ rule __test__ ( ) {
assert.result "disk:[my_docs.work]Jamfile." : native "/disk:/my_docs/work/Jamfile." ;
modules.poke path : os : $(save-os) ;
}