diff options
Diffstat (limited to 'src/engine/SCons/Script')
| -rw-r--r-- | src/engine/SCons/Script/Main.py | 25 | ||||
| -rw-r--r-- | src/engine/SCons/Script/SConsOptions.py | 69 | ||||
| -rw-r--r-- | src/engine/SCons/Script/__init__.py | 6 |
3 files changed, 85 insertions, 15 deletions
diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py index a3c0a51..a76165f 100644 --- a/src/engine/SCons/Script/Main.py +++ b/src/engine/SCons/Script/Main.py @@ -54,6 +54,7 @@ import traceback # 'lib', # 'scons-%d' % SCons.__version__)] + sys.path[1:] +import SCons.CacheDir import SCons.Debug import SCons.Defaults import SCons.Environment @@ -641,10 +642,15 @@ def _load_site_scons_dir(topdir, site_dir_name=None): SCons.Tool.DefaultToolpath.append(os.path.abspath(site_tools_dir)) def version_string(label, module): - fmt = "\t%s: v%s.%s, %s, by %s on %s\n" + version = module.__version__ + build = module.__build__ + if build: + if build[0] != '.': + build = '.' + build + version = version + build + fmt = "\t%s: v%s, %s, by %s on %s\n" return fmt % (label, - module.__version__, - module.__build__, + version, module.__date__, module.__developer__, module.__buildsys__) @@ -720,7 +726,7 @@ def _main(parser): # Now that we're in the top-level SConstruct directory, go ahead # and initialize the FS object that represents the file system, # and make it the build engine default. - fs = SCons.Node.FS.default_fs = SCons.Node.FS.FS() + fs = SCons.Node.FS.get_default_fs() for rep in options.repository: fs.Repository(rep) @@ -770,15 +776,14 @@ def _main(parser): if options.silent: SCons.Action.print_actions = None - if options.cache_debug: - fs.CacheDebugEnable(options.cache_debug) if options.cache_disable: - def disable(self): pass - fs.CacheDir = disable + SCons.CacheDir.CacheDir = SCons.Util.Null() + if options.cache_debug: + SCons.CacheDir.cache_debug = options.cache_debug if options.cache_force: - fs.cache_force = 1 + SCons.CacheDir.cache_force = True if options.cache_show: - fs.cache_show = 1 + SCons.CacheDir.cache_show = True if options.site_dir: _load_site_scons_dir(d, options.site_dir) diff --git a/src/engine/SCons/Script/SConsOptions.py b/src/engine/SCons/Script/SConsOptions.py index 053fff1..46ece27 100644 --- a/src/engine/SCons/Script/SConsOptions.py +++ b/src/engine/SCons/Script/SConsOptions.py @@ -166,6 +166,65 @@ class SConsValues(optparse.Values): self.__SConscript_settings__[name] = value +class SConsOption(optparse.Option): + def convert_value(self, opt, value): + if value is not None: + if self.nargs in (1, '?'): + return self.check_value(opt, value) + else: + return tuple(map(lambda v, o=opt, s=self: s.check_value(o, v), value)) + + def process(self, opt, value, values, parser): + + # First, convert the value(s) to the right type. Howl if any + # value(s) are bogus. + value = self.convert_value(opt, value) + + # And then take whatever action is expected of us. + # This is a separate method to make life easier for + # subclasses to add new actions. + return self.take_action( + self.action, self.dest, opt, value, values, parser) + + def _check_nargs_optional(self): + if self.nargs == '?' and self._short_opts: + fmt = "option %s: nargs='?' is incompatible with short options" + raise SCons.Errors.UserError, fmt % self._short_opts[0] + + try: + _orig_CONST_ACTIONS = optparse.Option.CONST_ACTIONS + + _orig_CHECK_METHODS = optparse.Option.CHECK_METHODS + + except AttributeError: + # optparse.Option had no CONST_ACTIONS before Python 2.5. + + _orig_CONST_ACTIONS = ("store_const",) + + def _check_const(self): + if self.action not in self.CONST_ACTIONS and self.const is not None: + raise OptionError( + "'const' must not be supplied for action %r" % self.action, + self) + + # optparse.Option collects its list of unbound check functions + # up front. This sucks because it means we can't just override + # the _check_const() function like a normal method, we have to + # actually replace it in the list. This seems to be the most + # straightforward way to do that. + + _orig_CHECK_METHODS = [optparse.Option._check_action, + optparse.Option._check_type, + optparse.Option._check_choice, + optparse.Option._check_dest, + _check_const, + optparse.Option._check_nargs, + optparse.Option._check_callback] + + CHECK_METHODS = _orig_CHECK_METHODS + [_check_nargs_optional] + + CONST_ACTIONS = _orig_CONST_ACTIONS + optparse.Option.TYPED_ACTIONS + class SConsOptionGroup(optparse.OptionGroup): """ A subclass for SCons-specific option groups. @@ -232,7 +291,12 @@ class SConsOptionParser(optparse.OptionParser): option = self._long_opt[opt] if option.takes_value(): nargs = option.nargs - if len(rargs) < nargs: + if nargs == '?': + if had_explicit_value: + value = rargs.pop(0) + else: + value = option.const + elif len(rargs) < nargs: if nargs == 1: self.error(_("%s option requires an argument") % opt) else: @@ -396,7 +460,8 @@ def Parser(version): formatter = SConsIndentedHelpFormatter(max_help_position=30) - op = SConsOptionParser(add_help_option=False, + op = SConsOptionParser(option_class=SConsOption, + add_help_option=False, formatter=formatter, usage="usage: scons [OPTION] [TARGET] ...",) diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index 8204c65..4010d80 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -296,6 +296,8 @@ GlobalDefaultEnvironmentFunctions = [ 'Execute', 'File', 'FindFile', + 'FindInstalledFiles', + 'FindSourceFiles', 'Flatten', 'GetBuildPath', 'Ignore', @@ -311,11 +313,9 @@ GlobalDefaultEnvironmentFunctions = [ 'SourceCode', 'SourceSignatures', 'Split', + 'Tag', 'TargetSignatures', 'Value', - 'Tag', - 'FindInstalledFiles', - 'FindSourceFiles', ] GlobalDefaultBuilders = [ |
