1
2"""scons.Node.Alias
3
4Alias nodes.
5
6This creates a hash of global Aliases (dummy targets).
7
8"""
9
10#
11# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 The SCons Foundation
12#
13# Permission is hereby granted, free of charge, to any person obtaining
14# a copy of this software and associated documentation files (the
15# "Software"), to deal in the Software without restriction, including
16# without limitation the rights to use, copy, modify, merge, publish,
17# distribute, sublicense, and/or sell copies of the Software, and to
18# permit persons to whom the Software is furnished to do so, subject to
19# the following conditions:
20#
21# The above copyright notice and this permission notice shall be included
22# in all copies or substantial portions of the Software.
23#
24# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
25# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
26# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31#
32
33__revision__ = "src/engine/SCons/Node/Alias.py 4369 2009/09/19 15:58:29 scons"
34
35import string
36import UserDict
37
38import SCons.Errors
39import SCons.Node
40import SCons.Util
41
42class AliasNameSpace(UserDict.UserDict):
43    def Alias(self, name, **kw):
44        if isinstance(name, SCons.Node.Alias.Alias):
45            return name
46        try:
47            a = self[name]
48        except KeyError:
49            a = SCons.Node.Alias.Alias(*(name,), **kw)
50            self[name] = a
51        return a
52
53    def lookup(self, name, **kw):
54        try:
55            return self[name]
56        except KeyError:
57            return None
58
59class AliasNodeInfo(SCons.Node.NodeInfoBase):
60    current_version_id = 1
61    field_list = ['csig']
62    def str_to_node(self, s):
63        return default_ans.Alias(s)
64
65class AliasBuildInfo(SCons.Node.BuildInfoBase):
66    current_version_id = 1
67
68class Alias(SCons.Node.Node):
69
70    NodeInfo = AliasNodeInfo
71    BuildInfo = AliasBuildInfo
72
73    def __init__(self, name):
74        SCons.Node.Node.__init__(self)
75        self.name = name
76
77    def str_for_display(self):
78        return '"' + self.__str__() + '"'
79
80    def __str__(self):
81        return self.name
82
83    def make_ready(self):
84        self.get_csig()
85
86    really_build = SCons.Node.Node.build
87    is_up_to_date = SCons.Node.Node.children_are_up_to_date
88
89    def is_under(self, dir):
90        # Make Alias nodes get built regardless of
91        # what directory scons was run from. Alias nodes
92        # are outside the filesystem:
93        return 1
94
95    def get_contents(self):
96        """The contents of an alias is the concatenation
97        of the content signatures of all its sources."""
98        childsigs = map(lambda n: n.get_csig(), self.children())
99        return string.join(childsigs, '')
100
101    def sconsign(self):
102        """An Alias is not recorded in .sconsign files"""
103        pass
104
105    #
106    #
107    #
108
109    def changed_since_last_build(self, target, prev_ni):
110        cur_csig = self.get_csig()
111        try:
112            return cur_csig != prev_ni.csig
113        except AttributeError:
114            return 1
115
116    def build(self):
117        """A "builder" for aliases."""
118        pass
119
120    def convert(self):
121        try: del self.builder
122        except AttributeError: pass
123        self.reset_executor()
124        self.build = self.really_build
125
126    def get_csig(self):
127        """
128        Generate a node's content signature, the digested signature
129        of its content.
130
131        node - the node
132        cache - alternate node to use for the signature cache
133        returns - the content signature
134        """
135        try:
136            return self.ninfo.csig
137        except AttributeError:
138            pass
139
140        contents = self.get_contents()
141        csig = SCons.Util.MD5signature(contents)
142        self.get_ninfo().csig = csig
143        return csig
144
145default_ans = AliasNameSpace()
146
147SCons.Node.arg2nodes_lookups.append(default_ans.lookup)
148
149# Local Variables:
150# tab-width:4
151# indent-tabs-mode:nil
152# End:
153# vim: set expandtab tabstop=4 shiftwidth=4:
154