8 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
10 # Permission is hereby granted, free of charge, to any person obtaining
11 # a copy of this software and associated documentation files (the
12 # "Software"), to deal in the Software without restriction, including
13 # without limitation the rights to use, copy, modify, merge, publish,
14 # distribute, sublicense, and/or sell copies of the Software, and to
15 # permit persons to whom the Software is furnished to do so, subject to
16 # the following conditions:
18 # The above copyright notice and this permission notice shall be included
19 # in all copies or substantial portions of the Software.
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
22 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
23 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 __revision__ = "src/engine/SCons/Node/Python.py 3842 2008/12/20 22:59:52 scons"
34 class ValueNodeInfo(SCons.Node.NodeInfoBase):
35 current_version_id = 1
39 def str_to_node(self, s):
42 class ValueBuildInfo(SCons.Node.BuildInfoBase):
43 current_version_id = 1
45 class Value(SCons.Node.Node):
46 """A class for Python variables, typically passed on the command line
47 or generated by a script, but not from a file or some other source.
50 NodeInfo = ValueNodeInfo
51 BuildInfo = ValueBuildInfo
53 def __init__(self, value, built_value=None):
54 SCons.Node.Node.__init__(self)
56 if not built_value is None:
57 self.built_value = built_value
59 def str_for_display(self):
60 return repr(self.value)
63 return str(self.value)
68 def build(self, **kw):
69 if not hasattr(self, 'built_value'):
70 apply (SCons.Node.Node.build, (self,), kw)
72 is_up_to_date = SCons.Node.Node.children_are_up_to_date
74 def is_under(self, dir):
75 # Make Value nodes get built regardless of
76 # what directory scons was run from. Value nodes
77 # are outside the filesystem:
80 def write(self, built_value):
81 """Set the value of the node."""
82 self.built_value = built_value
85 """Return the value. If necessary, the value is built."""
87 if not hasattr(self, 'built_value'):
88 self.built_value = self.value
89 return self.built_value
91 def get_contents(self):
92 """By the assumption that the node.built_value is a
93 deterministic product of the sources, the contents of a Value
94 are the concatenation of all the contents of its sources. As
95 the value need not be built when get_contents() is called, we
96 cannot use the actual node.built_value."""
97 contents = str(self.value)
98 for kid in self.children(None):
99 contents = contents + kid.get_contents()
102 def changed_since_last_build(self, target, prev_ni):
103 cur_csig = self.get_csig()
105 return cur_csig != prev_ni.csig
106 except AttributeError:
109 def get_csig(self, calc=None):
110 """Because we're a Python value node and don't have a real
111 timestamp, we get to ignore the calculator and just use the
114 return self.ninfo.csig
115 except AttributeError:
117 contents = self.get_contents()
118 self.get_ninfo().csig = contents