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