Skip to content

Commit

Permalink
Add a check for bad opts which are abbrev of good
Browse files Browse the repository at this point in the history
Adds a post-processing step called after sconscript processing
is done which checks if there are any leftover options. Previously,
some options would sneak through silently if they were an
abbreviation of another option added by AddOption.

Fixes SCons#3653

Signed-off-by: Mats Wichmann <mats@linux.com>
  • Loading branch information
mwichmann committed May 17, 2020
1 parent b62d1a5 commit ba41fc3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
definitions using a metaclass be written the same for Py2/Py3.
- Bump python_version_unsupported (and deprecated) to indicate 3.5
is lowest supported Python.
- Generate an error if AddOption uses an "abbreviation" for an option
string (e.g. via a user error) rather than swallowing silently (#3653)



Expand Down
1 change: 1 addition & 0 deletions SCons/Script/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ def _main(parser):
revert_io()
sys.stderr.write("scons: *** %s Stop.\n" % e)
sys.exit(2)
OptionsParser.cleanup()
global sconscript_time
sconscript_time = time.time() - start_time

Expand Down
14 changes: 14 additions & 0 deletions SCons/Script/SConsOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,20 @@ def add_local_option(self, *args, **kw):

return result

def cleanup(self):
"""If there are leftover unprocessed options, fail.
Unrecognized options are saved for later processing, since
a later AddOption might enable them. Although abbreviations
of AddOption option strings don't trigger a match, they
also can't trigger an error because of that. This method
provides a way sweep through is to catch those cases still left
when all sconscripts are read.
"""
xtra_args = [a for a in self.largs if a.startswith('--')]
if xtra_args:
self.error(_("no such option: %s") % " ".join(xtra_args))

class SConsIndentedHelpFormatter(optparse.IndentedHelpFormatter):
def format_usage(self, usage):
return "usage: %s\n" % usage
Expand Down
10 changes: 10 additions & 0 deletions test/AddOption/longopts.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
test.run('-Q -q . --myarg=helloworld',
stdout="myargument: gully\nmyarg: helloworld\n")

# Issue #3653: add a check for an abbreviation which never gets AddOption'd.
test.run('-Q -q --myargumen=helloworld', status=2,
stdout="myargument: gully\nmyarg: balla\n",
stderr="""\
usage: scons [OPTION] [TARGET] ...
SCons Error: no such option: --myargumen=helloworld
""")


test.pass_test()

# Local Variables:
Expand Down

0 comments on commit ba41fc3

Please sign in to comment.