Skip to content

Unknown variables from Variables file are now reported - #4653

Merged
bdbaddog merged 2 commits into
SCons:masterfrom
mwichmann:issue/varfile-unknowns
Nov 24, 2024
Merged

bdbaddog merged 2 commits into
SCons:masterfrom
mwichmann:issue/varfile-unknowns

Conversation

@mwichmann

Copy link
Copy Markdown
Collaborator

Previously Update added everything from the file(s) to the local values dict by doing exec, and then unknown ones ended up silently dropped since they weren't declared as options. Now the result of the exec call is reprocessed, so unknowns can be collected.

No doc impacts - just making it work as documented (see linked issue).

Fixes #4645

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

Previously Update added everything from the file(s) to the local
values dict by doing "exec", and then unknown ones ended up silently
dropped since they weren't declared as options. Now the result
of the exec call is reprocessed so unknowns can be collected.

Fixes SCons#4645

Signed-off-by: Mats Wichmann <[email protected]>
@bdbaddog

Copy link
Copy Markdown
Contributor

This changes the previous behavior.
Previously unknown variables in variables files would still propagate in the Environment()..

Fairly certain I've seen such depended on in the wild.

@mwichmann

Copy link
Copy Markdown
Collaborator Author

They shouldn't - existing bit of Update:

        # put the variables in the environment:
        # (don't copy over variables that are not declared as options)
        for option in self.options:
            try:
                env[option.key] = values[option.key]
            except KeyError:
                pass

@mwichmann

Copy link
Copy Markdown
Collaborator Author

git blame (needed a --follow !!!) says that code snippet is old, indeed:

1523e6f372 src/engine/SCons/Options.py            (Steven Knight    2002-09-26 00:54:35 +0000 276)         # put the variables in the environment:
13985d5667 src/engine/SCons/Options/__init__.py   (Steven Knight    2007-07-15 13:42:20 +0000 277)         # (don't copy over variables that are not declared as options)
82bf497dd0 src/engine/SCons/Options.py            (Steven Knight    2002-10-13 12:52:05 +0000 278)         for option in self.options:
82bf497dd0 src/engine/SCons/Options.py            (Steven Knight    2002-10-13 12:52:05 +0000 279)             try:
82bf497dd0 src/engine/SCons/Options.py            (Steven Knight    2002-10-13 12:52:05 +0000 280)                 env[option.key] = values[option.key]
82bf497dd0 src/engine/SCons/Options.py            (Steven Knight    2002-10-13 12:52:05 +0000 281)             except KeyError:
82bf497dd0 src/engine/SCons/Options.py            (Steven Knight    2002-10-13 12:52:05 +0000 282)                 pass
1523e6f372 src/engine/SCons/Options.py            (Steven Knight    2002-09-26 00:54:35 +0000 283) 

So I think we can say that unknown options have never been copied to the environment.

However, the added check reading from the files doesn't have to exclude unknowns (since they'll be skipped by the mentioned chunk anyway) and just add to the unknown dict if that feels more comfortable...

@bdbaddog

Copy link
Copy Markdown
Contributor

You are correct. I was mistaken.. sorry bout that..

@mwichmann mwichmann added the Variables Variables() subsystem label Nov 20, 2024
@bdbaddog
bdbaddog merged commit 502665a into SCons:master Nov 24, 2024
@mwichmann mwichmann added this to the NextRelease milestone Nov 25, 2024
@mwichmann
mwichmann deleted the issue/varfile-unknowns branch November 25, 2024 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Variables Variables() subsystem

Projects

No open projects
Status: Complete

Development

Successfully merging this pull request may close these issues.

UnknownVariables doesn't return unknown variables defined in files

2 participants