• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2003, 2004, 2006 Vladimir Prus
2# Distributed under the Boost Software License, Version 1.0.
3# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
4
5# Status: ported (danielw)
6# Base revision: 56043
7
8#  This module defines the 'alias' rule and associated class.
9#
10#  Alias is just a main target which returns its source targets without any
11#  processing. For example::
12#
13#    alias bin : hello test_hello ;
14#    alias lib : helpers xml_parser ;
15#
16#  Another important use of 'alias' is to conveniently group source files::
17#
18#    alias platform-src : win.cpp : <os>NT ;
19#    alias platform-src : linux.cpp : <os>LINUX ;
20#    exe main : main.cpp platform-src ;
21#
22#  Lastly, it's possible to create local alias for some target, with different
23#  properties::
24#
25#    alias big_lib : : @/external_project/big_lib/<link>static ;
26#
27
28import targets
29import property_set
30from b2.manager import get_manager
31
32from b2.util import metatarget, is_iterable_typed
33
34class AliasTarget(targets.BasicTarget):
35
36    def __init__(self, *args):
37        targets.BasicTarget.__init__(self, *args)
38
39    def construct(self, name, source_targets, properties):
40        if __debug__:
41            from .virtual_target import VirtualTarget
42            assert isinstance(name, basestring)
43            assert is_iterable_typed(source_targets, VirtualTarget)
44            assert isinstance(properties, property_set.PropertySet)
45        return [property_set.empty(), source_targets]
46
47    def compute_usage_requirements(self, subvariant):
48        if __debug__:
49            from .virtual_target import Subvariant
50            assert isinstance(subvariant, Subvariant)
51        base = targets.BasicTarget.compute_usage_requirements(self, subvariant)
52        # Add source's usage requirement. If we don't do this, "alias" does not
53        # look like 100% alias.
54        return base.add(subvariant.sources_usage_requirements())
55
56@metatarget
57def alias(name, sources=[], requirements=[], default_build=[], usage_requirements=[]):
58    assert isinstance(name, basestring)
59    assert is_iterable_typed(sources, basestring)
60    assert is_iterable_typed(requirements, basestring)
61    assert is_iterable_typed(default_build, basestring)
62    assert is_iterable_typed(usage_requirements, basestring)
63    project = get_manager().projects().current()
64    targets = get_manager().targets()
65
66    targets.main_target_alternative(AliasTarget(
67        name, project,
68        targets.main_target_sources(sources, name, no_renaming=True),
69        targets.main_target_requirements(requirements or [], project),
70        targets.main_target_default_build(default_build, project),
71        targets.main_target_usage_requirements(usage_requirements or [], project)))
72
73# Declares the 'alias' target. It will build sources, and return them unaltered.
74get_manager().projects().add_rule("alias", alias)
75
76