2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-16 13:22:11 +00:00
Files
build/new/type.jam
Vladimir Prus ca18960a9e Implement simple form of use requirements.
* new/virtual-target.jam
        (virtual-target.use-requirements): New rule.
        (virtual-target.set-use-requirements): New rule.

    * new/generators.jam (construct): Use 'use-requirements' of sources.

    * new/targets.jam (basic-target.generate): Store use requirements for
             generated targets.
      (main-target-alternative): Process use requirements.

    * new/project.jam: Support 'use-requirements' project attribute.


[SVN r15821]
2002-10-09 11:33:22 +00:00

118 lines
3.4 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 *
: use-requirements * )
{
# 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 : 5 : 4
: $(type:U) : $(sources) : $(requirements) : $(default-build) : $(use-requirements)
;
}