diff options
author | Dirk Baechle <dl9obn@darc.de> | 2014-02-08 21:33:19 (GMT) |
---|---|---|
committer | Dirk Baechle <dl9obn@darc.de> | 2014-02-08 21:33:19 (GMT) |
commit | 2990e8015515e764c786c819fc7ccef18f77a8e2 (patch) | |
tree | 7cc2b0c6892e3fd01898dba982c4715e64db1b9f /src/engine/SCons/Script | |
parent | 0eec585b4ffaad0c11a8d1cff541e9f4a50115ac (diff) | |
download | SCons-2990e8015515e764c786c819fc7ccef18f77a8e2.zip SCons-2990e8015515e764c786c819fc7ccef18f77a8e2.tar.gz SCons-2990e8015515e764c786c819fc7ccef18f77a8e2.tar.bz2 |
- fixed the handling of long options in the command-line parsing (#2929)
Diffstat (limited to 'src/engine/SCons/Script')
-rw-r--r-- | src/engine/SCons/Script/SConsOptions.py | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/src/engine/SCons/Script/SConsOptions.py b/src/engine/SCons/Script/SConsOptions.py index 62033ba..d7262a9 100644 --- a/src/engine/SCons/Script/SConsOptions.py +++ b/src/engine/SCons/Script/SConsOptions.py @@ -337,6 +337,71 @@ class SConsOptionParser(optparse.OptionParser): option.process(opt, value, values, self) + def reparse_local_options(self): + """ + Re-parse the leftover command-line options stored + in self.largs, so that any value overridden on the + command line is immediately available if the user turns + around and does a GetOption() right away. + + We mimic the processing of the single args + in the original OptionParser._process_args(), but here we + allow exact matches for long-opts only (no partial + argument names!). + + Else, this would lead to problems in add_local_option() + below. When called from there, we try to reparse the + command-line arguments that + 1. haven't been processed so far (self.largs), but + 2. are possibly not added to the list of options yet. + + So, when we only have a value for "--myargument" yet, + a command-line argument of "--myarg=test" would set it. + Responsible for this behaviour is the method + _match_long_opt(), which allows for partial matches of + the option name, as long as the common prefix appears to + be unique. + This would lead to further confusion, because we might want + to add another option "--myarg" later on (see issue #2929). + + """ + rargs = [] + largs_restore = [] + # Loop over all remaining arguments + skip = False + for l in self.largs: + if skip: + # Accept all remaining arguments as they are + largs_restore.append(l) + else: + if len(l) > 2 and l[0:2] == "--": + # Check long option + lopt = (l,) + if "=" in l: + # Split into option and value + lopt = l.split("=", 1) + + if lopt[0] in self._long_opt: + # Argument is already known + rargs.append('='.join(lopt)) + else: + # Not known yet, so reject for now + largs_restore.append('='.join(lopt)) + else: + if l == "--" or l == "-": + # Stop normal processing and don't + # process the rest of the command-line opts + largs_restore.append(l) + skip = True + else: + rargs.append(l) + + # Parse the filtered list + self.parse_args(rargs, self.values) + # Restore the list of remaining arguments for the + # next call of AddOption/add_local_option... + self.largs = self.largs + largs_restore + def add_local_option(self, *args, **kw): """ Adds a local option to the parser. @@ -364,7 +429,7 @@ class SConsOptionParser(optparse.OptionParser): # available if the user turns around and does a GetOption() # right away. setattr(self.values.__defaults__, result.dest, result.default) - self.parse_args(self.largs, self.values) + self.reparse_local_options() return result |