Skip to content

Fix AddOption handling of spaces#4841

Draft
mwichmann wants to merge 4 commits intoSCons:masterfrom
mwichmann:fix/addOption
Draft

Fix AddOption handling of spaces#4841
mwichmann wants to merge 4 commits intoSCons:masterfrom
mwichmann:fix/addOption

Conversation

@mwichmann
Copy link
Copy Markdown
Collaborator

@mwichmann mwichmann commented Mar 23, 2026

Fix handling of AddOption for option-arguments with spaces (when omitting the = sign and/or when an option takes multiple option-arguments). Arguments unknown at the time the first pass splits the command line into arguments and targets would put such arguments into targets, and they remained there even after the AddOption calls were seen.

This is the final piece of the work from PR #3799, which was previously closed but noted as to be done.

Resolves #2748, resolves #2805, resolves #2977

NOTE: currently marked as Draft for two reasons which need resolution:

  • The changes make SCons.Script.SConsOption.reparse_local_options unused. Should we get rid of that? (the referenced PR did propose to remove it)
  • Documentation has some "don't do that" warnings about the problem this PR attempts to address. Should those warnings be removed, or perhaps softened?

Contributor Checklist:

  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt and RELEASE.txt (and read the README.rst).
  • I have updated the appropriate documentation

Fix handling of AddOption for option-arguments with spaces
(when omitting the = sign and/or when an option takes multiple
option-arguments). Arguments unknown at the time the first pass splits
the command line into arguments and targets would put such arguments into
targets, and they remained there even after the AddOption calls were seen.

Signed-off-by: Mats Wichmann <mats@linux.com>
@mwichmann mwichmann added the args_and_options options processing, arguments, get/setoption and their relationshiop label Mar 23, 2026
@mwichmann
Copy link
Copy Markdown
Collaborator Author

Okay, as I look at the manpage note, I think that does need to be changed...

Note

As an artifact of the internal implementation, the behavior of options added by AddOption which take option arguments is undefined if whitespace (rather than an = sign) is used as the separator on the command line. Users should avoid such usage; it is recommended to add a note to this effect to project documentation if the situation is likely to arise. In addition, if the nargs keyword is used to specify more than one following option argument (that is, with a value of 2 or greater), such arguments would necessarily be whitespace separated, triggering the issue. Developers should not use AddOption this way. Future versions of SCons will likely forbid such usage.

@mwichmann mwichmann added this to the NextRelease milestone Mar 23, 2026
mwichmann and others added 3 commits March 23, 2026 13:50
Testcases were added earlier (and recently expanded), but because
they were previously illustarting a shortcoming, there were listed
in the .exclude_tests file, and so not run unless explicitly listed.
Removing that file should let the tests run.

Signed-off-by: Mats Wichmann <mats@linux.com>
The two expected exception message showed SCons paths with enough
detail to include filesystem separators (SCons/Script/Main.py for
example).  Trimmed that back to include only the filename part
so the slash-vs-backslash difference doesn't fail us.

Signed-off-by: Mats Wichmann <mats@linux.com>
@mwichmann mwichmann moved this to In progress in Next Release Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

args_and_options options processing, arguments, get/setoption and their relationshiop

Projects

Status: In progress

2 participants