📄 project.jam
字号:
}
}
}
# Now do some checks
if $(.current-project) != $(saved-project)
{
errors.error "The value of the .current-project variable"
: "has magically changed after loading a Jamfile."
: "This means some of the targets might be defined a the wrong project."
;
}
if $(.global-build-dir)
{
local id = [ attribute $(jamfile-module) id ] ;
local project-root = [ attribute $(jamfile-module) project-root ] ;
local location = [ attribute $(jamfile-module) location ] ;
if $(location) && $(project-root) = $(dir)
{
# This is Jamroot
if ! $(id)
{
ECHO "warning: the --build-dir option was specified" ;
ECHO "warning: but Jamroot at '$(dir)'" ;
ECHO "warning: specified no project id" ;
ECHO "warning: the --build-dir option will be ignored" ;
}
}
}
}
rule mark-as-user ( module-name )
{
if USER_MODULE in [ RULENAMES ]
{
USER_MODULE $(module-name) ;
}
}
rule load-aux ( module-name : file )
{
mark-as-user $(module-name) ;
module $(module-name)
{
include $(2) ;
local rules = [ RULENAMES $(1) ] ;
IMPORT $(1) : $(rules) : $(1) : $(1).$(rules) ;
}
}
.global-build-dir = [ MATCH --build-dir=(.*) : [ modules.peek : ARGV ] ] ;
if $(.global-build-dir)
{
# If the option is specified several times, take the last value.
.global-build-dir = [ path.make $(.global-build-dir[-1]) ] ;
}
# Initialize the module for a project.
#
rule initialize (
module-name # The name of the project module.
: location ? # The location (directory) of the project to initialize.
# If not specified, stanalone project will be initialized.
: basename ?
)
{
if --debug-loading in [ modules.peek : ARGV ]
{
ECHO "Initializing project '$(module-name)'" ;
}
# TODO: need to consider if standalone projects can do anything but defining
# prebuilt targets. If so, we need to give more sensible "location", so that
# source paths are correct.
location ?= "" ;
# Create the module for the Jamfile first.
module $(module-name)
{
}
$(module-name).attributes = [ new project-attributes $(location)
$(module-name) ] ;
local attributes = $($(module-name).attributes) ;
if $(location)
{
$(attributes).set source-location : [ path.make $(location) ] : exact ;
}
else
{
$(attributes).set source-location : "" : exact ;
}
$(attributes).set requirements : [ property-set.empty ] : exact ;
$(attributes).set usage-requirements : [ property-set.empty ] : exact ;
# Import rules common to all project modules from project-rules module,
# defined at the end of this file.
modules.clone-rules project-rules $(module-name) ;
local jamroot ;
local parent-module ;
if $(module-name) = site-config
{
# No parent.
}
else if $(module-name) = user-config
{
parent-module = site-config ;
}
else
{
# We search for parent/project-root only if jamfile was specified
# --- i.e
# if the project is not standalone.
if $(location) && ! $(basename) in
project-root.jam Jamroot jamroot Jamroot.jam Jamroot
{
parent-module = [ load-parent $(location) ] ;
}
else
{
# It's either jamroot, or standalone project.
# If it's jamroot, inherit from user-config.
if $(location)
{
parent-module = user-config ;
jamroot = true ;
}
}
}
if $(parent-module)
{
inherit-attributes $(module-name) : $(parent-module) ;
}
if $(jamroot)
{
$(attributes).set project-root : $(location) : exact ;
}
local parent ;
if $(parent-module)
{
parent = [ target $(parent-module) ] ;
}
if ! $(.target.$(module-name))
{
.target.$(module-name) = [ new project-target $(module-name)
: $(module-name) $(parent)
: [ attribute $(module-name) requirements ] ] ;
if --debug-loading in [ modules.peek : ARGV ]
{
ECHO "Assigned project target" $(.target.$(module-name))
"to '$(module-name)'" ;
}
}
.current-project = [ target $(module-name) ] ;
}
# Make 'project-module' inherit attributes of project root and parent module.
rule inherit-attributes ( project-module : parent-module )
{
local attributes = $($(project-module).attributes) ;
local pattributes = [ attributes $(parent-module) ] ;
# Parent module might be locationless user-config.
if [ modules.binding $(parent-module) ]
{
$(attributes).set parent : [ path.parent
[ path.make [ modules.binding $(parent-module) ] ] ] ;
}
local v = [ $(pattributes).get project-root ] ;
$(attributes).set project-root : $(v) : exact ;
$(attributes).set default-build
: [ $(pattributes).get default-build ] ;
$(attributes).set requirements
: [ $(pattributes).get requirements ] : exact ;
$(attributes).set usage-requirements
: [ $(pattributes).get usage-requirements ] : exact ;
local parent-build-dir = [ $(pattributes).get build-dir ] ;
if $(parent-build-dir)
{
# Have to compute relative path from parent dir to our dir
# Convert both paths to absolute, since we cannot
# find relative path from ".." to "."
local location = [ attribute $(project-module) location ] ;
local parent-location = [ attribute $(parent-module) location ] ;
local pwd = [ path.pwd ] ;
local parent-dir = [ path.root $(parent-location) $(pwd) ] ;
local our-dir = [ path.root $(location) $(pwd) ] ;
$(attributes).set build-dir : [ path.join $(parent-build-dir)
[ path.relative $(our-dir) $(parent-dir) ] ] : exact ;
}
}
# Associate the given id with the given project module
rule register-id ( id : module )
{
$(id).jamfile-module = $(module) ;
}
# Class keeping all the attributes of a project.
#
# The standard attributes are "id", "location", "project-root", "parent"
# "requirements", "default-build", "source-location" and "projects-to-build".
class project-attributes
{
import property ;
import property-set ;
import errors ;
import path ;
import print ;
import sequence ;
import project ;
rule __init__ ( location project-module )
{
self.location = $(location) ;
self.project-module = $(project-module) ;
}
# Set the named attribute from the specification given by the user.
# The value actually set may be different.
rule set ( attribute : specification *
: exact ? # Sets value from 'specification' without any processing
)
{
if $(exact)
{
self.$(attribute) = $(specification) ;
}
else if $(attribute) = "requirements"
{
local result = [ property-set.create-from-user-input
$(specification) : $(self.project-module) $(self.location) ] ;
# If we have inherited properties, need to refine them with the
# specified.
local current = $(self.requirements) ;
if $(current)
{
result = [ $(current).refine $(result) ] ;
}
if $(result[1]) = "@error"
{
errors.error
"Requirements for project at '$(self.location)'"
"conflict with parent's." :
"Explanation: " $(result[2-]) ;
}
else
{
self.requirements = $(result) ;
}
}
else if $(attribute) = "usage-requirements"
{
local unconditional ;
for local p in $(specification)
{
local split = [ property.split-conditional $(p) ] ;
split ?= nothing $(p) ;
unconditional += $(split[2]) ;
}
local non-free = [ property.remove free : $(unconditional) ] ;
if $(non-free)
{
errors.error "usage-requirements" $(specification) "have non-free properties" $(non-free) ;
}
local t = [ property.translate-paths $(specification)
: $(self.location) ] ;
if $(self.usage-requirements)
{
self.usage-requirements = [ property-set.create
[ $(self.usage-requirements).raw ] $(t) ] ;
}
else
{
self.usage-requirements = [ property-set.create $(t) ] ;
}
}
else if $(attribute) = "default-build"
{
self.default-build = [ property.make $(specification) ] ;
}
else if $(attribute) = "source-location"
{
self.source-location = ;
for local src-path in $(specification)
{
self.source-location += [ path.root
[ path.make $(src-path) ] $(self.location) ] ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -