Add some documentation to the SCons-version-switching hack
[senf.git] / scons / scons-1.2.0 / engine / SCons / Node / Python.py
1 """scons.Node.Python
2
3 Python nodes.
4
5 """
6
7 #
8 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
9 #
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:
17 #
18 # The above copyright notice and this permission notice shall be included
19 # in all copies or substantial portions of the Software.
20 #
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.
28 #
29
30 __revision__ = "src/engine/SCons/Node/Python.py 3842 2008/12/20 22:59:52 scons"
31
32 import SCons.Node
33
34 class ValueNodeInfo(SCons.Node.NodeInfoBase):
35     current_version_id = 1
36
37     field_list = ['csig']
38
39     def str_to_node(self, s):
40         return Value(s)
41
42 class ValueBuildInfo(SCons.Node.BuildInfoBase):
43     current_version_id = 1
44
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.
48     """
49
50     NodeInfo = ValueNodeInfo
51     BuildInfo = ValueBuildInfo
52
53     def __init__(self, value, built_value=None):
54         SCons.Node.Node.__init__(self)
55         self.value = value
56         if not built_value is None:
57             self.built_value = built_value
58
59     def str_for_display(self):
60         return repr(self.value)
61
62     def __str__(self):
63         return str(self.value)
64
65     def make_ready(self):
66         self.get_csig()
67
68     def build(self, **kw):
69         if not hasattr(self, 'built_value'):
70             apply (SCons.Node.Node.build, (self,), kw)
71
72     is_up_to_date = SCons.Node.Node.children_are_up_to_date
73
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:
78         return 1
79
80     def write(self, built_value):
81         """Set the value of the node."""
82         self.built_value = built_value
83
84     def read(self):
85         """Return the value. If necessary, the value is built."""
86         self.build()
87         if not hasattr(self, 'built_value'):
88             self.built_value = self.value
89         return self.built_value
90
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()
100         return contents
101
102     def changed_since_last_build(self, target, prev_ni):
103         cur_csig = self.get_csig()
104         try:
105             return cur_csig != prev_ni.csig
106         except AttributeError:
107             return 1
108
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
112         value contents."""
113         try:
114             return self.ninfo.csig
115         except AttributeError:
116             pass
117         contents = self.get_contents()
118         self.get_ninfo().csig = contents
119         return contents