518a97332d833e62983ce8d9a4e20b9439be93bd
[scons.git] / src / engine / SCons / Node / Alias.py
1
2 """scons.Node.Alias
3
4 Alias nodes.
5
6 This creates a hash of global Aliases (dummy targets).
7
8 """
9
10 #
11 # Copyright (c) 2001, 2002, 2003 Steven Knight
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__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
34
35 import UserDict
36
37 import SCons.Errors
38 import SCons.Node
39 import SCons.Util
40
41 class AliasNameSpace(UserDict.UserDict):
42     def Alias(self, name):
43         if self.has_key(name):
44             raise SCons.Errors.UserError
45         self[name] = SCons.Node.Alias.Alias(name)
46         return self[name]
47
48     def lookup(self, name):
49         try:
50             return self[name]
51         except KeyError:
52             return None
53
54 class Alias(SCons.Node.Node):
55     def __init__(self, name):
56         SCons.Node.Node.__init__(self)
57         self.name = name
58
59     def __str__(self):
60         return self.name
61
62     def build(self):
63         """A "builder" for aliases."""
64         pass
65
66     def current(self, calc):
67         """If all of our children were up-to-date, then this
68         Alias was up-to-date, too."""
69         # Allow the children to calculate their signatures.
70         calc.bsig(self)
71         state = 0
72         for kid in self.children(None):
73             s = kid.get_state()
74             if s and (not state or s > state):
75                 state = s
76         if state == 0 or state == SCons.Node.up_to_date:
77             return 1
78         else:
79             return 0
80
81     def sconsign(self):
82         """An Alias is not recorded in .sconsign files"""
83         pass
84
85     def is_under(self, dir):
86         # Make Alias nodes get built regardless of 
87         # what directory scons was run from. Alias nodes
88         # are outside the filesystem:
89         return 1
90
91     def get_contents(self):
92         """The contents of an alias is the concatenation
93         of all the contents of its sources"""
94         contents = ""
95         for kid in self.children(None):
96             contents = contents + kid.get_contents()
97         return contents
98         
99 default_ans = AliasNameSpace()
100
101 SCons.Node.arg2nodes_lookups.append(default_ans.lookup)