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.
26 This creates a hash of global Aliases (dummy targets).
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
):
43 a
= SCons
.Node
.Alias
.Alias(name
, **kw
)
47 def lookup(self
, name
, **kw
):
53 class AliasNodeInfo(SCons
.Node
.NodeInfoBase
):
55 current_version_id
= 2
57 def str_to_node(self
, s
):
58 return default_ans
.Alias(s
)
60 def __getstate__(self
):
62 Return all fields that shall be pickled. Walk the slots in the class
63 hierarchy and add those to the state dictionary. If a '__dict__' slot is
64 available, copy all entries to the dictionary. Also include the version
65 id, which is fixed for all instances of a class.
67 state
= getattr(self
, '__dict__', {}).copy()
68 for obj
in type(self
).mro():
69 for name
in getattr(obj
,'__slots__',()):
70 if hasattr(self
, name
):
71 state
[name
] = getattr(self
, name
)
73 state
['_version_id'] = self
.current_version_id
75 del state
['__weakref__']
81 def __setstate__(self
, state
) -> None:
83 Restore the attributes from a pickled state.
85 # TODO check or discard version
86 del state
['_version_id']
87 for key
, value
in state
.items():
88 if key
not in ('__weakref__',):
89 setattr(self
, key
, value
)
92 class AliasBuildInfo(SCons
.Node
.BuildInfoBase
):
94 current_version_id
= 2
96 class Alias(SCons
.Node
.Node
):
98 NodeInfo
= AliasNodeInfo
99 BuildInfo
= AliasBuildInfo
101 def __init__(self
, name
) -> None:
104 self
.changed_since_last_build
= 1
107 def str_for_display(self
):
108 return '"' + self
.__str
__() + '"'
110 def __str__(self
) -> str:
113 def make_ready(self
) -> None:
116 really_build
= SCons
.Node
.Node
.build
117 is_up_to_date
= SCons
.Node
.Node
.children_are_up_to_date
119 def is_under(self
, dir) -> bool:
120 # Make Alias nodes get built regardless of
121 # what directory scons was run from. Alias nodes
122 # are outside the filesystem:
125 def get_contents(self
):
126 """The contents of an alias is the concatenation
127 of the content signatures of all its sources."""
128 childsigs
= [n
.get_csig() for n
in self
.children()]
129 return ''.join(childsigs
)
131 def sconsign(self
) -> None:
132 """An Alias is not recorded in .sconsign files"""
139 def build(self
) -> None:
140 """A "builder" for aliases."""
143 def convert(self
) -> None:
144 try: del self
.builder
145 except AttributeError: pass
146 self
.reset_executor()
147 self
.build
= self
.really_build
151 Generate a node's content signature, the digested signature
155 cache - alternate node to use for the signature cache
156 returns - the content signature
159 return self
.ninfo
.csig
160 except AttributeError:
163 contents
= self
.get_contents()
164 csig
= hash_signature(contents
)
165 self
.get_ninfo().csig
= csig
168 default_ans
= AliasNameSpace()
170 SCons
.Node
.arg2nodes_lookups
.append(default_ans
.lookup
)
174 # indent-tabs-mode:nil
176 # vim: set expandtab tabstop=4 shiftwidth=4: