mirror of
https://github.com/boostorg/build.git
synced 2026-02-15 13:02:11 +00:00
Integrated my load behaviour into Valdimir's code. Some cleanup along the way.
[SVN r13503]
This commit is contained in:
@@ -3,40 +3,36 @@
|
||||
# all copies. This software is provided "as is" without express or implied
|
||||
# warranty, and with no claim as to its suitability for any purpose.
|
||||
|
||||
# Bootstrap the doc system. doing this first makes it possible to document
|
||||
# in all the modules. And import the basic doc rules, to make them easily
|
||||
# available.
|
||||
#
|
||||
SEARCH on <module@>doc.jam = $(BOOST_BUILD_PATH) ;
|
||||
module doc { include <module@>doc.jam ; }
|
||||
IMPORT doc
|
||||
: document-module document-rule document-variable :
|
||||
: document-module document-rule document-variable ;
|
||||
|
||||
# Bootstrap the module system. And bring the import rule into the global module.
|
||||
#
|
||||
SEARCH on <module@>modules.jam = $(BOOST_BUILD_PATH) ;
|
||||
module modules { include <module@>modules.jam ; }
|
||||
IMPORT modules : import : : import ;
|
||||
|
||||
# Re-load the doc system, to clean up things. Both doc and modules
|
||||
# can handle getting included twice.
|
||||
#
|
||||
import doc ;
|
||||
|
||||
# Reload the modules, to clean up things. The modules module can tolerate
|
||||
# being included twice.
|
||||
#
|
||||
import modules ;
|
||||
|
||||
import doc ;
|
||||
import project ;
|
||||
|
||||
# Check to see if the user is asking for help as soon as possible.
|
||||
# This is first action, so that we can interrupt the regular build
|
||||
# process if they are asking for help.
|
||||
#
|
||||
doc.do-help ;
|
||||
|
||||
import build-system ;
|
||||
|
||||
# Load the first Jamfile, and build it.
|
||||
#
|
||||
build-system.construct [ build-system.load-jamfile [ PWD ] ] ;
|
||||
if [ doc.help ]
|
||||
{
|
||||
# Do nothing, the doc system will generate the appropriate
|
||||
# targets that prints out the documentation.
|
||||
# To do this we need to fake the build system loading so the
|
||||
# Jambase doesn't error.
|
||||
module build-system { rule __placeholder__ ( ) { } }
|
||||
}
|
||||
else
|
||||
{
|
||||
# No help requested, go ahead and load and build the users
|
||||
# project.
|
||||
import build-system ;
|
||||
project.load [ PWD ] ;
|
||||
}
|
||||
|
||||
@@ -4,123 +4,9 @@
|
||||
# warranty, and with no claim as to its suitability for any purpose.
|
||||
|
||||
import modules ;
|
||||
import os.path ;
|
||||
|
||||
# this rule will be used to generate build instructions for the
|
||||
# given module (Jamfile) once its declarations have been read.
|
||||
rule construct ( module-name )
|
||||
{
|
||||
}
|
||||
|
||||
# Default patterns to search for the Jamfiles to use for build
|
||||
# declarations.
|
||||
#
|
||||
JAMFILE = [ modules.peek : JAMFILE ] ;
|
||||
JAMFILE ?= [Jj]amfile [Jj]amfile.jam ;
|
||||
|
||||
# Load a Jamfile at the given directory. Will attempt to load
|
||||
# the file as indicated by the JAMFILE patterns. Also the project-root.jam
|
||||
# corresponding to the Jamfile is also loaded. We return the
|
||||
# name of the Jamfile we loaded, which is the module for the Jamfile.
|
||||
#
|
||||
rule load-jamfile ( dir )
|
||||
{
|
||||
# See if the Jamfile is where it should be.
|
||||
#
|
||||
local jamfile-to-load = [ GLOB $(dir) : $(JAMFILE) ] ;
|
||||
|
||||
# Could not find it, error.
|
||||
#
|
||||
if ! $(jamfile-to-load)
|
||||
{
|
||||
EXIT
|
||||
"Unable to load Jamfile. Could not find a Jamfile in"
|
||||
"this directory:" $(dir)"." "Attempted to find it with"
|
||||
"this pattern:" $(JAMFILE)"."
|
||||
"Please consult the documentation at 'http://www.boost.org'." ;
|
||||
}
|
||||
|
||||
# Multiple Jamfiles found in the same place. Warn about this.
|
||||
# And ensure we use only one of them.
|
||||
#
|
||||
if $(jamfile-to-load[2-])
|
||||
{
|
||||
ECHO
|
||||
"WARNING: Found multiple Jamfiles at this '"$(dir)"' location!"
|
||||
"Loading the first one: '"$(jamfile-to-load[1]:D=)"'." ;
|
||||
}
|
||||
jamfile-to-load = $(jamfile-to-load[1]) ;
|
||||
if ! [ os.path.is_rooted $(jamfile-to-load) ]
|
||||
{
|
||||
local root-path =
|
||||
[ os.path.parent [ os.path.make [ modules.binding [ CALLER_MODULE ] ] ] ] ;
|
||||
jamfile-to-load =
|
||||
[ os.path.native [ os.path.root_relative_path $(jamfile-to-load) $(root-path) ] ] ;
|
||||
}
|
||||
|
||||
# Load the project-root, and find out what the project root is
|
||||
# for this Jamfile so we can correctly scope it.
|
||||
#
|
||||
local project-root-module = [ load-project-root $(jamfile-to-load:D) ] ;
|
||||
|
||||
# Setup variable and rule for access to project-root location in
|
||||
# Jamfile.
|
||||
#
|
||||
modules.poke $(jamfile-module)
|
||||
: project-root-module : $(project-root-module) ;
|
||||
IMPORT build-system : project-root
|
||||
: $(jamfile-module) : project-root : LOCALIZE ;
|
||||
|
||||
# Now load the Jamfile in the project-root module context.
|
||||
#
|
||||
local jamfile-module = Jamfile<$(jamfile-to-load:D)> ;
|
||||
modules.load $(jamfile-module)
|
||||
: $(jamfile-to-load:D=) : $(jamfile-to-load:D) ;
|
||||
|
||||
# Return the Jamfile's filename/module.
|
||||
#
|
||||
return $(jamfile-module) ;
|
||||
}
|
||||
|
||||
# Load the project-root file for the given directory. The directory can
|
||||
# be either the project-root itself, or any subdirectory. Fails if it can't
|
||||
# find the project-root. We return the project-root location.
|
||||
#
|
||||
rule load-project-root ( dir )
|
||||
{
|
||||
# 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)
|
||||
{
|
||||
EXIT
|
||||
"Failed to find the project root for:" $(dir)"." "Did not"
|
||||
"find a project-root.jam file there or in any of its parent"
|
||||
"directories."
|
||||
"Please consult the documentation at 'http://www.boost.org'." ;
|
||||
}
|
||||
|
||||
# Load it within a module specifically for the project root.
|
||||
# The module system handles checking for multiple includes.
|
||||
#
|
||||
local project-root-module = project-root<$(project-root-to-load:D)> ;
|
||||
modules.load $(project-root-module)
|
||||
: $(project-root-to-load:D=) : $(project-root-to-load:D) ;
|
||||
|
||||
# Return the module for the project.
|
||||
#
|
||||
return $(project-root-module) ;
|
||||
}
|
||||
|
||||
# Returns the project-root for the calling context. This hides the
|
||||
# internals of maintenance of project-root values. This is imported
|
||||
# into all project-root modules to ease use.
|
||||
#
|
||||
rule project-root ( )
|
||||
{
|
||||
local project-root-binding = [ modules.binding $(project-root-module) ] ;
|
||||
return $(project-root-binding:D) ;
|
||||
}
|
||||
|
||||
315
new/project.jam
315
new/project.jam
@@ -1,4 +1,5 @@
|
||||
# Copyright (C) Vladimir Prus 2002. Permission to copy, use, modify, sell and
|
||||
# Copyright (C) Vladimir Prus and Rene Rivera 2002.
|
||||
# Permission to copy, use, modify, sell and
|
||||
# distribute this software is granted provided this copyright notice appears in
|
||||
# all copies. This software is provided "as is" without express or implied
|
||||
# warranty, and with no claim as to its suitability for any purpose.
|
||||
@@ -56,6 +57,7 @@ import os.path ;
|
||||
import sequence ;
|
||||
import targets ;
|
||||
import errors : error ;
|
||||
import project-root ;
|
||||
|
||||
|
||||
jamfile-rules = project.project ;
|
||||
@@ -63,68 +65,19 @@ jamfile-rules = project.project ;
|
||||
|
||||
rule load ( jamfile-location )
|
||||
{
|
||||
local module-name = Jamfile@$(jamfile-location) ;
|
||||
local loaded = ;
|
||||
local module-name = [ load-jamfile $(jamfile-location) loaded ] ;
|
||||
|
||||
if ! $(jamfile-location) in $(projects) {
|
||||
|
||||
projects += $(jamfile-location) ;
|
||||
|
||||
# ECHO "project.load $(jamfile-location)" ;
|
||||
|
||||
local project-root = [ locate-project-root $(jamfile-location) ] ;
|
||||
|
||||
# ECHO "project root found in $(project-root)" ;
|
||||
|
||||
modules.load project-root@$(project-root) : project-root.jam : $(project-root) ;
|
||||
|
||||
|
||||
local parent = [ locate-parent $(jamfile-location) : $(project-root) ] ;
|
||||
|
||||
# ECHO "parent found in $(parent)" ;
|
||||
|
||||
if $(parent) != $(jamfile-location) {
|
||||
load $(parent) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
module $(module-name) {
|
||||
import project : project ;
|
||||
}
|
||||
|
||||
# Import rules common to all project modules from project-rules module,
|
||||
# define at the end of this file.
|
||||
# (Should be use classes instead?)
|
||||
|
||||
IMPORT project-rules : [ RULENAMES project-rules ]
|
||||
: $(module-name) : [ RULENAMES project-rules ] : localize ;
|
||||
EXPORT $(module-name) : [ RULENAMES project-rules ] ;
|
||||
for local r in [ RULENAMES $(module-name) ] {
|
||||
IMPORT $(module-name) : $(r) : : $(module-name).$(r) ;
|
||||
}
|
||||
|
||||
modules.poke $(module-name) : __jamfile-location__ : $(jamfile-location) ;
|
||||
modules.poke $(module-name) : __source-location__ : $(jamfile-location) ;
|
||||
modules.poke $(module-name) : __project-root__ : $(project-root) ;
|
||||
modules.poke $(module-name) : __parent__ : $(parent) ;
|
||||
if $(parent) != $(jamfile-location) {
|
||||
modules.poke $(module-name) : __default-build__ : [ Jamfile@$(parent).default-build ] ;
|
||||
modules.poke $(module-name) : __requirements__ : [ Jamfile@$(parent).requirements ] ;
|
||||
} else {
|
||||
modules.poke $(module-name) : __default-build__ : debug ;
|
||||
}
|
||||
|
||||
modules.load $(module-name) : Jamfile : $(jamfile-location) ;
|
||||
|
||||
for local subinclude in [ $(module-name).subincludes ] {
|
||||
if $(loaded)
|
||||
{
|
||||
for local subinclude in [ $(module-name).subincludes ]
|
||||
{
|
||||
load [ os.path.join $(jamfile-location) $(subinclude) ] ;
|
||||
}
|
||||
}
|
||||
return $(module-name) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
rule lookup ( id )
|
||||
{
|
||||
local split = [ MATCH (.*)@(.*) : $(id) ] ;
|
||||
@@ -196,62 +149,6 @@ rule assign-option ( module : option + )
|
||||
|
||||
dummy_module_number = 0 ;
|
||||
|
||||
# Does an upward directory crawl to find a file.
|
||||
# As a side effect, loads that file as a module with auto-generated name.
|
||||
# The side effect should be eliminated once glob builtin is available.
|
||||
rule upward-crawl ( directory : file : upper_limit ? )
|
||||
{
|
||||
local parents = [ os.path.all_parents
|
||||
[ os.path.join $(directory) file ] : $(upper_limit) ] ;
|
||||
|
||||
# ECHO "Parents are:" ;
|
||||
# ECHO $(parents) ;
|
||||
|
||||
local found ;
|
||||
while $(parents) && ! $(found) {
|
||||
found = [ GLOB [ os.path.native $(parents[1]) ] : $(file) ] ;
|
||||
# ECHO "Search in $(parents[1]) gives $(found)" ;
|
||||
parents = $(parents[2-]) ;
|
||||
}
|
||||
if ! $(found) {
|
||||
error "Unable to locate file $(file), starting from $(directory)" ;
|
||||
} else {
|
||||
return [ os.path.make $(found) ] ;
|
||||
}
|
||||
}
|
||||
|
||||
# Locates a file called project-root.jam in parent dirs and returns
|
||||
# the directory where it is found
|
||||
rule locate-project-root ( jamfile-location )
|
||||
{
|
||||
local result = [ upward-crawl $(jamfile-location) : project-root.jam ] ;
|
||||
|
||||
if ! $(result) {
|
||||
EXIT "Unable to locate project root for Jamfile in $(jamfile-location)" ;
|
||||
} else {
|
||||
return [ os.path.parent [ os.path.make $(result) ] ] ;
|
||||
}
|
||||
}
|
||||
|
||||
# Locates a file called Jamfile in parent dirs, stopping search at
|
||||
# 'upper_limit'
|
||||
rule locate-parent ( jamfile-location : upper_limit )
|
||||
{
|
||||
if $(jamfile-location) = $(upper_limit) {
|
||||
return $(jamfile-location) ;
|
||||
} else {
|
||||
local result = [ upward-crawl
|
||||
[ os.path.parent $(jamfile-location) ]
|
||||
: Jamfile : $(upper_limit) ] ;
|
||||
|
||||
if ! $(result) {
|
||||
EXIT "Unable to locate parent Jamfile for $(jamfile-location)" ;
|
||||
} else {
|
||||
return [ os.path.parent [ os.path.make $(result) ] ] ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Returns the name of module corresponding to 'jamfile-location'.
|
||||
#
|
||||
@@ -299,6 +196,179 @@ rule dump ( )
|
||||
}
|
||||
}
|
||||
|
||||
# Default patterns to search for the Jamfiles to use for build
|
||||
# declarations.
|
||||
#
|
||||
JAMFILE = [ modules.peek : JAMFILE ] ;
|
||||
JAMFILE ?= [Jj]amfile [Jj]amfile.jam ;
|
||||
|
||||
# Find the Jamfile at the given location. This returns the exact names of
|
||||
# all the Jamfiles in the given directory. The optional parent-root argument
|
||||
# causes this to search not the given directory but the ones above it up
|
||||
# to the directory given in it.
|
||||
#
|
||||
local rule find-jamfile (
|
||||
dir # The directory(s) to look for a Jamfile.
|
||||
parent-root ? # Optional flag indicating to search for the parent Jamfile.
|
||||
)
|
||||
{
|
||||
# Glob for all the possible Jamfiles according to the match pattern.
|
||||
#
|
||||
local jamfile-glob = ;
|
||||
if $(parent-root)
|
||||
{
|
||||
jamfile-glob = [ find-to-root $(dir:P) : $(JAMFILE) ] ;
|
||||
}
|
||||
else
|
||||
{
|
||||
jamfile-glob = [ GLOB $(dir) : $(JAMFILE) ] ;
|
||||
}
|
||||
|
||||
# Normalize the paths of each file found.
|
||||
#
|
||||
local jamfile-found = ;
|
||||
for local jamfile in $(jamfile-glob)
|
||||
{
|
||||
local normalized = $(jamfile) ;
|
||||
if ! [ os.path.is_rooted $(jamfile) ]
|
||||
{
|
||||
local root-path =
|
||||
[ os.path.parent [ os.path.make [ modules.binding [ CALLER_MODULE ] ] ] ] ;
|
||||
normalized =
|
||||
[ os.path.native [ os.path.root_relative_path $(jamfile) $(root-path) ] ] ;
|
||||
}
|
||||
|
||||
# Filter out if the found file is above the target parent root.
|
||||
if $(parent-root)
|
||||
{
|
||||
if ! [ MATCH "$(parent-root)\\$(SLASH)(.*)" : $(normalized) ]
|
||||
{
|
||||
normalized = ;
|
||||
}
|
||||
}
|
||||
|
||||
jamfile-found += $(normalized) ;
|
||||
}
|
||||
|
||||
return $(jamfile-found) ;
|
||||
}
|
||||
|
||||
# Load a Jamfile at the given directory. Will attempt to load
|
||||
# the file as indicated by the JAMFILE patterns. We return the
|
||||
# module for the Jamfile.
|
||||
#
|
||||
local rule load-jamfile (
|
||||
dir # The directory of the project Jamfile.
|
||||
loaded-var ? # Name of variable to indicated we loaded the Jamfile.
|
||||
)
|
||||
{
|
||||
# See if the Jamfile is where it should be.
|
||||
#
|
||||
local jamfile-to-load = [ find-jamfile $(dir) ] ;
|
||||
|
||||
# Could not find it, error.
|
||||
#
|
||||
if ! $(jamfile-to-load)
|
||||
{
|
||||
EXIT
|
||||
"Unable to load Jamfile. Could not find a Jamfile in"
|
||||
"this directory:" $(dir)"." "Attempted to find it with"
|
||||
"this pattern:" $(JAMFILE)"."
|
||||
"Please consult the documentation at 'http://www.boost.org'." ;
|
||||
}
|
||||
|
||||
# The module of the jamfile.
|
||||
#
|
||||
local jamfile-module = Jamfile<$(jamfile-to-load[1]:D)> ;
|
||||
|
||||
# Don't even bother with the rest if we know the file is already loaded.
|
||||
#
|
||||
if ! [ modules.binding $(jamfile-module) ]
|
||||
{
|
||||
# Multiple Jamfiles found in the same place. Warn about this.
|
||||
# And ensure we use only one of them.
|
||||
#
|
||||
if $(jamfile-to-load[2-])
|
||||
{
|
||||
ECHO
|
||||
"WARNING: Found multiple Jamfiles at this '"$(dir)"' location!"
|
||||
"Loading the first one: '"$(jamfile-to-load[1]:D=)"'." ;
|
||||
}
|
||||
jamfile-to-load = $(jamfile-to-load[1]) ;
|
||||
|
||||
# Initialize the jamfile module before loading.
|
||||
#
|
||||
initialize $(jamfile-module) : $(jamfile-to-load) ;
|
||||
|
||||
# Setup, by coordinating with project-root.
|
||||
#
|
||||
local project-root-module = [ $(jamfile-module).project-root-module ] ;
|
||||
$(project-root-module).register-project $(jamfile-module) ;
|
||||
|
||||
# Now load the Jamfile in it's own context.
|
||||
#
|
||||
modules.load $(jamfile-module)
|
||||
: $(jamfile-to-load:D=) : $(jamfile-to-load:D) ;
|
||||
|
||||
# Indicate we loaded the Jamfile.
|
||||
#
|
||||
if $(loaded-var)
|
||||
{
|
||||
$(loaded-var) = true ;
|
||||
}
|
||||
}
|
||||
|
||||
# Return the Jamfile's filename/module.
|
||||
#
|
||||
return $(jamfile-module) ;
|
||||
}
|
||||
|
||||
# Initialize the module for a Jamfile.
|
||||
#
|
||||
local rule initialize (
|
||||
module-name # The name of the Jamfile module.
|
||||
: jamfile # The location (binding) of the jamfile for the project to 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 = [ $(project-root-module).location ] ;
|
||||
|
||||
local parent = [ find-jamfile $(jamfile:D) $(project-root) ] ;
|
||||
local parent-module = ;
|
||||
if $(parent)
|
||||
{
|
||||
parent-module = [ load $(parent[1]:D) ] ;
|
||||
}
|
||||
|
||||
module $(module-name)
|
||||
{
|
||||
import project : project ;
|
||||
}
|
||||
|
||||
# Import rules common to all project modules from project-rules module,
|
||||
# define at the end of this file.
|
||||
# (Should be use classes instead?)
|
||||
module $(module-name) { modules.localize project-rules export : * ; }
|
||||
|
||||
modules.poke $(module-name) : __jamfile-location__ : $(jamfile-location) ;
|
||||
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) : __default-build__ : [ $(parent-module).default-build ] ;
|
||||
modules.poke $(module-name) : __requirements__ : [ $(parent-module).requirements ] ;
|
||||
}
|
||||
else
|
||||
{
|
||||
modules.poke $(module-name) : __default-build__ : debug ;
|
||||
}
|
||||
}
|
||||
|
||||
# This module defines rules common to all projects
|
||||
module project-rules {
|
||||
|
||||
@@ -317,6 +387,11 @@ module project-rules {
|
||||
return $(__project-root__) ;
|
||||
}
|
||||
|
||||
rule project-root-module ( )
|
||||
{
|
||||
return $(__project-root-module__) ;
|
||||
}
|
||||
|
||||
rule parent ( )
|
||||
{
|
||||
return $(__parent__) ;
|
||||
@@ -346,6 +421,22 @@ module project-rules {
|
||||
{
|
||||
return $(__subincludes__) ;
|
||||
}
|
||||
|
||||
rule print ( )
|
||||
{
|
||||
import sequence ;
|
||||
import print ;
|
||||
|
||||
print.section "'"$(__id__)"'" ;
|
||||
print.list-start ;
|
||||
print.list-item "Project root:" [ project-root ] ;
|
||||
print.list-item "Parent project:" [ parent ] ;
|
||||
print.list-item "Requirements:" [ requirements ] ;
|
||||
print.list-item "Default build:" [ default-build ] ;
|
||||
print.list-item "Source location:" [ source-location ] ;
|
||||
print.list-item "Subincludes:" [ sequence.insertion-sort [ subincludes ] ] ;
|
||||
print.list-end ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# Copyright (C) Vladimir Prus 2002. Permission to copy, use, modify, sell and
|
||||
# Copyright (C) Vladimir Prus and Rene Rivera 2002.
|
||||
# Permission to copy, use, modify, sell and
|
||||
# distribute this software is granted provided this copyright notice appears in
|
||||
# all copies. This software is provided "as is" without express or implied
|
||||
# warranty, and with no claim as to its suitability for any purpose.
|
||||
@@ -56,6 +57,7 @@ import os.path ;
|
||||
import sequence ;
|
||||
import targets ;
|
||||
import errors : error ;
|
||||
import project-root ;
|
||||
|
||||
|
||||
jamfile-rules = project.project ;
|
||||
@@ -63,68 +65,19 @@ jamfile-rules = project.project ;
|
||||
|
||||
rule load ( jamfile-location )
|
||||
{
|
||||
local module-name = Jamfile@$(jamfile-location) ;
|
||||
local loaded = ;
|
||||
local module-name = [ load-jamfile $(jamfile-location) loaded ] ;
|
||||
|
||||
if ! $(jamfile-location) in $(projects) {
|
||||
|
||||
projects += $(jamfile-location) ;
|
||||
|
||||
# ECHO "project.load $(jamfile-location)" ;
|
||||
|
||||
local project-root = [ locate-project-root $(jamfile-location) ] ;
|
||||
|
||||
# ECHO "project root found in $(project-root)" ;
|
||||
|
||||
modules.load project-root@$(project-root) : project-root.jam : $(project-root) ;
|
||||
|
||||
|
||||
local parent = [ locate-parent $(jamfile-location) : $(project-root) ] ;
|
||||
|
||||
# ECHO "parent found in $(parent)" ;
|
||||
|
||||
if $(parent) != $(jamfile-location) {
|
||||
load $(parent) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
module $(module-name) {
|
||||
import project : project ;
|
||||
}
|
||||
|
||||
# Import rules common to all project modules from project-rules module,
|
||||
# define at the end of this file.
|
||||
# (Should be use classes instead?)
|
||||
|
||||
IMPORT project-rules : [ RULENAMES project-rules ]
|
||||
: $(module-name) : [ RULENAMES project-rules ] : localize ;
|
||||
EXPORT $(module-name) : [ RULENAMES project-rules ] ;
|
||||
for local r in [ RULENAMES $(module-name) ] {
|
||||
IMPORT $(module-name) : $(r) : : $(module-name).$(r) ;
|
||||
}
|
||||
|
||||
modules.poke $(module-name) : __jamfile-location__ : $(jamfile-location) ;
|
||||
modules.poke $(module-name) : __source-location__ : $(jamfile-location) ;
|
||||
modules.poke $(module-name) : __project-root__ : $(project-root) ;
|
||||
modules.poke $(module-name) : __parent__ : $(parent) ;
|
||||
if $(parent) != $(jamfile-location) {
|
||||
modules.poke $(module-name) : __default-build__ : [ Jamfile@$(parent).default-build ] ;
|
||||
modules.poke $(module-name) : __requirements__ : [ Jamfile@$(parent).requirements ] ;
|
||||
} else {
|
||||
modules.poke $(module-name) : __default-build__ : debug ;
|
||||
}
|
||||
|
||||
modules.load $(module-name) : Jamfile : $(jamfile-location) ;
|
||||
|
||||
for local subinclude in [ $(module-name).subincludes ] {
|
||||
if $(loaded)
|
||||
{
|
||||
for local subinclude in [ $(module-name).subincludes ]
|
||||
{
|
||||
load [ os.path.join $(jamfile-location) $(subinclude) ] ;
|
||||
}
|
||||
}
|
||||
return $(module-name) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
rule lookup ( id )
|
||||
{
|
||||
local split = [ MATCH (.*)@(.*) : $(id) ] ;
|
||||
@@ -196,62 +149,6 @@ rule assign-option ( module : option + )
|
||||
|
||||
dummy_module_number = 0 ;
|
||||
|
||||
# Does an upward directory crawl to find a file.
|
||||
# As a side effect, loads that file as a module with auto-generated name.
|
||||
# The side effect should be eliminated once glob builtin is available.
|
||||
rule upward-crawl ( directory : file : upper_limit ? )
|
||||
{
|
||||
local parents = [ os.path.all_parents
|
||||
[ os.path.join $(directory) file ] : $(upper_limit) ] ;
|
||||
|
||||
# ECHO "Parents are:" ;
|
||||
# ECHO $(parents) ;
|
||||
|
||||
local found ;
|
||||
while $(parents) && ! $(found) {
|
||||
found = [ GLOB [ os.path.native $(parents[1]) ] : $(file) ] ;
|
||||
# ECHO "Search in $(parents[1]) gives $(found)" ;
|
||||
parents = $(parents[2-]) ;
|
||||
}
|
||||
if ! $(found) {
|
||||
error "Unable to locate file $(file), starting from $(directory)" ;
|
||||
} else {
|
||||
return [ os.path.make $(found) ] ;
|
||||
}
|
||||
}
|
||||
|
||||
# Locates a file called project-root.jam in parent dirs and returns
|
||||
# the directory where it is found
|
||||
rule locate-project-root ( jamfile-location )
|
||||
{
|
||||
local result = [ upward-crawl $(jamfile-location) : project-root.jam ] ;
|
||||
|
||||
if ! $(result) {
|
||||
EXIT "Unable to locate project root for Jamfile in $(jamfile-location)" ;
|
||||
} else {
|
||||
return [ os.path.parent [ os.path.make $(result) ] ] ;
|
||||
}
|
||||
}
|
||||
|
||||
# Locates a file called Jamfile in parent dirs, stopping search at
|
||||
# 'upper_limit'
|
||||
rule locate-parent ( jamfile-location : upper_limit )
|
||||
{
|
||||
if $(jamfile-location) = $(upper_limit) {
|
||||
return $(jamfile-location) ;
|
||||
} else {
|
||||
local result = [ upward-crawl
|
||||
[ os.path.parent $(jamfile-location) ]
|
||||
: Jamfile : $(upper_limit) ] ;
|
||||
|
||||
if ! $(result) {
|
||||
EXIT "Unable to locate parent Jamfile for $(jamfile-location)" ;
|
||||
} else {
|
||||
return [ os.path.parent [ os.path.make $(result) ] ] ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Returns the name of module corresponding to 'jamfile-location'.
|
||||
#
|
||||
@@ -299,6 +196,179 @@ rule dump ( )
|
||||
}
|
||||
}
|
||||
|
||||
# Default patterns to search for the Jamfiles to use for build
|
||||
# declarations.
|
||||
#
|
||||
JAMFILE = [ modules.peek : JAMFILE ] ;
|
||||
JAMFILE ?= [Jj]amfile [Jj]amfile.jam ;
|
||||
|
||||
# Find the Jamfile at the given location. This returns the exact names of
|
||||
# all the Jamfiles in the given directory. The optional parent-root argument
|
||||
# causes this to search not the given directory but the ones above it up
|
||||
# to the directory given in it.
|
||||
#
|
||||
local rule find-jamfile (
|
||||
dir # The directory(s) to look for a Jamfile.
|
||||
parent-root ? # Optional flag indicating to search for the parent Jamfile.
|
||||
)
|
||||
{
|
||||
# Glob for all the possible Jamfiles according to the match pattern.
|
||||
#
|
||||
local jamfile-glob = ;
|
||||
if $(parent-root)
|
||||
{
|
||||
jamfile-glob = [ find-to-root $(dir:P) : $(JAMFILE) ] ;
|
||||
}
|
||||
else
|
||||
{
|
||||
jamfile-glob = [ GLOB $(dir) : $(JAMFILE) ] ;
|
||||
}
|
||||
|
||||
# Normalize the paths of each file found.
|
||||
#
|
||||
local jamfile-found = ;
|
||||
for local jamfile in $(jamfile-glob)
|
||||
{
|
||||
local normalized = $(jamfile) ;
|
||||
if ! [ os.path.is_rooted $(jamfile) ]
|
||||
{
|
||||
local root-path =
|
||||
[ os.path.parent [ os.path.make [ modules.binding [ CALLER_MODULE ] ] ] ] ;
|
||||
normalized =
|
||||
[ os.path.native [ os.path.root_relative_path $(jamfile) $(root-path) ] ] ;
|
||||
}
|
||||
|
||||
# Filter out if the found file is above the target parent root.
|
||||
if $(parent-root)
|
||||
{
|
||||
if ! [ MATCH "$(parent-root)\\$(SLASH)(.*)" : $(normalized) ]
|
||||
{
|
||||
normalized = ;
|
||||
}
|
||||
}
|
||||
|
||||
jamfile-found += $(normalized) ;
|
||||
}
|
||||
|
||||
return $(jamfile-found) ;
|
||||
}
|
||||
|
||||
# Load a Jamfile at the given directory. Will attempt to load
|
||||
# the file as indicated by the JAMFILE patterns. We return the
|
||||
# module for the Jamfile.
|
||||
#
|
||||
local rule load-jamfile (
|
||||
dir # The directory of the project Jamfile.
|
||||
loaded-var ? # Name of variable to indicated we loaded the Jamfile.
|
||||
)
|
||||
{
|
||||
# See if the Jamfile is where it should be.
|
||||
#
|
||||
local jamfile-to-load = [ find-jamfile $(dir) ] ;
|
||||
|
||||
# Could not find it, error.
|
||||
#
|
||||
if ! $(jamfile-to-load)
|
||||
{
|
||||
EXIT
|
||||
"Unable to load Jamfile. Could not find a Jamfile in"
|
||||
"this directory:" $(dir)"." "Attempted to find it with"
|
||||
"this pattern:" $(JAMFILE)"."
|
||||
"Please consult the documentation at 'http://www.boost.org'." ;
|
||||
}
|
||||
|
||||
# The module of the jamfile.
|
||||
#
|
||||
local jamfile-module = Jamfile<$(jamfile-to-load[1]:D)> ;
|
||||
|
||||
# Don't even bother with the rest if we know the file is already loaded.
|
||||
#
|
||||
if ! [ modules.binding $(jamfile-module) ]
|
||||
{
|
||||
# Multiple Jamfiles found in the same place. Warn about this.
|
||||
# And ensure we use only one of them.
|
||||
#
|
||||
if $(jamfile-to-load[2-])
|
||||
{
|
||||
ECHO
|
||||
"WARNING: Found multiple Jamfiles at this '"$(dir)"' location!"
|
||||
"Loading the first one: '"$(jamfile-to-load[1]:D=)"'." ;
|
||||
}
|
||||
jamfile-to-load = $(jamfile-to-load[1]) ;
|
||||
|
||||
# Initialize the jamfile module before loading.
|
||||
#
|
||||
initialize $(jamfile-module) : $(jamfile-to-load) ;
|
||||
|
||||
# Setup, by coordinating with project-root.
|
||||
#
|
||||
local project-root-module = [ $(jamfile-module).project-root-module ] ;
|
||||
$(project-root-module).register-project $(jamfile-module) ;
|
||||
|
||||
# Now load the Jamfile in it's own context.
|
||||
#
|
||||
modules.load $(jamfile-module)
|
||||
: $(jamfile-to-load:D=) : $(jamfile-to-load:D) ;
|
||||
|
||||
# Indicate we loaded the Jamfile.
|
||||
#
|
||||
if $(loaded-var)
|
||||
{
|
||||
$(loaded-var) = true ;
|
||||
}
|
||||
}
|
||||
|
||||
# Return the Jamfile's filename/module.
|
||||
#
|
||||
return $(jamfile-module) ;
|
||||
}
|
||||
|
||||
# Initialize the module for a Jamfile.
|
||||
#
|
||||
local rule initialize (
|
||||
module-name # The name of the Jamfile module.
|
||||
: jamfile # The location (binding) of the jamfile for the project to 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 = [ $(project-root-module).location ] ;
|
||||
|
||||
local parent = [ find-jamfile $(jamfile:D) $(project-root) ] ;
|
||||
local parent-module = ;
|
||||
if $(parent)
|
||||
{
|
||||
parent-module = [ load $(parent[1]:D) ] ;
|
||||
}
|
||||
|
||||
module $(module-name)
|
||||
{
|
||||
import project : project ;
|
||||
}
|
||||
|
||||
# Import rules common to all project modules from project-rules module,
|
||||
# define at the end of this file.
|
||||
# (Should be use classes instead?)
|
||||
module $(module-name) { modules.localize project-rules export : * ; }
|
||||
|
||||
modules.poke $(module-name) : __jamfile-location__ : $(jamfile-location) ;
|
||||
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) : __default-build__ : [ $(parent-module).default-build ] ;
|
||||
modules.poke $(module-name) : __requirements__ : [ $(parent-module).requirements ] ;
|
||||
}
|
||||
else
|
||||
{
|
||||
modules.poke $(module-name) : __default-build__ : debug ;
|
||||
}
|
||||
}
|
||||
|
||||
# This module defines rules common to all projects
|
||||
module project-rules {
|
||||
|
||||
@@ -317,6 +387,11 @@ module project-rules {
|
||||
return $(__project-root__) ;
|
||||
}
|
||||
|
||||
rule project-root-module ( )
|
||||
{
|
||||
return $(__project-root-module__) ;
|
||||
}
|
||||
|
||||
rule parent ( )
|
||||
{
|
||||
return $(__parent__) ;
|
||||
@@ -346,6 +421,22 @@ module project-rules {
|
||||
{
|
||||
return $(__subincludes__) ;
|
||||
}
|
||||
|
||||
rule print ( )
|
||||
{
|
||||
import sequence ;
|
||||
import print ;
|
||||
|
||||
print.section "'"$(__id__)"'" ;
|
||||
print.list-start ;
|
||||
print.list-item "Project root:" [ project-root ] ;
|
||||
print.list-item "Parent project:" [ parent ] ;
|
||||
print.list-item "Requirements:" [ requirements ] ;
|
||||
print.list-item "Default build:" [ default-build ] ;
|
||||
print.list-item "Source location:" [ source-location ] ;
|
||||
print.list-item "Subincludes:" [ sequence.insertion-sort [ subincludes ] ] ;
|
||||
print.list-end ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,40 +3,36 @@
|
||||
# all copies. This software is provided "as is" without express or implied
|
||||
# warranty, and with no claim as to its suitability for any purpose.
|
||||
|
||||
# Bootstrap the doc system. doing this first makes it possible to document
|
||||
# in all the modules. And import the basic doc rules, to make them easily
|
||||
# available.
|
||||
#
|
||||
SEARCH on <module@>doc.jam = $(BOOST_BUILD_PATH) ;
|
||||
module doc { include <module@>doc.jam ; }
|
||||
IMPORT doc
|
||||
: document-module document-rule document-variable :
|
||||
: document-module document-rule document-variable ;
|
||||
|
||||
# Bootstrap the module system. And bring the import rule into the global module.
|
||||
#
|
||||
SEARCH on <module@>modules.jam = $(BOOST_BUILD_PATH) ;
|
||||
module modules { include <module@>modules.jam ; }
|
||||
IMPORT modules : import : : import ;
|
||||
|
||||
# Re-load the doc system, to clean up things. Both doc and modules
|
||||
# can handle getting included twice.
|
||||
#
|
||||
import doc ;
|
||||
|
||||
# Reload the modules, to clean up things. The modules module can tolerate
|
||||
# being included twice.
|
||||
#
|
||||
import modules ;
|
||||
|
||||
import doc ;
|
||||
import project ;
|
||||
|
||||
# Check to see if the user is asking for help as soon as possible.
|
||||
# This is first action, so that we can interrupt the regular build
|
||||
# process if they are asking for help.
|
||||
#
|
||||
doc.do-help ;
|
||||
|
||||
import build-system ;
|
||||
|
||||
# Load the first Jamfile, and build it.
|
||||
#
|
||||
build-system.construct [ build-system.load-jamfile [ PWD ] ] ;
|
||||
if [ doc.help ]
|
||||
{
|
||||
# Do nothing, the doc system will generate the appropriate
|
||||
# targets that prints out the documentation.
|
||||
# To do this we need to fake the build system loading so the
|
||||
# Jambase doesn't error.
|
||||
module build-system { rule __placeholder__ ( ) { } }
|
||||
}
|
||||
else
|
||||
{
|
||||
# No help requested, go ahead and load and build the users
|
||||
# project.
|
||||
import build-system ;
|
||||
project.load [ PWD ] ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user