-
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
Conversation
|
@microsoft-github-policy-service agree company="elusoft GmbH" |
|
You could get the error logs from https://dev.azure.com/vcpkg/public/_build/results?buildId=86250&view=artifacts&pathAsName=false&type=publishedArtifacts |
|
Yeah, I really shouldn't have made that second set of changes. |
| set(config_link_backup "$ENV{_LINK_}") | ||
| set(ENV{_LINK_} "${LINK_ENV_${cmake_buildtype}}") | ||
| else() | ||
| unset(config_link_backup) |
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 to LINK_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 second if() clause.
As a result, we might observe the value of config_link_backup from the first iteration in the second iteration of the foreach() loop.
Regardless, and to be pedantic, we don't even know that config_link_backup is unset when the foreach() 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 second if() clause if and only if it was changed in the first if() clause.
There are certainly several ways to implement this logic in a semantically equivalent way.
For example, we could not look at config_link_backup at all in the second if() condition and instead use the exact same condition as in the first if() clause, i.e. if(LINK_ENV_${cmake_buildtype}) (assuming LINK_ENV_${cmake_buildtype} itself is not modified between the first and the second if() 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 first if() clause, by encoding the latter decision into config_link_backup (it's either DEFINED or not).
At first I considered just replacing the whole
config_link_backuplogic invcpkg_build_makewithvcpkg_{backup,restore}_env_variables(VARS _LINK_).Unfortunately, I soon realized that the same logic exists in
vcpkg_configure_make, only that in this casevcpkg_backup_env_variables(VARS _LINK_)is already used in the same scope.Since
vcpkg_{backup,restore}_env_variables()relies on the enclosing variable scope, which makes nested calls (within the same function) difficult, I kept theconfig_link_backuplogic (for now).Note that thanks to CMake 3.25 and
block()scopes, nested calls tovcpkg_{backup,restore}_env_variables()are now actually an option.However, even though vcpkg already uses CMake 3.25, I wasn't sure if this meant that backwards compatibility was not an issue.
Fixes #29983.