Fix instances of incorrect if(ENV{...}) usage and ENV{PKG_CONFIG_PATH} not being reset#14799
Fix instances of incorrect if(ENV{...}) usage and ENV{PKG_CONFIG_PATH} not being reset#14799LRFLEW wants to merge 2 commits intomicrosoft:masterfrom
Conversation
|
cc @Neumann-A for review this PR because he is the pkgconfig author. |
|
we should define some helper macros for this kind of environment stuff |
|
I could use some clarification/direction for this. I see the tag "requires author response" was added. I'm assuming this means you want me to attempt turning the handling of @Neumann-A I haven't done much with macros in CMake. Are you talking about specifically using |
|
Ok, I spent some time looking into the build error that CI found. I was able to confirm the build errors in my VM. After a lot of investigating, I finally figured out the source. As it turns out, one of the typos that this fixed resulted in a latent bug appearing. In vcpkg_configure_make.cmake, it is using this line to setup pkg-config a specific way (i.e. with a specific prefix): set(ENV{PKG_CONFIG} "${PKGCONFIG} --define-variable=prefix=${_VCPKG_INSTALLED}${PATH_SUFFIX_${_buildtype}}")This definition of the environment variable is never reset, which results in subsequent steps being affected by this line. This wasn't an issue before because vcpkg_find_acquire_program.cmake was incorrectly checking for the existence of this environment variable and was ignoring it. When I fixed the check in vcpkg_find_acquire_program.cmake, its behavior was being changed by calling vcpkg_configure_make.cmake isn't the only file that's changing |
|
@Neumann-A Do you have anyother questions? |
|
@JackBoosY No not really we should introduce something like |
|
Ok, a few quick comments / responses @Neumann-A What exactly would The Speaking of path-lists, there are a few instances with Looking at the cases I found for this, I'm not sure how necessary the Lastly, should these macros be strictly internal? This PR already found two instances in ports where the macros would be useful, and there's likely more for other ENV variables. It might be nice to allow the functions to be utilized from there. |
no it might not be path specific e.g. CFLAGS etc.. You would always use a
it is required there a cases where you want to first setup general configuration independent falgs and then configuration dependent flags. It also avoiding issues to to forgetting to correctly unset the previous configuration |
There was a problem hiding this comment.
To preserve the (un)defined semantics of pkg_config_path, we should set/unset the backup variable.
Is there a way we can add tests for this to scripts/e2e_ports/ and scripts/azure-pipelines/end-to-end-tests.ps1? Maybe one could embed some .pc files and do testing about setting and unsetting PKG_CONFIG_PATH and calling various helpers.
ports/ffmpeg/portfile.cmake
Outdated
There was a problem hiding this comment.
| if(BACKUP_ENV_PKG_CONFIG_PATH_RELEASE) | |
| if(DEFINED BACKUP_ENV_PKG_CONFIG_PATH_RELEASE) |
There was a problem hiding this comment.
Just to add a point of clarification, this isn't as necessary as it is to add DEFINED when checking environment variables. That's because the form if(<variable>) checks if the variable is "defined to a value that is not a false constant" (if). This could be an issue if the environment variable was set to something like FALSE, so it probably should be changed everywhere it's used (or in the new macro), but it's a less pressing issue.
ports/ffmpeg/portfile.cmake
Outdated
There was a problem hiding this comment.
| set(ENV{PKG_CONFIG_PATH} "${CURRENT_INSTALLED_DIR}/lib/pkgconfig") | |
| set(ENV{PKG_CONFIG_PATH} "${CURRENT_INSTALLED_DIR}/lib/pkgconfig") | |
| unset(BACKUP_ENV_PKG_CONFIG_PATH_RELEASE) |
There was a problem hiding this comment.
The way this is written now, it's assumed that BACKUP_ENV_PKG_CONFIG_PATH_${_config} is unset going in. If it's not unset, then that's a larger bug. Rather than unsetting the variable it here, I think the broader solution is to check in vcpkg_internal_(set|prepend|append)_and_backup_env if it exists (or if it is in the list being kept for vcpkg_internal_check_env_restored) and throw an error if it is.
|
@ras0219 Ping for review again. |
|
@LRFLEW, could you resolve the conflicts? |
|
I've updated the code here, but the CI is showing regressions. The codebase has changed a lot since I first made this PR. One of the files was already fixed, so I removed that from this PR. The regressions are likely due to other ports having or being affected by the underlying bug. I'll take a closer look at this and try to get all the regressions fixed. |
|
This PR has been inactive for a long time, please reopen it if there is any progress. |
I was experimenting with vcpkg in a way that required setting the environment variable
PKG_CONFIG_PATH, but I was getting errors in vcpkg. As it turns out, there is a mistake in a few locations where the variable isn't tested correctly.if(ENV{PKG_CONFIG_PATH})does not work (at least on my setup, macOS 10.14), and always results in the condition being evaluated as false/OFF. This is fixed by changing it toif(DEFINED ENV{PKG_CONFIG_PATH}). Performing a grep forif(ENV{found one other instance, so I fixed that too.While looking into this, I noticed that while (almost) all instances of modifying
ENV{PKG_CONFIG_PATH}was setting a variable of the formBACKUP_ENV_PKG_CONFIG_PATH_*, not all of them were using it. Based on the variable's name, I assume this is a mistake and corrected all the instances of it (for this specific environment variable). This resulted in touching a few ports that used the environment variable. I'm not sure if it's appropriate to increment thePort-Versionin this case (as it's more of a tooling update even in the ports), but I went ahead and incremented them, as that seems to be the protocol for this.