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

📄 virtual-target.jam

📁 C++的一个好库。。。现在很流行
💻 JAM
📖 第 1 页 / 共 3 页
字号:
            # for identification, since path is as unique as it can get.
            return p$(path) ;            
        }
        else
        {
            # File is either source, which will be searched for, or is not a file at
            # all. Use the location of project for distinguishing.
            local project-location = [ $(self.project).get location ] ;
            local location-grist =
              [ sequence.join [ regex.split $(project-location) "/" ] : "!" ] ;
            
            if $(self.action)
            {
                local ps = [ $(self.action).properties ] ;     
                local property-grist = [ $(ps).as-path ] ;
                # 'property-grist' can be empty when 'ps' is an empty
                # property set.
                if $(property-grist)
                {                    
                    location-grist = $(location-grist)/$(property-grist) ;
                }                
            }            
                        
            return l$(location-grist) ;
        }                
    }            

    # Given the target name specified in constructor, returns the
    # name which should be really used, by looking at the <tag> properties.
    # The tag properties come in two flavour:
    #   - <tag>value, 
    #   - <tag>@rule-name
    # In the first case, value is just added to name
    # In the second case, the specified rule is called with specified name,
    # target type and properties and should return the new name.
    # If not <tag> property is specified, or the rule specified by
    # <tag> returns nothing, returns the result of calling 
    # virtual-target.add-suffix
    rule _adjust-name ( specified-name )
    {        
        local ps ;
        if $(self.action) 
        {
            ps = [ $(self.action).properties ] ;
        }
        else
        {
            ps = [ property-set.empty ] ;
        }
        
        local tag = [ $(ps).get <tag> ] ;

        if $(tag)
        {
            local rule-name = [ MATCH ^@(.*) : $(tag) ] ;
            if $(rule-name)
            {
                if $(tag[2])
                {
                    errors.error "<tag>@rulename is present but is not the only <tag> feature" ;
                }
                
                self.name = [ indirect.call $(rule-name) $(specified-name) :
                  $(self.type) :  $(ps) ] ;
            }
            else
            {
                errors.error 
                  "The value of the <tag> feature must be '@rule-nane'" ;
            }
        }
        
        # If there's no tag or the tag rule returned nothing.
        if ! $(tag) || ! $(self.name)
        {                            
            self.name = [ virtual-target.add-prefix-and-suffix
                $(specified-name) : $(self.type) : $(ps) ] ;
        }    
    }
    
}

# Appends the suffix appropriate to 'type/property-set' combination
# to the specified name and returns the result.
rule add-prefix-and-suffix ( specified-name : type ? : property-set )
{
    local suffix = [ type.generated-target-suffix $(type) : $(property-set) ] ;
    suffix = .$(suffix) ;
    
    local prefix ;
    
    if [ type.is-derived $(type) LIB ] && [ os.on-unix ] 
       && ! [ MATCH ^(lib) : $(specified-name) ]
    {
        prefix = "lib" ;
    }
    
    return $(prefix:E="")$(specified-name)$(suffix:E="") ;
}


# File target with explicitly known location.
#
# The file path is determined as
#    - value passed to the 'set-path' method, if any
#    - for derived files, project's build dir, joined with components
#      that describe action's properties. If the free properties
#      are not equal to the project's reference properties
#      an element with name of main target is added.
#    - for source files, project's source dir
#
# The file suffix is
#     - the value passed to the 'suffix' method, if any, or
#     - the suffix which correspond to the target's type.
#
class file-target : abstract-file-target 
{
    import common ;    
    import errors ;
    
    rule __init__ (
      name exact ?
        : type ?  # Optional type for this target
        : project
        : action ?
        : path ?
    )
    {
        abstract-file-target.__init__ $(name) $(exact) : $(type) : $(project) 
          : $(action) ;   

        self.path = $(path) ;
    }
        
    rule actualize-location ( target )
    {
        if $(self.action)
        {
            # This is a derived file.
            local path = [ path ] ;
            LOCATE on $(target) = $(path) ;                        

            # Make sure the path exists.
            DEPENDS $(target) : $(path) ;
            common.MkDir $(path) ;

            # It's possible that the target name includes a directory
            # too, for example when installing headers. Create that
            # directory.
            if $(target:D)
            {
                local d = $(target:D) ;
                d = $(d:R=$(path)) ;
                DEPENDS $(target) : $(d) ;

                common.MkDir $(d) ;
            }            
            
            # For real file target, we create gristless target that
            # depends on the real target. This allows to run
            #
            #    bjam hello.o
            #
            # without trying to guess the name of the real target.            
            DEPENDS $(target:G=) : $(target) ;
        }
        else
        {
            SEARCH on $(target) = [ path.native $(self.path) ] ;
        }        
    }
    
    # Returns the directory for this target
    rule path ( )
    {
        if ! $(self.path)
        {
            if $(self.action)
            {       
                local p = [ $(self.action).properties ] ;                
                local path = [ $(p).target-path ] ;
                
                if $(path[2]) = true
                {        
                    # Indicates that the path is relative to
                    # build dir.
                    path = [ path.join [ $(self.project).build-dir ]
                       $(path[1]) ] ;
                }
                                
                # Store the computed path, so that it's not recomputed
                # any more
                self.path = [ path.native $(path) ] ;
            }            
        }
        return $(self.path) ;
     }

}

class notfile-target : abstract-file-target
{
    rule __init__ ( name : project : action ? )
    {
        abstract-file-target.__init__ $(name) : : $(project) : $(action) ;
    }
    
    # Returns nothing, to indicate that target path is not known.
    rule path ( )
    {
        return ;
    }
            
    rule actualize-location ( target )
    {
        NOTFILE $(target) ;
        ALWAYS $(target) ;
    }    
}    

# Class which represents an action.
# Both 'targets' and 'sources' should list instances of 'virtual-target'.
# Action name should name a rule with this prototype
#     rule action-name ( targets + : sources * : properties * )
# Targets and sources are passed as actual jam targets. The rule may
# not establish dependency relationship, but should do everything else.
class action 
{
    import type toolset property-set indirect class path assert ;
    
    rule __init__ ( sources * : action-name + : property-set ? )
    {        
        self.sources = $(sources) ;
    
        self.action-name = [ indirect.make-qualified $(action-name) ] ;
        
        if ! $(property-set) 
        {
            property-set = [ property-set.empty ] ;
        }
        
        if ! [ class.is-instance $(property-set) ]
        {        
            errors.error "Property set instance required" ;
        }
        
        self.properties = $(property-set) ;
    }        
    
    rule add-targets ( targets * )
    {
        self.targets += $(targets) ;
    }
        
    rule targets ( )
    {
        return $(self.targets) ;
    }

    rule sources ( )
    {
        return $(self.sources) ;
    }

    rule action-name ( )
    {
        return $(self.action-name) ;
    }

    rule properties ( )
    {
        return $(self.properties) ;
    }

    # Generates actual build instructions.
    rule actualize ( )
    {
        if ! $(self.actualized)
        {
            self.actualized = true ;

            local ps = [ properties ] ;
            local properties = [ adjust-properties $(ps) ] ;

            local actual-targets ;
            for local i in [ targets ]
            {
                actual-targets += [ $(i).actualize ] ;
            }

            actualize-sources [ sources ] : $(properties) ;

            DEPENDS $(actual-targets) : $(self.actual-sources) $(self.dependency-only-sources) ;

            # Action name can include additional argument to rule, which should not
            # be passed to 'set-target-variables'
            toolset.set-target-variables
              [ indirect.get-rule $(self.action-name[1]) ] $(actual-targets)
                : $(properties) ;
            
            indirect.call $(self.action-name) 
              $(actual-targets) : $(self.actual-sources) : [ $(properties).raw ] 
                ;
            
            # Since we set up creating action here, we also set up
            # action for cleaning up
            common.Clean clean : $(actual-targets) ;
        }
    }

    # Helper for 'actualize-sources'.
    # For each passed source, actualizes it with the appropriate scanner.
    # Returns the actualized virtual targets.
    rule actualize-source-type ( sources * : property-set )
    {
        local result = ;
        for local i in $(sources)
        {
            local scanner ;
            if [ $(i).type ]
            {
                scanner =
                  [ type.get-scanner [ $(i).type ] : $(property-set) ] ;
            }
            result += [ $(i).actualize $(scanner) ] ;
        }
        
        return $(result) ;
    }
    
    # Creates actual jam targets for sources. Initialized two member
    # variables:.
    # 'self.actual-sources' -- sources which are passed to updating action
    # 'self.dependency-only-sources' -- sources which are made dependencies, but
    # are not used otherwise.
    #
    # New values will be *appended* to the variables. They may be non-empty,
    # if caller wants it.
    rule actualize-sources ( sources * : property-set )
    {
        local dependencies = [ $(self.properties).get <dependency> ] ;
                
        self.dependency-only-sources += [ 
          actualize-source-type $(dependencies) : $(property-set) ] ;
        self.actual-sources += [ 
          actualize-source-type $(sources) : $(property-set) ] ;
    }

    # Determined real properties when trying building with 'properties'.
    # This is last chance to fix properties, for example to adjust includes
    # to get generated headers correctly. Default implementation returns
    # its argument.
    rule adjust-properties ( property-set )
    {
        return $(property-set) ;
    }
}

# Action class which does nothing --- it produces the targets with
# specific properties out of nowhere. It's needed to distinguish virtual
# targets with different properties that are known to exist, and have no 
# actions which create them.
class null-action : action 
{
    rule __init__ ( property-set ? )
    {
        action.__init__  : .no-action : $(property-set) ;
    }

⌨️ 快捷键说明

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