2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-17 13:42:14 +00:00
Files
build/new/type.jam
Vladimir Prus f1ae04c4a9 Infrastructure for dependency scanning.
* virtual-target.jam (virtual-target.actualize): Accept
        'scanner' parameter and create different actual targets
        for different values of that parameter.
     (virtual-target.includes): Remove.
     (binding): New rule
     (remember-binding): New rule.

    * type.jam (set-scanner): New rule. (get-scanner): New rule.

    * scanner.jam: New file.

    * class.jam (__init__): Define __name__ in class scopes.

    * builtin.jam (c-scanner): New scanner class, associated with CPP
        files.


[SVN r15644]
2002-10-02 10:04:03 +00:00

117 lines
3.3 KiB
Plaintext

# 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.
# Deals with target type declaration and defines target class which supports
# typed targets.
import feature ;
import generators : * ;
import class : class new ;
feature.feature target-type : : composite optional ;
feature.feature base-target-type : : composite optional ;
feature.feature main-target-type : : optional incidental ;
# Registers a target type, possible derived from a 'base-type'.
# If 'suffixes' are provided, they given all the suffixes that mean a file is of 'type'.
# Also, the first element gives the suffix to be used when constructing and object of
# 'type'.
# If 'main' is given, a rule with the same name as the target type
# and signature
# rule target-type ( name : sources * : requirements * : default-build )
# will be added to the global scope.
rule register ( type : suffixes * : base-type ? : main ? )
{
if $(type) in $(.types)
{
error "Type $(type) is already registered." ;
}
else
{
.types += $(type) ;
.bases.$(type) = $(base-type) ;
.suffix.$(type) = $(suffixes[1]) ;
.type.$(suffixes) = $(type) ;
feature.extend target-type : $(type) ;
feature.compose <target-type>$(type) : $(base-type:G=<base-target-type>) ;
feature.compose <base-target-type>$(type) : $(base-type:G=<base-target-type>) ;
if $(main)
{
IMPORT $(__name__) : main-target-rule : : $(type:L) ;
}
}
}
# Sets a scanner class that will be used for this 'type'.
rule set-scanner ( type : scanner )
{
if ! $(type) in $(.types)
{
error "Type" $(type) "is not declared" ;
}
.scanner.$(type) = $(scanner) ;
}
# Returns a scanner instance appropriate to 'type' and 'properties'.
rule get-scanner ( type : properties * )
{
if $(.scanner.$(type)) {
return [ scanner.get $(.scanner.$(type)) : $(properties) ] ;
}
}
# Returns true if 'type' has 'base' as its direct or
# indirect base.
rule is-derived ( type base )
{
if $(base) in $(.bases.$(type))
{
return true ;
}
else
{
# CONSIDER: maybe break when 'found' is true
local found ;
for local e in $(.bases.$(type))
{
if [ is-derived $(e) $(base) ]
{
found = true ;
}
}
return $(found) ;
}
}
# Returns suffix that should be used when generating target of 'type'.
rule generated-target-suffix ( type )
{
return $(.suffix.$(type)) ;
}
# Returns file type given its suffix. The 'suffix' parameter should include
# the dot.
rule type ( suffix )
{
return $(.type$(suffix)) ;
}
rule main-target-rule ( name : sources * : requirements * : default-build ? )
{
# First find requuired target type, which is equal to the name used to
# invoke us.
local bt = [ BACKTRACE 1 ] ;
local type = $(bt[4]) ;
targets.main-target-alternative $(name) [ CALLER_MODULE ] typed-target : 3 : 4
: $(type:U) : $(sources) : $(requirements) : $(default-build)
;
}