Package SCons :: Package Script
[hide private]
[frames] | no frames]

Source Code for Package SCons.Script

  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 - 2019 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 3a41ed6b288cee8d085373ad7fa02894e1903864 2019-01-23 17:30:35 bdeegan" 
 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.Platform 
 85  import SCons.Platform.virtualenv 
 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  Virtualenv              = SCons.Platform.virtualenv.Virtualenv 
154  Return                  = _SConscript.Return 
155  Scanner                 = SCons.Scanner.Base 
156  Tool                    = SCons.Tool.Tool 
157  WhereIs                 = SCons.Util.WhereIs 
158   
159  # 
160  BoolVariable            = SCons.Variables.BoolVariable 
161  EnumVariable            = SCons.Variables.EnumVariable 
162  ListVariable            = SCons.Variables.ListVariable 
163  PackageVariable         = SCons.Variables.PackageVariable 
164  PathVariable            = SCons.Variables.PathVariable 
165   
166   
167  # Action factories. 
168  Chmod                   = SCons.Defaults.Chmod 
169  Copy                    = SCons.Defaults.Copy 
170  Delete                  = SCons.Defaults.Delete 
171  Mkdir                   = SCons.Defaults.Mkdir 
172  Move                    = SCons.Defaults.Move 
173  Touch                   = SCons.Defaults.Touch 
174   
175  # Pre-made, public scanners. 
176  CScanner                = SCons.Tool.CScanner 
177  DScanner                = SCons.Tool.DScanner 
178  DirScanner              = SCons.Defaults.DirScanner 
179  ProgramScanner          = SCons.Tool.ProgramScanner 
180  SourceFileScanner       = SCons.Tool.SourceFileScanner 
181   
182  # Functions we might still convert to Environment methods. 
183  CScan                   = SCons.Defaults.CScan 
184  DefaultEnvironment      = SCons.Defaults.DefaultEnvironment 
185   
186  # Other variables we provide. 
187 -class TargetList(collections.UserList):
188 - def _do_nothing(self, *args, **kw):
189 pass
190 - def _add_Default(self, list):
191 self.extend(list)
192 - def _clear(self):
193 del self[:]
194 195 ARGUMENTS = {} 196 ARGLIST = [] 197 BUILD_TARGETS = TargetList() 198 COMMAND_LINE_TARGETS = [] 199 DEFAULT_TARGETS = [] 200 201 # BUILD_TARGETS can be modified in the SConscript files. If so, we 202 # want to treat the modified BUILD_TARGETS list as if they specified 203 # targets on the command line. To do that, though, we need to know if 204 # BUILD_TARGETS was modified through "official" APIs or by hand. We do 205 # this by updating two lists in parallel, the documented BUILD_TARGETS 206 # list, above, and this internal _build_plus_default targets list which 207 # should only have "official" API changes. Then Script/Main.py can 208 # compare these two afterwards to figure out if the user added their 209 # own targets to BUILD_TARGETS. 210 _build_plus_default = TargetList() 211
212 -def _Add_Arguments(alist):
213 for arg in alist: 214 a, b = arg.split('=', 1) 215 ARGUMENTS[a] = b 216 ARGLIST.append((a, b))
217
218 -def _Add_Targets(tlist):
219 if tlist: 220 COMMAND_LINE_TARGETS.extend(tlist) 221 BUILD_TARGETS.extend(tlist) 222 BUILD_TARGETS._add_Default = BUILD_TARGETS._do_nothing 223 BUILD_TARGETS._clear = BUILD_TARGETS._do_nothing 224 _build_plus_default.extend(tlist) 225 _build_plus_default._add_Default = _build_plus_default._do_nothing 226 _build_plus_default._clear = _build_plus_default._do_nothing
227
228 -def _Set_Default_Targets_Has_Been_Called(d, fs):
229 return DEFAULT_TARGETS
230
231 -def _Set_Default_Targets_Has_Not_Been_Called(d, fs):
232 if d is None: 233 d = [fs.Dir('.')] 234 return d
235 236 _Get_Default_Targets = _Set_Default_Targets_Has_Not_Been_Called 237
238 -def _Set_Default_Targets(env, tlist):
239 global DEFAULT_TARGETS 240 global _Get_Default_Targets 241 _Get_Default_Targets = _Set_Default_Targets_Has_Been_Called 242 for t in tlist: 243 if t is None: 244 # Delete the elements from the list in-place, don't 245 # reassign an empty list to DEFAULT_TARGETS, so that the 246 # variables will still point to the same object we point to. 247 del DEFAULT_TARGETS[:] 248 BUILD_TARGETS._clear() 249 _build_plus_default._clear() 250 elif isinstance(t, SCons.Node.Node): 251 DEFAULT_TARGETS.append(t) 252 BUILD_TARGETS._add_Default([t]) 253 _build_plus_default._add_Default([t]) 254 else: 255 nodes = env.arg2nodes(t, env.fs.Entry) 256 DEFAULT_TARGETS.extend(nodes) 257 BUILD_TARGETS._add_Default(nodes) 258 _build_plus_default._add_Default(nodes)
259 260 # 261 help_text = None 262
263 -def HelpFunction(text, append=False):
264 global help_text 265 if help_text is None: 266 if append: 267 s = StringIO() 268 PrintHelp(s) 269 help_text = s.getvalue() 270 s.close() 271 else: 272 help_text = "" 273 274 help_text= help_text + text
275 276 277 # 278 # Will be non-zero if we are reading an SConscript file. 279 sconscript_reading = 0 280 281 _no_missing_sconscript = False 282 _warn_missing_sconscript_deprecated = True 283
284 -def set_missing_sconscript_error(flag=1):
285 """Set behavior on missing file in SConscript() call. Returns previous value""" 286 global _no_missing_sconscript 287 old = _no_missing_sconscript 288 _no_missing_sconscript = flag 289 return old
290 291 #
292 -def Variables(files=[], args=ARGUMENTS):
293 return SCons.Variables.Variables(files, args)
294 295 296 # The list of global functions to add to the SConscript name space 297 # that end up calling corresponding methods or Builders in the 298 # DefaultEnvironment(). 299 GlobalDefaultEnvironmentFunctions = [ 300 # Methods from the SConsEnvironment class, above. 301 'Default', 302 'EnsurePythonVersion', 303 'EnsureSConsVersion', 304 'Exit', 305 'Export', 306 'GetLaunchDir', 307 'Help', 308 'Import', 309 #'SConscript', is handled separately, below. 310 'SConscriptChdir', 311 312 # Methods from the Environment.Base class. 313 'AddPostAction', 314 'AddPreAction', 315 'Alias', 316 'AlwaysBuild', 317 'BuildDir', 318 'CacheDir', 319 'Clean', 320 #The Command() method is handled separately, below. 321 'Decider', 322 'Depends', 323 'Dir', 324 'NoClean', 325 'NoCache', 326 'Entry', 327 'Execute', 328 'File', 329 'FindFile', 330 'FindInstalledFiles', 331 'FindSourceFiles', 332 'Flatten', 333 'GetBuildPath', 334 'Glob', 335 'Ignore', 336 'Install', 337 'InstallAs', 338 'InstallVersionedLib', 339 'Literal', 340 'Local', 341 'ParseDepends', 342 'Precious', 343 'PyPackageDir', 344 'Repository', 345 'Requires', 346 'SConsignFile', 347 'SideEffect', 348 'SourceCode', 349 'SourceSignatures', 350 'Split', 351 'Tag', 352 'TargetSignatures', 353 'Value', 354 'VariantDir', 355 ] 356 357 GlobalDefaultBuilders = [ 358 # Supported builders. 359 'CFile', 360 'CXXFile', 361 'DVI', 362 'Jar', 363 'Java', 364 'JavaH', 365 'Library', 366 'LoadableModule', 367 'M4', 368 'MSVSProject', 369 'Object', 370 'PCH', 371 'PDF', 372 'PostScript', 373 'Program', 374 'RES', 375 'RMIC', 376 'SharedLibrary', 377 'SharedObject', 378 'StaticLibrary', 379 'StaticObject', 380 'Substfile', 381 'Tar', 382 'Textfile', 383 'TypeLibrary', 384 'Zip', 385 'Package', 386 ] 387 388 for name in GlobalDefaultEnvironmentFunctions + GlobalDefaultBuilders: 389 exec ("%s = _SConscript.DefaultEnvironmentCall(%s)" % (name, repr(name))) 390 del name 391 392 # There are a handful of variables that used to live in the 393 # Script/SConscript.py module that some SConscript files out there were 394 # accessing directly as SCons.Script.SConscript.*. The problem is that 395 # "SConscript" in this namespace is no longer a module, it's a global 396 # function call--or more precisely, an object that implements a global 397 # function call through the default Environment. Nevertheless, we can 398 # maintain backwards compatibility for SConscripts that were reaching in 399 # this way by hanging some attributes off the "SConscript" object here. 400 SConscript = _SConscript.DefaultEnvironmentCall('SConscript') 401 402 # Make SConscript look enough like the module it used to be so 403 # that pychecker doesn't barf. 404 SConscript.__name__ = 'SConscript' 405 406 SConscript.Arguments = ARGUMENTS 407 SConscript.ArgList = ARGLIST 408 SConscript.BuildTargets = BUILD_TARGETS 409 SConscript.CommandLineTargets = COMMAND_LINE_TARGETS 410 SConscript.DefaultTargets = DEFAULT_TARGETS 411 412 # The global Command() function must be handled differently than the 413 # global functions for other construction environment methods because 414 # we want people to be able to use Actions that must expand $TARGET 415 # and $SOURCE later, when (and if) the Action is invoked to build 416 # the target(s). We do this with the subst=1 argument, which creates 417 # a DefaultEnvironmentCall instance that wraps up a normal default 418 # construction environment that performs variable substitution, not a 419 # proxy that doesn't. 420 # 421 # There's a flaw here, though, because any other $-variables on a command 422 # line will *also* be expanded, each to a null string, but that should 423 # only be a problem in the unusual case where someone was passing a '$' 424 # on a command line and *expected* the $ to get through to the shell 425 # because they were calling Command() and not env.Command()... This is 426 # unlikely enough that we're going to leave this as is and cross that 427 # bridge if someone actually comes to it. 428 Command = _SConscript.DefaultEnvironmentCall('Command', subst=1) 429 430 # Local Variables: 431 # tab-width:4 432 # indent-tabs-mode:nil 433 # End: 434 # vim: set expandtab tabstop=4 shiftwidth=4: 435