📄 project.jam
字号:
else if $(attribute) = "build-dir"
{
self.build-dir = [ path.root $(specification) $(self.location) ] ;
}
else if ! $(attribute) in "id" "default-build" "location" "source-location"
"parent" "projects-to-build" "project-root"
{
errors.error "Invalid project attribute '$(attribute)' specified "
"for project at '$(self.location)'" ;
}
else
{
self.$(attribute) = $(specification) ;
}
}
# Returns the value of the given attribute.
rule get ( attribute )
{
return $(self.$(attribute)) ;
}
# Prints the project attributes.
rule print ( )
{
local id = $(self.id) ; id ?= (none) ;
local parent = $(self.parent) ; parent ?= (none) ;
print.section "'"$(id)"'" ;
print.list-start ;
print.list-item "Parent project:" $(parent) ;
print.list-item "Requirements:" [ $(self.requirements).raw ] ;
print.list-item "Default build:" $(self.default-build) ;
print.list-item "Source location:" $(self.source-location) ;
print.list-item "Projects to build:"
[ sequence.insertion-sort $(self.projects-to-build) ] ;
print.list-end ;
}
}
# Returns the project which is currently being loaded
rule current ( )
{
return $(.current-project) ;
}
# Returns the project-attribute instance for the specified jamfile module.
rule attributes ( project )
{
return $($(project).attributes) ;
}
# Returns the value of the specified attribute in the specified jamfile module.
rule attribute ( project attribute )
{
return [ $($(project).attributes).get $(attribute) ] ;
}
# Returns the project target corresponding to the 'project-module'.
rule target ( project-module )
{
if ! $(.target.$(project-module))
{
.target.$(project-module) = [ new project-target $(project-module)
: $(project-module)
: [ attribute $(project-module) requirements ] ] ;
}
return $(.target.$(project-module)) ;
}
# Use/load a project.
rule use ( id : location )
{
local saved-project = $(.current-project) ;
local project-module = [ project.load $(location) ] ;
local declared-id = [ project.attribute $(project-module) id ] ;
if ! $(declared-id) || $(declared-id) != $(id)
{
# The project at 'location' either have no id or
# that id is not equal to the 'id' parameter.
if $($(id).jamfile-module)
&& $($(id).jamfile-module) != $(project-module)
{
errors.user-error
"Attempt to redeclare already existing project id" ;
}
$(id).jamfile-module = $(project-module) ;
}
.current-project = $(saved-project) ;
}
# Initializes an additional toolset-like module.
# First load 'toolset-module' and then calls its 'init'
# rule with trailing arguments
rule _using ( toolset-module : * )
{
import $(toolset-module) ;
if ! $(.$(toolset-module)-init-callled)
{
$(toolset-module)-init-callled = true ;
$(toolset-module).init $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
}
}
# This module defines rules common to all projects
module project-rules
{
rule using ( toolset-module : * )
{
import toolset ;
import modules ;
import project ;
# The module referred by 'using' can be placed in
# the same directory as Jamfile, and the user
# will expect the module to be found even though
# the directory is not in BOOST_BUILD_PATH.
# So temporary change the search path.
local x = [ modules.peek : BOOST_BUILD_PATH ] ;
local caller = [ modules.binding $(__name__) ] ;
modules.poke : BOOST_BUILD_PATH : $(caller:D) $(x) ;
project._using $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
modules.poke : BOOST_BUILD_PATH : $(x) ;
# The above might have clobbered .current-project
# Restore the the right value.
modules.poke project : .current-project
: [ project.target $(__name__) ] ;
}
import modules ;
rule import ( * : * : * )
{
modules.import project ;
local caller = [ CALLER_MODULE ] ;
module $(caller)
{
modules.import $(1) : $(2) : $(3) ;
}
modules.poke project : .current-project
: [ project.target $(__name__) ] ;
}
rule project ( id ? : options * : * )
{
import project ;
import path ;
import errors ;
local attributes = [ project.attributes $(__name__) ] ;
if $(id)
{
id = [ path.root $(id) / ] ;
project.register-id $(id) : $(__name__) ;
$(attributes).set id : $(id) ;
}
local explicit-build-dir ;
for n in 2 3 4 5 6 7 8 9
{
local option = $($(n)) ;
if $(option)
{
$(attributes).set $(option[1]) : $(option[2-]) ;
}
if $(option[1]) = "build-dir"
{
explicit-build-dir = [ path.make $(option[2-]) ] ;
}
}
# If '--build-dir' is specified, change the build dir for the project.
local global-build-dir =
[ modules.peek project : .global-build-dir ] ;
if $(global-build-dir)
{
if [ $(attributes).get location ] = [ $(attributes).get project-root ]
{
# This is Jamroot.
if $(id)
{
if $(explicit-build-dir)
&& [ path.is-rooted $(explicit-build-dir) ]
{
errors.user-error "Absolute directory specified via 'build-dir' project attribute"
: "Don't know how to combine that with the --build-dir option."
;
}
# Strip the leading slash from id.
local rid = [ MATCH /(.*) : $(id) ] ;
local p = [ path.join
$(global-build-dir) $(rid) $(explicit-build-dir) ] ;
$(attributes).set build-dir : $(p) : exact ;
}
}
else
{
# Not Jamroot
if $(explicit-build-dir)
{
errors.user-error "When --build-dir is specified, the 'build-project'"
: "attribute is allowed only for top-level 'project' invocations" ;
}
}
}
}
# Declare and set a project global constant. Project global constants are
# normal variables but should not be changed. They are applied to every
# child Jamfile.
#
rule constant (
name # Variable name of the constant.
: value + # Value of the constant.
)
{
import project ;
local p = [ project.target $(__name__) ] ;
$(p).add-constant $(name) : $(value) ;
}
# Declare and set a project global constant, whose value is a path. The
# path is adjusted to be relative to the invocation directory. The given
# value path is taken to be either absolute, or relative to this project
# root.
rule path-constant (
name # Variable name of the constant.
: value + # Value of the constant.
)
{
import project ;
local p = [ project.target $(__name__) ] ;
$(p).add-constant $(name) : $(value) : path ;
}
rule use-project ( id : where )
{
# See comment in 'load' for explanation.
.used-projects += $(id) $(where) ;
}
rule build-project ( dir )
{
import project ;
local attributes = [ project.attributes $(__name__) ] ;
local now = [ $(attributes).get projects-to-build ] ;
$(attributes).set projects-to-build : $(now) $(dir) ;
}
rule explicit ( target-names * )
{
import project ;
local t = [ project.target $(__name__) ] ;
for local n in $(target-names)
{
$(t).mark-target-as-explicit $(n) ;
}
}
rule glob ( wildcards + )
{
import path ;
import project ;
import sequence ;
local location = [ project.attribute $(__name__) source-location ] ;
local result ;
local paths = [ path.glob $(location) :
[ sequence.transform path.make : $(wildcards) ] ] ;
if $(wildcards:D)
{
# The paths we've found are relative to current directory,
# but the names specified in sources list are assumed to
# be relative to source directory of the corresponding
# prject. So, just make the name absolute.
for local p in $(paths)
{
result += [ path.root $(p) [ path.pwd ] ] ;
}
}
else
{
# There were not directory in wildcard, so the files are all
# in the source directory of the project. Just drop the
# directory, instead of making paths absolute.
result = $(paths:D="") ;
}
return $(result) ;
}
}
local rule __test__ ( )
{
import assert ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -