1 """scons.Node.Python
2
3 Python nodes.
4
5 """
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 __revision__ = "src/engine/SCons/Node/Python.py 74b2c53bc42290e911b334a6b44f187da698a668 2017/11/14 13:16:53 bdbaddog"
31
32 import SCons.Node
33
35 __slots__ = ('csig',)
36 current_version_id = 2
37
38 field_list = ['csig']
39
42
44 """
45 Return all fields that shall be pickled. Walk the slots in the class
46 hierarchy and add those to the state dictionary. If a '__dict__' slot is
47 available, copy all entries to the dictionary. Also include the version
48 id, which is fixed for all instances of a class.
49 """
50 state = getattr(self, '__dict__', {}).copy()
51 for obj in type(self).mro():
52 for name in getattr(obj,'__slots__',()):
53 if hasattr(self, name):
54 state[name] = getattr(self, name)
55
56 state['_version_id'] = self.current_version_id
57 try:
58 del state['__weakref__']
59 except KeyError:
60 pass
61
62 return state
63
65 """
66 Restore the attributes from a pickled state.
67 """
68
69 del state['_version_id']
70 for key, value in state.items():
71 if key not in ('__weakref__',):
72 setattr(self, key, value)
73
74
78
79 -class Value(SCons.Node.Node):
80 """A class for Python variables, typically passed on the command line
81 or generated by a script, but not from a file or some other source.
82 """
83
84 NodeInfo = ValueNodeInfo
85 BuildInfo = ValueBuildInfo
86
87 - def __init__(self, value, built_value=None):
94
96 return repr(self.value)
97
99 return str(self.value)
100
103
107
108 is_up_to_date = SCons.Node.Node.children_are_up_to_date
109
115
116 - def write(self, built_value):
117 """Set the value of the node."""
118 self.built_value = built_value
119
121 """Return the value. If necessary, the value is built."""
122 self.build()
123 if not hasattr(self, 'built_value'):
124 self.built_value = self.value
125 return self.built_value
126
128 """By the assumption that the node.built_value is a
129 deterministic product of the sources, the contents of a Value
130 are the concatenation of all the contents of its sources. As
131 the value need not be built when get_contents() is called, we
132 cannot use the actual node.built_value."""
133
134 contents = str(self.value)
135 for kid in self.children(None):
136 contents = contents + kid.get_contents().decode()
137 return contents
138
139 - def get_contents(self):
140 text_contents = self.get_text_contents()
141 try:
142 return text_contents.encode()
143 except UnicodeDecodeError:
144
145 return text_contents
146
147
149 cur_csig = self.get_csig()
150 try:
151 return cur_csig != prev_ni.csig
152 except AttributeError:
153 return 1
154
156 """Because we're a Python value node and don't have a real
157 timestamp, we get to ignore the calculator and just use the
158 value contents."""
159 try:
160 return self.ninfo.csig
161 except AttributeError:
162 pass
163 contents = self.get_contents()
164 self.get_ninfo().csig = contents
165 return contents
166
167
168
169
170
171
172