PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/scons/scons-local-3.0.1/SCons/Script/__init__.py

https://gitlab.com/benbelga/muscleHPC
Python | 429 lines | 424 code | 0 blank | 5 comment | 0 complexity | 8df9163fc38ddaea8e929239bcdf496a MD5 | raw file
  1. """SCons.Script
  2. This file implements the main() function used by the scons script.
  3. Architecturally, this *is* the scons script, and will likely only be
  4. called from the external "scons" wrapper. Consequently, anything here
  5. should not be, or be considered, part of the build engine. If it's
  6. something that we expect other software to want to use, it should go in
  7. some other module. If it's specific to the "scons" script invocation,
  8. it goes here.
  9. """
  10. #
  11. # Copyright (c) 2001 - 2017 The SCons Foundation
  12. #
  13. # Permission is hereby granted, free of charge, to any person obtaining
  14. # a copy of this software and associated documentation files (the
  15. # "Software"), to deal in the Software without restriction, including
  16. # without limitation the rights to use, copy, modify, merge, publish,
  17. # distribute, sublicense, and/or sell copies of the Software, and to
  18. # permit persons to whom the Software is furnished to do so, subject to
  19. # the following conditions:
  20. #
  21. # The above copyright notice and this permission notice shall be included
  22. # in all copies or substantial portions of the Software.
  23. #
  24. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  25. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  26. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. #
  32. __revision__ = "src/engine/SCons/Script/__init__.py 74b2c53bc42290e911b334a6b44f187da698a668 2017/11/14 13:16:53 bdbaddog"
  33. import time
  34. start_time = time.time()
  35. import collections
  36. import os
  37. try:
  38. from StringIO import StringIO
  39. except ImportError:
  40. from io import StringIO
  41. import sys
  42. # Special chicken-and-egg handling of the "--debug=memoizer" flag:
  43. #
  44. # SCons.Memoize contains a metaclass implementation that affects how
  45. # the other classes are instantiated. The Memoizer may add shim methods
  46. # to classes that have methods that cache computed values in order to
  47. # count and report the hits and misses.
  48. #
  49. # If we wait to enable the Memoization until after we've parsed the
  50. # command line options normally, it will be too late, because the Memoizer
  51. # will have already analyzed the classes that it's Memoizing and decided
  52. # to not add the shims. So we use a special-case, up-front check for
  53. # the "--debug=memoizer" flag and enable Memoizer before we import any
  54. # of the other modules that use it.
  55. _args = sys.argv + os.environ.get('SCONSFLAGS', '').split()
  56. if "--debug=memoizer" in _args:
  57. import SCons.Memoize
  58. import SCons.Warnings
  59. try:
  60. SCons.Memoize.EnableMemoization()
  61. except SCons.Warnings.Warning:
  62. # Some warning was thrown. Arrange for it to be displayed
  63. # or not after warnings are configured.
  64. from . import Main
  65. exc_type, exc_value, tb = sys.exc_info()
  66. Main.delayed_warnings.append((exc_type, exc_value))
  67. del _args
  68. import SCons.Action
  69. import SCons.Builder
  70. import SCons.Environment
  71. import SCons.Node.FS
  72. import SCons.Options
  73. import SCons.Platform
  74. import SCons.Scanner
  75. import SCons.SConf
  76. import SCons.Subst
  77. import SCons.Tool
  78. import SCons.Util
  79. import SCons.Variables
  80. import SCons.Defaults
  81. from . import Main
  82. main = Main.main
  83. # The following are global class definitions and variables that used to
  84. # live directly in this module back before 0.96.90, when it contained
  85. # a lot of code. Some SConscript files in widely-distributed packages
  86. # (Blender is the specific example) actually reached into SCons.Script
  87. # directly to use some of these. Rather than break those SConscript
  88. # files, we're going to propagate these names into the SCons.Script
  89. # namespace here.
  90. #
  91. # Some of these are commented out because it's *really* unlikely anyone
  92. # used them, but we're going to leave the comment here to try to make
  93. # it obvious what to do if the situation arises.
  94. BuildTask = Main.BuildTask
  95. CleanTask = Main.CleanTask
  96. QuestionTask = Main.QuestionTask
  97. #PrintHelp = Main.PrintHelp
  98. #SConscriptSettableOptions = Main.SConscriptSettableOptions
  99. AddOption = Main.AddOption
  100. PrintHelp = Main.PrintHelp
  101. GetOption = Main.GetOption
  102. SetOption = Main.SetOption
  103. Progress = Main.Progress
  104. GetBuildFailures = Main.GetBuildFailures
  105. #keep_going_on_error = Main.keep_going_on_error
  106. #print_dtree = Main.print_dtree
  107. #print_explanations = Main.print_explanations
  108. #print_includes = Main.print_includes
  109. #print_objects = Main.print_objects
  110. #print_time = Main.print_time
  111. #print_tree = Main.print_tree
  112. #memory_stats = Main.memory_stats
  113. #ignore_errors = Main.ignore_errors
  114. #sconscript_time = Main.sconscript_time
  115. #command_time = Main.command_time
  116. #exit_status = Main.exit_status
  117. #profiling = Main.profiling
  118. #repositories = Main.repositories
  119. #
  120. from . import SConscript
  121. _SConscript = SConscript
  122. call_stack = _SConscript.call_stack
  123. #
  124. Action = SCons.Action.Action
  125. AddMethod = SCons.Util.AddMethod
  126. AllowSubstExceptions = SCons.Subst.SetAllowableExceptions
  127. Builder = SCons.Builder.Builder
  128. Configure = _SConscript.Configure
  129. Environment = SCons.Environment.Environment
  130. #OptParser = SCons.SConsOptions.OptParser
  131. FindPathDirs = SCons.Scanner.FindPathDirs
  132. Platform = SCons.Platform.Platform
  133. Return = _SConscript.Return
  134. Scanner = SCons.Scanner.Base
  135. Tool = SCons.Tool.Tool
  136. WhereIs = SCons.Util.WhereIs
  137. #
  138. BoolVariable = SCons.Variables.BoolVariable
  139. EnumVariable = SCons.Variables.EnumVariable
  140. ListVariable = SCons.Variables.ListVariable
  141. PackageVariable = SCons.Variables.PackageVariable
  142. PathVariable = SCons.Variables.PathVariable
  143. # Deprecated names that will go away some day.
  144. BoolOption = SCons.Options.BoolOption
  145. EnumOption = SCons.Options.EnumOption
  146. ListOption = SCons.Options.ListOption
  147. PackageOption = SCons.Options.PackageOption
  148. PathOption = SCons.Options.PathOption
  149. # Action factories.
  150. Chmod = SCons.Defaults.Chmod
  151. Copy = SCons.Defaults.Copy
  152. Delete = SCons.Defaults.Delete
  153. Mkdir = SCons.Defaults.Mkdir
  154. Move = SCons.Defaults.Move
  155. Touch = SCons.Defaults.Touch
  156. # Pre-made, public scanners.
  157. CScanner = SCons.Tool.CScanner
  158. DScanner = SCons.Tool.DScanner
  159. DirScanner = SCons.Defaults.DirScanner
  160. ProgramScanner = SCons.Tool.ProgramScanner
  161. SourceFileScanner = SCons.Tool.SourceFileScanner
  162. # Functions we might still convert to Environment methods.
  163. CScan = SCons.Defaults.CScan
  164. DefaultEnvironment = SCons.Defaults.DefaultEnvironment
  165. # Other variables we provide.
  166. class TargetList(collections.UserList):
  167. def _do_nothing(self, *args, **kw):
  168. pass
  169. def _add_Default(self, list):
  170. self.extend(list)
  171. def _clear(self):
  172. del self[:]
  173. ARGUMENTS = {}
  174. ARGLIST = []
  175. BUILD_TARGETS = TargetList()
  176. COMMAND_LINE_TARGETS = []
  177. DEFAULT_TARGETS = []
  178. # BUILD_TARGETS can be modified in the SConscript files. If so, we
  179. # want to treat the modified BUILD_TARGETS list as if they specified
  180. # targets on the command line. To do that, though, we need to know if
  181. # BUILD_TARGETS was modified through "official" APIs or by hand. We do
  182. # this by updating two lists in parallel, the documented BUILD_TARGETS
  183. # list, above, and this internal _build_plus_default targets list which
  184. # should only have "official" API changes. Then Script/Main.py can
  185. # compare these two afterwards to figure out if the user added their
  186. # own targets to BUILD_TARGETS.
  187. _build_plus_default = TargetList()
  188. def _Add_Arguments(alist):
  189. for arg in alist:
  190. a, b = arg.split('=', 1)
  191. ARGUMENTS[a] = b
  192. ARGLIST.append((a, b))
  193. def _Add_Targets(tlist):
  194. if tlist:
  195. COMMAND_LINE_TARGETS.extend(tlist)
  196. BUILD_TARGETS.extend(tlist)
  197. BUILD_TARGETS._add_Default = BUILD_TARGETS._do_nothing
  198. BUILD_TARGETS._clear = BUILD_TARGETS._do_nothing
  199. _build_plus_default.extend(tlist)
  200. _build_plus_default._add_Default = _build_plus_default._do_nothing
  201. _build_plus_default._clear = _build_plus_default._do_nothing
  202. def _Set_Default_Targets_Has_Been_Called(d, fs):
  203. return DEFAULT_TARGETS
  204. def _Set_Default_Targets_Has_Not_Been_Called(d, fs):
  205. if d is None:
  206. d = [fs.Dir('.')]
  207. return d
  208. _Get_Default_Targets = _Set_Default_Targets_Has_Not_Been_Called
  209. def _Set_Default_Targets(env, tlist):
  210. global DEFAULT_TARGETS
  211. global _Get_Default_Targets
  212. _Get_Default_Targets = _Set_Default_Targets_Has_Been_Called
  213. for t in tlist:
  214. if t is None:
  215. # Delete the elements from the list in-place, don't
  216. # reassign an empty list to DEFAULT_TARGETS, so that the
  217. # variables will still point to the same object we point to.
  218. del DEFAULT_TARGETS[:]
  219. BUILD_TARGETS._clear()
  220. _build_plus_default._clear()
  221. elif isinstance(t, SCons.Node.Node):
  222. DEFAULT_TARGETS.append(t)
  223. BUILD_TARGETS._add_Default([t])
  224. _build_plus_default._add_Default([t])
  225. else:
  226. nodes = env.arg2nodes(t, env.fs.Entry)
  227. DEFAULT_TARGETS.extend(nodes)
  228. BUILD_TARGETS._add_Default(nodes)
  229. _build_plus_default._add_Default(nodes)
  230. #
  231. help_text = None
  232. def HelpFunction(text, append=False):
  233. global help_text
  234. if help_text is None:
  235. if append:
  236. s = StringIO()
  237. PrintHelp(s)
  238. help_text = s.getvalue()
  239. s.close()
  240. else:
  241. help_text = ""
  242. help_text= help_text + text
  243. #
  244. # Will be non-zero if we are reading an SConscript file.
  245. sconscript_reading = 0
  246. #
  247. def Variables(files=[], args=ARGUMENTS):
  248. return SCons.Variables.Variables(files, args)
  249. def Options(files=[], args=ARGUMENTS):
  250. return SCons.Options.Options(files, args)
  251. # The list of global functions to add to the SConscript name space
  252. # that end up calling corresponding methods or Builders in the
  253. # DefaultEnvironment().
  254. GlobalDefaultEnvironmentFunctions = [
  255. # Methods from the SConsEnvironment class, above.
  256. 'Default',
  257. 'EnsurePythonVersion',
  258. 'EnsureSConsVersion',
  259. 'Exit',
  260. 'Export',
  261. 'GetLaunchDir',
  262. 'Help',
  263. 'Import',
  264. #'SConscript', is handled separately, below.
  265. 'SConscriptChdir',
  266. # Methods from the Environment.Base class.
  267. 'AddPostAction',
  268. 'AddPreAction',
  269. 'Alias',
  270. 'AlwaysBuild',
  271. 'BuildDir',
  272. 'CacheDir',
  273. 'Clean',
  274. #The Command() method is handled separately, below.
  275. 'Decider',
  276. 'Depends',
  277. 'Dir',
  278. 'NoClean',
  279. 'NoCache',
  280. 'Entry',
  281. 'Execute',
  282. 'File',
  283. 'FindFile',
  284. 'FindInstalledFiles',
  285. 'FindSourceFiles',
  286. 'Flatten',
  287. 'GetBuildPath',
  288. 'Glob',
  289. 'Ignore',
  290. 'Install',
  291. 'InstallAs',
  292. 'InstallVersionedLib',
  293. 'Literal',
  294. 'Local',
  295. 'ParseDepends',
  296. 'Precious',
  297. 'PyPackageDir',
  298. 'Repository',
  299. 'Requires',
  300. 'SConsignFile',
  301. 'SideEffect',
  302. 'SourceCode',
  303. 'SourceSignatures',
  304. 'Split',
  305. 'Tag',
  306. 'TargetSignatures',
  307. 'Value',
  308. 'VariantDir',
  309. ]
  310. GlobalDefaultBuilders = [
  311. # Supported builders.
  312. 'CFile',
  313. 'CXXFile',
  314. 'DVI',
  315. 'Jar',
  316. 'Java',
  317. 'JavaH',
  318. 'Library',
  319. 'LoadableModule',
  320. 'M4',
  321. 'MSVSProject',
  322. 'Object',
  323. 'PCH',
  324. 'PDF',
  325. 'PostScript',
  326. 'Program',
  327. 'RES',
  328. 'RMIC',
  329. 'SharedLibrary',
  330. 'SharedObject',
  331. 'StaticLibrary',
  332. 'StaticObject',
  333. 'Tar',
  334. 'TypeLibrary',
  335. 'Zip',
  336. 'Package',
  337. ]
  338. for name in GlobalDefaultEnvironmentFunctions + GlobalDefaultBuilders:
  339. exec ("%s = _SConscript.DefaultEnvironmentCall(%s)" % (name, repr(name)))
  340. del name
  341. # There are a handful of variables that used to live in the
  342. # Script/SConscript.py module that some SConscript files out there were
  343. # accessing directly as SCons.Script.SConscript.*. The problem is that
  344. # "SConscript" in this namespace is no longer a module, it's a global
  345. # function call--or more precisely, an object that implements a global
  346. # function call through the default Environment. Nevertheless, we can
  347. # maintain backwards compatibility for SConscripts that were reaching in
  348. # this way by hanging some attributes off the "SConscript" object here.
  349. SConscript = _SConscript.DefaultEnvironmentCall('SConscript')
  350. # Make SConscript look enough like the module it used to be so
  351. # that pychecker doesn't barf.
  352. SConscript.__name__ = 'SConscript'
  353. SConscript.Arguments = ARGUMENTS
  354. SConscript.ArgList = ARGLIST
  355. SConscript.BuildTargets = BUILD_TARGETS
  356. SConscript.CommandLineTargets = COMMAND_LINE_TARGETS
  357. SConscript.DefaultTargets = DEFAULT_TARGETS
  358. # The global Command() function must be handled differently than the
  359. # global functions for other construction environment methods because
  360. # we want people to be able to use Actions that must expand $TARGET
  361. # and $SOURCE later, when (and if) the Action is invoked to build
  362. # the target(s). We do this with the subst=1 argument, which creates
  363. # a DefaultEnvironmentCall instance that wraps up a normal default
  364. # construction environment that performs variable substitution, not a
  365. # proxy that doesn't.
  366. #
  367. # There's a flaw here, though, because any other $-variables on a command
  368. # line will *also* be expanded, each to a null string, but that should
  369. # only be a problem in the unusual case where someone was passing a '$'
  370. # on a command line and *expected* the $ to get through to the shell
  371. # because they were calling Command() and not env.Command()... This is
  372. # unlikely enough that we're going to leave this as is and cross that
  373. # bridge if someone actually comes to it.
  374. Command = _SConscript.DefaultEnvironmentCall('Command', subst=1)
  375. # Local Variables:
  376. # tab-width:4
  377. # indent-tabs-mode:nil
  378. # End:
  379. # vim: set expandtab tabstop=4 shiftwidth=4: