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