SCons.Node.Python

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 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 2725 2008/03/31 12:52:02 knight"
     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__(self):
     60          return repr(self.value)
     61
     62 -    def make_ready(self):
     63          self.get_csig()
     64
     65 -    def build(self, **kw):
     66          if not hasattr(self, 'built_value'):
     67              apply (SCons.Node.Node.build, (self,), kw)
     68
     69      is_up_to_date = SCons.Node.Node.children_are_up_to_date
     70
     71 -    def is_under(self, dir):
     72          # Make Value nodes get built regardless of
     73          # what directory scons was run from. Value nodes
     74          # are outside the filesystem:
     75          return 1
     76
     77 -    def write(self, built_value):
     78          """Set the value of the node."""
     79          self.built_value = built_value
     80
     81 -    def read(self):
     82          """Return the value. If necessary, the value is built."""
     83          self.build()
     84          if not hasattr(self, 'built_value'):
     85              self.built_value = self.value
     86          return self.built_value
     87
     88 -    def get_contents(self):
     89          """By the assumption that the node.built_value is a
     90          deterministic product of the sources, the contents of a Value
     91          are the concatenation of all the contents of its sources.  As
     92          the value need not be built when get_contents() is called, we
     93          cannot use the actual node.built_value."""
     94          contents = str(self.value)
     95          for kid in self.children(None):
     96              contents = contents + kid.get_contents()
     97          return contents
     98
     99 -    def changed_since_last_build(self, target, prev_ni):
    100          cur_csig = self.get_csig()
    101          try:
    102              return cur_csig != prev_ni.csig
    103          except AttributeError:
    104              return 1
    105
    106 -    def get_csig(self, calc=None):
    107          """Because we're a Python value node and don't have a real
    108          timestamp, we get to ignore the calculator and just use the
    109          value contents."""
    110          try:
    111              return self.ninfo.csig
    112          except AttributeError:
    113              pass
    114          contents = self.get_contents()
    115          self.get_ninfo().csig = contents
    116          return contents
    117