Support Repository and Default().
[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 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__ __USER__"
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 set_bsig(self, bsig):
67         """An alias has no signature."""
68         self.bsig = None
69
70     def set_csig(self, csig):
71         """An alias has no signature."""
72         self.csig = None
73
74     def current(self, calc):
75         """If all of our children were up-to-date, then this
76         Alias was up-to-date, too."""
77         # Allow the children to calculate their signatures.
78         calc.bsig(self)
79         state = 0
80         for kid in self.children(None):
81             s = kid.get_state()
82             if s and (not state or s > state):
83                 state = s
84         if state == 0 or state == SCons.Node.up_to_date:
85             return 1
86         else:
87             return 0
88
89     def sconsign(self):
90         """An Alias is not recorded in .sconsign files"""
91         pass
92
93     def is_under(self, dir):
94         # Make Alias nodes get built regardless of 
95         # what directory scons was run from. Alias nodes
96         # are outside the filesystem:
97         return 1
98         
99 default_ans = AliasNameSpace()
100
101 SCons.Node.arg2nodes_lookups.append(default_ans.lookup)