diff options
author | Steven Knight <knight@baldmt.com> | 2003-04-30 15:35:30 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2003-04-30 15:35:30 (GMT) |
commit | 212d77d88aa4374ef13f2e6bc7edf3395ac9736c (patch) | |
tree | 464ca9fd18866613629e2381dfb6b93190a5e2e6 /src | |
parent | 7ff542f3fb5b361087ef2738a82b5d849e005d45 (diff) | |
download | SCons-212d77d88aa4374ef13f2e6bc7edf3395ac9736c.zip SCons-212d77d88aa4374ef13f2e6bc7edf3395ac9736c.tar.gz SCons-212d77d88aa4374ef13f2e6bc7edf3395ac9736c.tar.bz2 |
Provide uniform access to (some) command-line options. (Anthony Roach)
Diffstat (limited to 'src')
-rw-r--r-- | src/CHANGES.txt | 6 | ||||
-rw-r--r-- | src/RELEASE.txt | 6 | ||||
-rw-r--r-- | src/engine/SCons/Script/SConscript.py | 29 | ||||
-rw-r--r-- | src/engine/SCons/Script/__init__.py | 81 | ||||
-rw-r--r-- | src/engine/SCons/Sig/__init__.py | 4 |
5 files changed, 94 insertions, 32 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 04afab8..f6bdee0 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -90,6 +90,12 @@ RELEASE 0.14 - XXX - Fix an undefined exitvalmap on Win32 systems. + - Support new SetOption() and GetOption() functions for setting + various command-line options from with an SConscript file. + + - Deprecate the old SetJobs() and GetJobs() functions in favor of + using the new generic {Set,Get}Option() functions. + From David Snopek: - Contribute the "Autoscons" code for Autoconf-like checking for diff --git a/src/RELEASE.txt b/src/RELEASE.txt index db275b7..e8d4b37 100644 --- a/src/RELEASE.txt +++ b/src/RELEASE.txt @@ -45,6 +45,12 @@ RELEASE 0.14 - XXX file, you may need to modify the module to make the previously global variables available to your Export() or SConscript() call. + - The SetJobs() and GetJobs() functions have been deprecated. + Their new equivalents are: + + SetOption('num_jobs', num) + GetOption('num_jobs') + Please note the following important changes since release 0.11: - The default behavior of SCons is now to change to the directory in diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py index e3da64f..6b28b92 100644 --- a/src/engine/SCons/Script/SConscript.py +++ b/src/engine/SCons/Script/SConscript.py @@ -443,17 +443,18 @@ def EnsurePythonVersion(major, minor): sys.exit(2) def GetJobs(): - return SCons.Script.get_num_jobs(SCons.Script.options) + SCons.Warnings.warn(SCons.Warnings.DeprecatedWarning, + "The GetJobs() function has been deprecated;\n" +\ + "\tuse GetOption('num_jobs') instead.") + return GetOption('num_jobs') + def SetJobs(num): - try: - tmp = int(num) - if tmp < 1: - raise ValueError - SCons.Script.num_jobs = tmp - except ValueError, x: - raise SCons.Errors.UserError, "A positive integer is required: %s"%repr(num) - + SCons.Warnings.warn(SCons.Warnings.DeprecatedWarning, + "The SetJobs() function has been deprecated;\n" +\ + "\tuse SetOption('num_jobs', num) instead.") + SetOption('num_jobs', num) + def Clean(target, files): if not isinstance(target, SCons.Node.Node): target = SCons.Node.FS.default_fs.Entry(target, create=1) @@ -493,6 +494,12 @@ def Alias(name): alias = SCons.Node.Alias.default_ans.Alias(name) return alias +def SetOption(name, value): + SCons.Script.ssoptions.set(name, value) + +def GetOption(name): + return SCons.Script.ssoptions.get(name) + def BuildDefaultGlobals(): """ Create a dictionary containing all the default globals for @@ -504,6 +511,7 @@ def BuildDefaultGlobals(): globals['Action'] = SCons.Action.Action globals['AddPostAction'] = AddPostAction globals['AddPreAction'] = AddPreAction + globals['Alias'] = Alias globals['ARGUMENTS'] = arguments globals['BuildDir'] = BuildDir globals['Builder'] = SCons.Builder.Builder @@ -524,6 +532,7 @@ def BuildDefaultGlobals(): globals['GetCommandHandler'] = SCons.Action.GetCommandHandler globals['GetJobs'] = GetJobs globals['GetLaunchDir'] = GetLaunchDir + globals['GetOption'] = GetOption globals['Help'] = Help globals['Import'] = Import globals['Library'] = SCons.Defaults.StaticLibrary @@ -543,6 +552,7 @@ def BuildDefaultGlobals(): globals['SetCommandHandler'] = SCons.Action.SetCommandHandler globals['SetContentSignatureType'] = SetContentSignatureType globals['SetJobs'] = SetJobs + globals['SetOption'] = SetOption globals['SharedLibrary'] = SCons.Defaults.SharedLibrary globals['SharedObject'] = SCons.Defaults.SharedObject globals['SourceSignatures'] = SourceSignatures @@ -552,5 +562,4 @@ def BuildDefaultGlobals(): globals['TargetSignatures'] = TargetSignatures globals['Tool'] = SCons.Tool.Tool globals['WhereIs'] = SCons.Util.WhereIs - globals['Alias'] = Alias return globals diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index d67b949..a1a54e6 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -216,7 +216,7 @@ command_time = 0 exit_status = 0 # exit status, assume success by default profiling = 0 repositories = [] -sig_module = None +sig_module = SCons.Sig.default_module num_jobs = 1 # this is modifed by SConscript.SetJobs() # Exceptions for this module @@ -225,12 +225,6 @@ class PrintHelp(Exception): # utility functions -def get_num_jobs(options): - if hasattr(options, 'num_jobs'): - return options.num_jobs - else: - return num_jobs - def get_all_children(node): return node.all_children(None) def get_derived_children(node): @@ -433,7 +427,7 @@ class OptParser(OptionParser): help="Ignored for compatibility.") self.add_option('-c', '--clean', '--remove', action="store_true", - default=0, dest="clean", + dest="clean", help="Remove specified targets and dependencies.") self.add_option('-C', '--directory', type="string", action = "append", @@ -507,7 +501,7 @@ class OptParser(OptionParser): dest='include_dir', metavar="DIRECTORY", help="Search DIRECTORY for imported Python modules.") - self.add_option('--implicit-cache', action="store_true", default=0, + self.add_option('--implicit-cache', action="store_true", dest='implicit_cache', help="Cache implicit dependencies") @@ -650,6 +644,53 @@ class OptParser(OptionParser): opt.implicit_cache = 1 return opt, arglist +class SConscriptSettableOptions: + """This class wraps an OptParser instance and provides + uniform access to options that can be either set on the command + line or from a SConscript file. A value specified on the command + line always overrides a value set in a SConscript file. + Not all command line options are SConscript settable, and the ones + that are must be explicitly added to settable dictionary and optionally + validated and coerced in the set() method.""" + + def __init__(self, options): + self.options = options + + # This dictionary stores the defaults for all the SConscript + # settable options, as well as indicating which options + # are SConscript settable. + self.settable = {'num_jobs':1, + 'max_drift':SCons.Sig.default_max_drift, + 'implicit_cache':0, + 'clean':0} + + def get(self, name): + if not self.settable.has_key(name): + raise SCons.Error.UserError, "This option is not settable from a SConscript file: %s"%name + if hasattr(self.options, name) and getattr(self.options, name) is not None: + return getattr(self.options, name) + else: + return self.settable[name] + + def set(self, name, value): + if not self.settable.has_key(name): + raise SCons.Error.UserError, "This option is not settable from a SConscript file: %s"%name + + if name == 'num_jobs': + try: + value = int(value) + if value < 1: + raise ValueError + except ValueError, x: + raise SCons.Errors.UserError, "A positive integer is required: %s"%repr(value) + elif name == 'max_drift': + try: + value = int(value) + except ValueError, x: + raise SCons.Errors.UserError, "An integer is required: %s"%repr(value) + + self.settable[name] = value + def _main(): targets = [] @@ -666,8 +707,9 @@ def _main(): # it's OK if there's no SCONSFLAGS pass parser = OptParser() - global options + global options, ssoptions options, args = parser.parse_args(all_args) + ssoptions = SConscriptSettableOptions(options) if options.help_msg: def raisePrintHelp(text): @@ -808,6 +850,10 @@ def _main(): parser.print_help(sys.stdout) sys.exit(0) + # Now that we've read the SConscripts we can set the options + # that are SConscript settable: + SCons.Node.implicit_cache = ssoptions.get('implicit_cache') + if target_top: target_top = SCons.Node.FS.default_fs.Dir(target_top) @@ -865,7 +911,7 @@ def _main(): if options.question: task_class = QuestionTask try: - if options.clean: + if ssoptions.get('clean'): task_class = CleanTask class CleanCalculator: def bsig(self, node): @@ -881,15 +927,8 @@ def _main(): pass if not calc: - if options.max_drift is not None: - if sig_module is not None: - SCons.Sig.default_calc = SCons.Sig.Calculator(module=sig_module, - max_drift=options.max_drift) - else: - SCons.Sig.default_calc = SCons.Sig.Calculator(max_drift=options.max_drift) - elif sig_module is not None: - SCons.Sig.default_calc = SCons.Sig.Calculator(module=sig_module) - + SCons.Sig.default_calc = SCons.Sig.Calculator(module=sig_module, + max_drift=ssoptions.get('max_drift')) calc = SCons.Sig.default_calc if options.random: @@ -910,7 +949,7 @@ def _main(): display("scons: Building targets ...") taskmaster = SCons.Taskmaster.Taskmaster(nodes, task_class, calc, order) - jobs = SCons.Job.Jobs(get_num_jobs(options), taskmaster) + jobs = SCons.Job.Jobs(ssoptions.get('num_jobs'), taskmaster) try: jobs.run() diff --git a/src/engine/SCons/Sig/__init__.py b/src/engine/SCons/Sig/__init__.py index 196d065..cd6fe7e 100644 --- a/src/engine/SCons/Sig/__init__.py +++ b/src/engine/SCons/Sig/__init__.py @@ -44,6 +44,8 @@ except ImportError: import TimeStamp default_module = TimeStamp +default_max_drift = 2*24*60*60 + #XXX Get rid of the global array so this becomes re-entrant. sig_files = [] @@ -237,7 +239,7 @@ class Calculator: for the build engine. """ - def __init__(self, module=default_module, max_drift=2*24*60*60): + def __init__(self, module=default_module, max_drift=default_max_drift): """ Initialize the calculator. |