⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 virtual-target.jam

📁 boost库提供标准的C++ API 配合dev c++使用,功能更加强大
💻 JAM
📖 第 1 页 / 共 3 页
字号:
                result = $(t) ;
            }
            else 
            {
                if $(a1) && $(a2) && [ $(a1).action-name ] = [ $(a2).action-name ] && 
                  [ $(a1).sources ] = [ $(a2).sources ]
                {
                    local ps1 = [ $(a1).properties ] ;
                    local ps2 = [ $(a2).properties ] ;
                    local p1 = [ $(ps1).base ] [ $(ps1).free ] [ $(ps1).dependency ] ;
                    local p2 = [ $(ps2).base ] [ $(ps2).free ] [ $(ps2).dependency ] ;
                    if $(p1) = $(p2) 
                    {                        
                        result = $(t) ;
                    }                    
                }
            }                        
        }
    }
    if ! $(result)
    {
        .cache.$(signature) += $(target) ;
        result = $(target) ;
    }

    return $(result) ;
}

rule register-actual-name ( actual-name : virtual-target )
{
    if $(.actual.$(actual-name))
    {
        errors.error "Duplicate name of actual target:" $(actual-name) 
          : "previous virtual target" [ $(.actual.$(actual-name)).str ] 
          : "another virtual target" [ $(virtual-target).str ] ;
    }
    else
    {
        .actual.$(actual-name) = $(virtual-target) ;
    }        
}


# Traverses the dependency graph of 'target' and return all targets that will
# be created before this one is created. If root of some dependency graph is
# found during traversal, it's either included or not, dependencing of the
# value of 'include-roots'. In either case, sources of root are not traversed.
rule traverse ( target : include-roots ? : include-sources ? )
{
    local result ;
    if [ $(target).action ]
    {
        local action = [ $(target).action ] ;
        # This includes 'target' as well
        result += [ $(action).targets ] ;

        for local t in [ $(action).sources ]
        {
            if ! [ $(t).root ]
            {
                result += [ traverse $(t) : $(include-roots) : $(include-sources) ] ;
            }
            else if $(include-roots)
            {
                result += $(t) ;
            }            
        }
    }
    else if $(include-sources)
    {
        result = $(target) ;
    }    
    return $(result) ;
}

# Takes an 'action' instances and creates new instance of it
# and all produced target. The rule-name and properties are set
# to 'new-rule-name' and 'new-properties', if those are specified.
# Returns the cloned action.
rule clone-action ( action : new-project : new-action-name ? : new-properties ? )
{
    if ! $(new-action-name)
    {
        new-action-name = [ $(action).action-name ] ;
    }
    if ! $(new-properties)
    {
        new-properties = [ $(action).properties ] ;
    }
                    
    local cloned-targets ;
    for local target in [ $(action).targets ]
    {
        local n = [ $(target).name ] ;
        local cloned-target = [ class.new file-target $(n:D=) : [ $(target).type ] 
          : $(new-project) ] ;
        local d = [ $(target).dependencies ] ;
        if $(d)
        {            
            $(cloned-target).depends $(d) ;
        }                    
        $(cloned-target).root [ $(target).root ] ;
        $(cloned-target).creating-subvariant [ $(target).creating-subvariant ] ;
        
        cloned-targets += $(cloned-target) ;
    }        
        
    local action-class = [ modules.peek $(action) : __class__ ] ;
    
    local cloned-action = [ class.new $(action-class) $(cloned-targets) : 
      [ $(action).sources ] : $(new-action-name) : $(new-properties) ] ;
    
    for local cloned-target in $(cloned-targets)
    {        
        $(cloned-target).action $(cloned-action) ;
    }
    
    
    return $(cloned-action) ;        
}




# Clones a dependency graph template, given one of its root,
# and a new source target to instantinate the template with.
#
# If 'target's name is "%" and type is equal to 'new-source's
# return 'new-source', otherwise created a new target:
#  - if there "%" in target's name, its replaced with 'new-target's
#  - project for new target is the same as for 'new-target'
#  - other attributes are copied
#
# If 'dont-recurse' is not set, clones action, which results in
# cloning of other targets, and, ultimately, cloning of the
# entire dependency graph.
#
# The 'new-project' parameter tells what project should be assigned
# for newly created non-source targets.
rule clone-template ( target dont-recurse ? : new-source : new-project )
{
    local name = [ $(new-source).name ] ;
    local old-name = [ $(target).name ] ;
    local new-name = $(old-name) ;
    local m = [ MATCH (.*)(%)(.*) : $(old-name) ] ;
    if $(m)
    {
        if [ $(target).action ]
        {
            new-name = [ sequence.join $(m[1]) $(name:D=) $(m[3]) ] ;
        }
        else
        {
            new-name = [ sequence.join $(m[1]) $(name) $(m[3]) ] ;
        }
    }

    if $(old-name) = % && [ $(target).type ] = [ $(new-source).type ]
    {
        return $(new-source) ;
    }
    else
    {
        local cloned = [ new file-target $(new-name) : [ $(target).type ] :
          $(new-project) ] ;

        if ! $(dont-recurse) && [ $(target).action ]
        {
            local cloned-action = [ clone-action-template
                [ $(target).action ] $(target) $(cloned) : $(new-source) : $(new-project) ] ;

            cloned-targets = $(cloned) ;
            for t in [ $(cloned-action).targets ]
            {
                if $(t) != $(target)
                {
                    cloned-targets +=
                      [ clone-template $(t) dont-recurse : $(new-source) : $(new-project) ] ;
                }
            }
            local cloned-targets2 ;
            for local t in $(cloned-targets)
            {
                $(t).action $(cloned-action) ;

                cloned-targets2 += [ register $(t) ] ;

            }
            $(cloned-action).set-targets $(cloned-targets2) ;
            cloned = $(cloned-targets2[1]) ;
        }
        else
        {
            cloned = [ register $(cloned) ] ;
        }
        return $(cloned) ;
    }
}

# Clones an action template: helper for clone-template above.
local rule clone-action-template ( action from cloned-from : new-source : new-project )
{
    local targets ;
    local sources ;

    for local t in [ $(action).sources ]
    {
        sources += [ clone-template $(t) : $(new-source) : $(new-project) ] ;
    }

    local action-class = [ modules.peek $(action) : __class__ ] ;

    local ps = [ $(action).properties ] ;
    local cloned = [ new $(action-class) [ $(action).targets ] : $(sources)
                     : [ $(action).action-name ] : $(ps) ] ;

    return $(cloned) ;
}

class subvariant
{
    import sequence ;    
    import type ;
    
    rule __init__ ( main-target # The instance of main-target class
        : property-set                     # Properties requested for this target
        : sources *
        : build-properties                 # Actually used properties
        : sources-usage-requirements       # Properties propagated from sources
        : created-targets * )              # Top-level created targets
    {        
        self.main-target = $(main-target) ;        
        self.properties = $(property-set) ;
        self.sources = $(sources) ;
        self.build-properties = $(build-properties) ;
        self.sources-usage-requirements = $(sources-usage-requirements) ;
        self.created-targets = $(created-targets) ;

        # Pre-compose the list of other dependency graphs, on which this one
        # depends
        local deps = [ $(build-properties).get <implicit-dependency> ] ;
        for local d in $(deps)
        {
            self.other-dg += [ $(d:G=).creating-subvariant ] ;
        }
        
        self.other-dg = [ sequence.unique $(self.other-dg) ] ;
    }
    
               
    rule main-target ( )
    {
        return $(self.main-target) ;
    }
    
    rule created-targets ( ) 
    {
        return $(self.created-targets) ;
    }
    
    rule requested-properties ( )
    {
        return $(self.properties) ;
    }
    
    rule build-properties ( )
    {
        return $(self.build-properties) ;
    }
        
    rule sources-usage-requirements ( )
    {
        return $(self.sources-usage-requirements) ;
    }
    
    rule set-usage-requirements ( usage-requirements )
    {
        self.usage-requirements = $(usage-requirements) ;
    }
    
    rule usage-requirements ( )
    {
        return $(self.usage-requirements) ;
    }
            
    # Returns all targets referenced by this subvariant,
    # either directly or indirectly, and 
    # either as sources, or as dependency properties.
    rule all-referenced-targets ( )
    {
        # Find directly referenced targets.
        local deps = [ $(self.build-properties).dependency ] ;
        local all-targets = $(self.sources) $(deps:G=) ;
        
        # Find other subvariants.
        local r ;
        for local t in $(all-targets)
        {            
            r += [ $(t).creating-subvariant ] ;
        }
        r = [ sequence.unique $(r) ] ;
        for local s in $(r) 
        {
            if $(s) != $(__name__)
            {
                all-targets += [ $(s).all-referenced-targets ] ;
            }            
        }
        return $(all-targets) ;                        
    }
               
    # Returns the properties which specify implicit include paths to
    # generated headers. This traverses all targets in this subvariant,
    # and subvariants referred by <implcit-dependecy>properties.
    # For all targets which are of type 'target-type' (or for all targets,
    # if 'target-type' is not specified), the result will contain
    # <$(feature)>path-to-that-target.
    rule implicit-includes ( feature : target-type ? )
    {
        local key = ii$(feature)-$(target-type:E="") ;
        if ! $($(key))-is-nonempty
        {
            local target-paths = [ all-target-directories $(target-type) ] ;    
            target-paths = [ sequence.unique $(target-paths) ] ;
            local result = $(target-paths:G=$(feature)) ;
            if ! $(result)
            {
                result = "" ;
            }            
            $(key) = $(result) ;
        }
        if $($(key)) = ""
        {
            return ;
        }
        else
        {
            return $($(key)) ;
        }        
    }
        
    rule all-target-directories ( target-type ? )
    {
        if ! $(self.target-directories)
        {
            compute-target-directories $(target-type) ;
        }                
        return $(self.target-directories) ;
    }
    
    rule compute-target-directories ( target-type ? )
    {   
        local result ;
        for local t in $(self.created-targets)
        {
            if $(target-type) && ! [ type.is-derived [ $(t).type ] $(target-type) ] 
            {
                # Skip target which is of wrong type.
            }
            else
            {                
                result = [ sequence.merge $(result) : [ $(t).path ] ] ;
            }            
        }
        for local d in $(self.other-dg)
        {
            result += [ $(d).all-target-directories $(target-type) ] ;
        }
        self.target-directories = $(result) ;
    }   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -