diff options
author | Joseph Brill <48932340+jcbrill@users.noreply.github.com> | 2024-10-07 21:02:24 (GMT) |
---|---|---|
committer | Joseph Brill <48932340+jcbrill@users.noreply.github.com> | 2024-10-07 21:02:24 (GMT) |
commit | a9a2f61db996f7fa090c136e2f763bb87373845c (patch) | |
tree | c460804f4daa11fb56c4ab30e50e21944894a401 /SCons | |
parent | 444f44c0f8caaf4508fdf31b58fd9647dca2618e (diff) | |
parent | fc36781173e80c99774284c653557c6cb9675c88 (diff) | |
download | SCons-a9a2f61db996f7fa090c136e2f763bb87373845c.zip SCons-a9a2f61db996f7fa090c136e2f763bb87373845c.tar.gz SCons-a9a2f61db996f7fa090c136e2f763bb87373845c.tar.bz2 |
Merge branch 'master' into jbrill-mscommon-debug
Diffstat (limited to 'SCons')
-rw-r--r-- | SCons/Script/SConsOptions.py | 73 |
1 files changed, 67 insertions, 6 deletions
diff --git a/SCons/Script/SConsOptions.py b/SCons/Script/SConsOptions.py index c9c7aa0..0853181 100644 --- a/SCons/Script/SConsOptions.py +++ b/SCons/Script/SConsOptions.py @@ -342,12 +342,13 @@ class SConsOptionParser(optparse.OptionParser): def _process_long_opt(self, rargs, values) -> None: """SCons-specific processing of long options. - This is copied directly from the normal - ``optparse._process_long_opt()`` method, except that, if configured - to do so, we catch the exception thrown when an unknown option - is encountered and just stick it back on the "leftover" arguments - for later (re-)processing. This is because we may see the option - definition later, while processing SConscript files. + This is copied directly from the normal Optparse + :meth:`~optparse.OptionParser._process_long_opt` method, except + that, if configured to do so, we catch the exception thrown + when an unknown option is encountered and just stick it back + on the "leftover" arguments for later (re-)processing. This is + because we may see the option definition later, while processing + SConscript files. """ arg = rargs.pop(0) @@ -414,6 +415,66 @@ class SConsOptionParser(optparse.OptionParser): option.process(opt, value, values, self) + + def _process_short_opts(self, rargs, values) -> None: + """SCons-specific processing of short options. + + This is copied directly from the normal Optparse + :meth:`~optparse.OptionParser._process_short_opts` method, except + that, if configured to do so, we catch the exception thrown + when an unknown option is encountered and just stick it back + on the "leftover" arguments for later (re-)processing. This is + because we may see the option definition later, while processing + SConscript files. + """ + arg = rargs.pop(0) + stop = False + i = 1 + for ch in arg[1:]: + opt = "-" + ch + option = self._short_opt.get(opt) + i += 1 # we have consumed a character + + try: + if not option: + raise optparse.BadOptionError(opt) + except optparse.BadOptionError: + # SCons addition: if requested, add unknown options to + # the "leftover arguments" list for later processing. + if self.preserve_unknown_options: + self.largs.append(arg) + return + raise + + if option.takes_value(): + # Any characters left in arg? Pretend they're the + # next arg, and stop consuming characters of arg. + if i < len(arg): + rargs.insert(0, arg[i:]) + stop = True + + nargs = option.nargs + if len(rargs) < nargs: + if nargs == 1: + self.error(_("%s option requires an argument") % opt) + else: + self.error(_("%s option requires %d arguments") + % (opt, nargs)) + elif nargs == 1: + value = rargs.pop(0) + else: + value = tuple(rargs[0:nargs]) + del rargs[0:nargs] + + else: # option doesn't take a value + value = None + + option.process(opt, value, values, self) + + if stop: + break + + def reparse_local_options(self) -> None: """Re-parse the leftover command-line options. |