You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
5.1 KiB

6 years ago
  1. """scons.Node.Alias
  2. Alias nodes.
  3. This creates a hash of global Aliases (dummy targets).
  4. """
  5. #
  6. # Copyright (c) 2001 - 2017 The SCons Foundation
  7. #
  8. # Permission is hereby granted, free of charge, to any person obtaining
  9. # a copy of this software and associated documentation files (the
  10. # "Software"), to deal in the Software without restriction, including
  11. # without limitation the rights to use, copy, modify, merge, publish,
  12. # distribute, sublicense, and/or sell copies of the Software, and to
  13. # permit persons to whom the Software is furnished to do so, subject to
  14. # the following conditions:
  15. #
  16. # The above copyright notice and this permission notice shall be included
  17. # in all copies or substantial portions of the Software.
  18. #
  19. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  20. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  21. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. #
  27. __revision__ = "src/engine/SCons/Node/Alias.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  28. import collections
  29. import SCons.Errors
  30. import SCons.Node
  31. import SCons.Util
  32. class AliasNameSpace(collections.UserDict):
  33. def Alias(self, name, **kw):
  34. if isinstance(name, SCons.Node.Alias.Alias):
  35. return name
  36. try:
  37. a = self[name]
  38. except KeyError:
  39. a = SCons.Node.Alias.Alias(name, **kw)
  40. self[name] = a
  41. return a
  42. def lookup(self, name, **kw):
  43. try:
  44. return self[name]
  45. except KeyError:
  46. return None
  47. class AliasNodeInfo(SCons.Node.NodeInfoBase):
  48. __slots__ = ('csig',)
  49. current_version_id = 2
  50. field_list = ['csig']
  51. def str_to_node(self, s):
  52. return default_ans.Alias(s)
  53. def __getstate__(self):
  54. """
  55. Return all fields that shall be pickled. Walk the slots in the class
  56. hierarchy and add those to the state dictionary. If a '__dict__' slot is
  57. available, copy all entries to the dictionary. Also include the version
  58. id, which is fixed for all instances of a class.
  59. """
  60. state = getattr(self, '__dict__', {}).copy()
  61. for obj in type(self).mro():
  62. for name in getattr(obj,'__slots__',()):
  63. if hasattr(self, name):
  64. state[name] = getattr(self, name)
  65. state['_version_id'] = self.current_version_id
  66. try:
  67. del state['__weakref__']
  68. except KeyError:
  69. pass
  70. return state
  71. def __setstate__(self, state):
  72. """
  73. Restore the attributes from a pickled state.
  74. """
  75. # TODO check or discard version
  76. del state['_version_id']
  77. for key, value in state.items():
  78. if key not in ('__weakref__',):
  79. setattr(self, key, value)
  80. class AliasBuildInfo(SCons.Node.BuildInfoBase):
  81. __slots__ = ()
  82. current_version_id = 2
  83. class Alias(SCons.Node.Node):
  84. NodeInfo = AliasNodeInfo
  85. BuildInfo = AliasBuildInfo
  86. def __init__(self, name):
  87. SCons.Node.Node.__init__(self)
  88. self.name = name
  89. self.changed_since_last_build = 1
  90. self.store_info = 0
  91. def str_for_display(self):
  92. return '"' + self.__str__() + '"'
  93. def __str__(self):
  94. return self.name
  95. def make_ready(self):
  96. self.get_csig()
  97. really_build = SCons.Node.Node.build
  98. is_up_to_date = SCons.Node.Node.children_are_up_to_date
  99. def is_under(self, dir):
  100. # Make Alias nodes get built regardless of
  101. # what directory scons was run from. Alias nodes
  102. # are outside the filesystem:
  103. return 1
  104. def get_contents(self):
  105. """The contents of an alias is the concatenation
  106. of the content signatures of all its sources."""
  107. childsigs = [n.get_csig() for n in self.children()]
  108. return ''.join(childsigs)
  109. def sconsign(self):
  110. """An Alias is not recorded in .sconsign files"""
  111. pass
  112. #
  113. #
  114. #
  115. def build(self):
  116. """A "builder" for aliases."""
  117. pass
  118. def convert(self):
  119. try: del self.builder
  120. except AttributeError: pass
  121. self.reset_executor()
  122. self.build = self.really_build
  123. def get_csig(self):
  124. """
  125. Generate a node's content signature, the digested signature
  126. of its content.
  127. node - the node
  128. cache - alternate node to use for the signature cache
  129. returns - the content signature
  130. """
  131. try:
  132. return self.ninfo.csig
  133. except AttributeError:
  134. pass
  135. contents = self.get_contents()
  136. csig = SCons.Util.MD5signature(contents)
  137. self.get_ninfo().csig = csig
  138. return csig
  139. default_ans = AliasNameSpace()
  140. SCons.Node.arg2nodes_lookups.append(default_ans.lookup)
  141. # Local Variables:
  142. # tab-width:4
  143. # indent-tabs-mode:nil
  144. # End:
  145. # vim: set expandtab tabstop=4 shiftwidth=4: