📄 stage.jam
字号:
# Copyright (C) Vladimir Prus 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.
# This module defines the 'install' rule, used to copy a set of targets to
# a single location
import targets ;
import "class" : new ;
import property ;
import errors : error ;
import type : type ;
import type ;
import regex ;
import generators ;
import feature ;
import project ;
import property-set ;
import virtual-target ;
import path ;
feature.feature <install-dependencies> : off on : incidental ;
feature.feature <install-type> : : free incidental ;
feature.feature <install-source-root> : : free path ;
feature.feature <so-version> : : free incidental ;
class install-target-class : basic-target
{
import feature project type errors generators path stage ;
import "class" : new ;
rule __init__ ( name-and-dir : project : sources * : requirements * : default-build * )
{
basic-target.__init__ $(name-and-dir) : $(project) : $(sources) : $(requirements)
: $(default-build) ;
}
# If <location> is not set, sets it based on the project data.
rule update-location ( property-set )
{
local loc = [ $(property-set).get <location> ] ;
if ! $(loc)
{
loc = [ path.root $(self.name) [ $(self.project).get location ] ] ;
property-set = [ $(property-set).add-raw $(loc:G=<location>) ] ;
}
return $(property-set) ;
}
# Takes a target that is installed and property set which is
# used when installing.
rule adjust-properties ( target : build-property-set )
{
local ps-raw ;
local a = [ $(target).action ] ;
if $(a)
{
local ps = [ $(a).properties ] ;
ps-raw = [ $(ps).raw ] ;
# Unless <hardcode-dll-paths>true is in properties, which can
# happen only if the user has explicitly requested it, nuke all
# <dll-path> properties
if [ $(property-set).get <hardcode-dll-paths> ] != true
{
ps-raw = [ property.change $(ps-raw) : <dll-path> ] ;
}
# If any <dll-path> properties were specified for installing,
# add them.
local l = [ $(build-property-set).get <dll-path> ] ;
ps-raw += $(l:G=<dll-path>) ;
}
# Remove the <tag> feature on original targets.
ps-raw = [ property.change $(ps-raw) : <tag> ] ;
# And <location>. If stage target has another stage target
# in sources, then we'll get virtual targets with <location>
# property set.
ps-raw = [ property.change $(ps-raw) : <location> ] ;
local d = [ $(build-property-set).get <dependency> ] ;
ps-raw += $(d:G=<dependency>) ;
local d = [ $(build-property-set).get <location> ] ;
ps-raw += $(d:G=<location>) ;
local d = [ $(build-property-set).get <install-source-root> ] ;
# Make the path absolute: we'll use it to compute relative
# paths and making the path absolute will help.
if $(d)
{
d = [ path.root $(d) [ path.pwd ] ] ;
ps-raw += $(d:G=<install-source-root>) ;
}
if $(ps-raw)
{
return [ property-set.create $(ps-raw) ] ;
}
else
{
return [ property-set.empty ] ;
}
}
rule construct ( name : source-targets * : property-set )
{
source-targets = [
targets-to-stage $(source-targets) : $(property-set) ] ;
property-set = [ update-location $(property-set) ] ;
local result ;
for local i in $(source-targets)
{
local staged-targets ;
local new-properties =
[ adjust-properties $(i) : $(property-set) ] ;
# See if something special should be done when staging this
# type. It is indicated by presense of special "staged" type
local t = [ $(i).type ] ;
if $(t) && [ type.registered INSTALLED_$(t) ]
{
local targets = [ generators.construct $(self.project) $(name) :
INSTALLED_$(t) : $(new-properties) : $(i) : * ] ;
staged-targets += $(targets[2-]) ;
}
else
{
staged-targets = [ stage.copy-file $(self.project)
: $(i) : $(new-properties) ] ;
}
if ! $(staged-targets)
{
errors.error "Unable to generate staged version of " [ $(source).str ] ;
}
for t in $(staged-targets)
{
result += [ virtual-target.register $(t) ] ;
}
}
return [ property-set.empty ] $(result) ;
}
# Given the list of source targets explicitly passed to 'stage',
# returns the list of targets which must be staged.
rule targets-to-stage ( source-targets * : property-set )
{
local result ;
# Traverse the dependencies, if needed.
if [ $(property-set).get <install-dependencies> ] = "on"
{
source-targets = [ collect-targets $(source-targets) ] ;
}
# Filter the target types, if needed
local included-types = [ $(property-set).get <install-type> ] ;
for local r in $(source-targets)
{
local ty = [ $(r).type ] ;
if $(ty)
{
# Don't stage searched libs.
if $(ty) != SEARCHED_LIB
{
if $(included-types)
{
if [ include-type $(ty) : $(included-types) ]
{
result += $(r) ;
}
}
else
{
result += $(r) ;
}
}
}
else
{
result += $(r) ;
}
}
return $(result) ;
}
# CONSIDER: figure out why we can't use virtual-target.traverse here.
rule collect-targets ( targets * )
{
# Find subvariants
local s ;
for local t in $(targets)
{
s += [ $(t).creating-subvariant ] ;
}
s = [ sequence.unique $(s) ] ;
local result = $(targets) ;
for local i in $(s)
{
result += [ $(i).all-referenced-targets ] ;
}
local result2 ;
for local r in $(result)
{
if $(r:G) != <use>
{
result2 += $(r:G=) ;
}
}
result = [ sequence.unique $(result2) ] ;
}
# Returns true iff 'type' is subtype of some element of 'types-to-include'.
local rule include-type ( type : types-to-include * )
{
local found ;
while $(types-to-include) && ! $(found)
{
if [ type.is-subtype $(type) $(types-to-include[1]) ]
{
found = true ;
}
types-to-include = $(types-to-include[2-]) ;
}
return $(found) ;
}
}
# Creates a copy of target 'source'. The 'properties' object should
# have a <location> property which specifies where the target must
# be placed.
rule copy-file ( project : source : properties )
{
local targets ;
local name = [ $(source).name ] ;
new-a = [ new action $(source) : common.copy : $(properties) ] ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -