Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions scripts/cmake/vcpkg_build_make.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ function(vcpkg_build_make)
if(LINK_ENV_${cmake_buildtype})
set(config_link_backup "$ENV{_LINK_}")
set(ENV{_LINK_} "${LINK_ENV_${cmake_buildtype}}")
else()
unset(config_link_backup)
Copy link
Contributor

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?

Copy link
Contributor Author

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).

endif()

if(arg_ADD_BIN_TO_PATH)
Expand Down Expand Up @@ -171,9 +173,8 @@ function(vcpkg_build_make)
)
endif()

if(config_link_backup)
if(DEFINED config_link_backup)
set(ENV{_LINK_} "${config_link_backup}")
unset(config_link_backup)
endif()

if(arg_ADD_BIN_TO_PATH)
Expand Down
5 changes: 3 additions & 2 deletions scripts/cmake/vcpkg_configure_make.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,8 @@ function(vcpkg_configure_make)
if(LINK_ENV_${current_buildtype})
set(link_config_backup "$ENV{_LINK_}")
set(ENV{_LINK_} "${LINK_ENV_${current_buildtype}}")
else()
unset(link_config_backup)
endif()

vcpkg_list(APPEND lib_env_vars LIB LIBPATH LIBRARY_PATH) # LD_LIBRARY_PATH)
Expand Down Expand Up @@ -826,9 +828,8 @@ function(vcpkg_configure_make)
endif()
z_vcpkg_restore_pkgconfig_path()

if(link_config_backup)
if(DEFINED link_config_backup)
set(ENV{_LINK_} "${link_config_backup}")
unset(link_config_backup)
endif()

if(arg_ADD_BIN_TO_PATH)
Expand Down