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