Package SCons :: Package Node :: Module Python
[hide private]
[frames] | no frames]

Source Code for Module SCons.Node.Python

  1  """scons.Node.Python 
  2   
  3  Python nodes. 
  4   
  5  """ 
  6   
  7  # 
  8  # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 5110 2010/07/25 16:14:38 bdeegan" 
 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 built_value is not 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_text_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 ###TODO: something reasonable about universal newlines 98 contents = str(self.value) 99 for kid in self.children(None): 100 contents = contents + kid.get_contents() 101 return contents
102 103 get_contents = get_text_contents ###TODO should return 'bytes' value 104
105 - def changed_since_last_build(self, target, prev_ni):
106 cur_csig = self.get_csig() 107 try: 108 return cur_csig != prev_ni.csig 109 except AttributeError: 110 return 1
111
112 - def get_csig(self, calc=None):
113 """Because we're a Python value node and don't have a real 114 timestamp, we get to ignore the calculator and just use the 115 value contents.""" 116 try: 117 return self.ninfo.csig 118 except AttributeError: 119 pass 120 contents = self.get_contents() 121 self.get_ninfo().csig = contents 122 return contents
123 124 # Local Variables: 125 # tab-width:4 126 # indent-tabs-mode:nil 127 # End: 128 # vim: set expandtab tabstop=4 shiftwidth=4: 129