-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Restore environment after make to avoid mixing-up linker flags
#29984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we unset this variable if it was not set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(In the following, I'll assume that both this variable and it are referring to
config_link_backup. However, if it refers toLINK_ENV_${cmake_buildtype}, you'll have to make some mental adjustments.)But we don't know that, do we?
Note that I have moved the
unset()up from the secondif()clause.As a result, we might observe the value of
config_link_backupfrom the first iteration in the second iteration of theforeach()loop.Regardless, and to be pedantic, we don't even know that
config_link_backupis unset when theforeach()loop is first entered, it could exist in the global scope, too.Call me paranoid.
The goal of this PR is to make sure that the value of the
_LINK_environment variable is restored in the secondif()clause if and only if it was changed in the firstif()clause.There are certainly several ways to implement this logic in a semantically equivalent way.
For example, we could not look at
config_link_backupat all in the secondif()condition and instead use the exact same condition as in the firstif()clause, i.e.if(LINK_ENV_${cmake_buildtype})(assumingLINK_ENV_${cmake_buildtype}itself is not modified between the first and the secondif()clause).I chose not to do this because I felt that it would increase, however slightly, the chances that the two conditions would become out of sync over time, breaking the if and only if requirement.
In other words: I decided to go with the proposed implementation because it (kind of) keeps both decisions, whether to modify
_LINK_in the first place and whether to restore its value, close together in the firstif()clause, by encoding the latter decision intoconfig_link_backup(it's eitherDEFINEDor not).