[vcpkg] VCPKG_ENV_PASSTHROUGH_UNTRACKED (#15115)

* [vcpkg] Add VCPKG_ENV_PASSTHROUGH_UNTRACKED

* [vcpkg] CR comments

Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
This commit is contained in:
ras0219 2020-12-17 11:35:08 -08:00 committed by GitHub
parent a268c5a7f1
commit 9a81392e48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 8 deletions

View File

@ -102,14 +102,20 @@ See the [`"supports"`](../maintainers/manifest-files.md#supports) manifest file
### VCPKG_ENV_PASSTHROUGH
Instructs vcpkg to allow additional environment variables into the build process.
On Windows, vcpkg builds packages in a special clean environment that is isolated from the current command prompt to ensure build reliability and consistency.
This triplet option can be set to a list of additional environment variables that will be added to the clean environment.
On Windows, vcpkg builds packages in a special clean environment that is isolated from the current command prompt to
ensure build reliability and consistency. This triplet option can be set to a list of additional environment variables
that will be added to the clean environment. The values of these environment variables will be hashed into the package
abi -- to pass through environment variables without abi tracking, see `VCPKG_ENV_PASSTHROUGH_UNTRACKED`.
See also the `vcpkg env` command for how you can inspect the precise environment that will be used.
> Implementers' Note: this list is extracted via the `vcpkg_get_tags` mechanism.
### VCPKG_ENV_PASSTHROUGH_UNTRACKED
Instructs vcpkg to allow additional environment variables into the build process without abi tracking.
See `VCPKG_ENV_PASSTHROUGH`.
<a name="VCPKG_VISUAL_STUDIO_PATH"></a>
### VCPKG_VISUAL_STUDIO_PATH
Specifies the Visual Studio installation to use.

View File

@ -0,0 +1,21 @@
if (-not $IsLinux -and -not $IsMacOS) {
. $PSScriptRoot/../end-to-end-tests-prelude.ps1
$env:_VCPKG_TEST_TRACKED = "a"
$env:_VCPKG_TEST_UNTRACKED = "b"
$x = ./vcpkg "--overlay-triplets=$PSScriptRoot/../../testing/env-passthrough" env "echo %_VCPKG_TEST_TRACKED% %_VCPKG_TEST_TRACKED2% %_VCPKG_TEST_UNTRACKED% %_VCPKG_TEST_UNTRACKED2%"
if ($x -ne "%_VCPKG_TEST_TRACKED% %_VCPKG_TEST_TRACKED2% %_VCPKG_TEST_UNTRACKED% %_VCPKG_TEST_UNTRACKED2%")
{
throw "env should have cleaned the environment ($x)"
}
$y = ./vcpkg "--overlay-triplets=$PSScriptRoot/../../testing/env-passthrough" env --triplet passthrough "echo %_VCPKG_TEST_TRACKED% %_VCPKG_TEST_TRACKED2% %_VCPKG_TEST_UNTRACKED% %_VCPKG_TEST_UNTRACKED2%"
if ($y -ne "a %_VCPKG_TEST_TRACKED2% b %_VCPKG_TEST_UNTRACKED2%")
{
throw "env should have kept the environment ($y)"
}
rm env:_VCPKG_TEST_TRACKED
rm env:_VCPKG_TEST_UNTRACKED
}

View File

@ -0,0 +1,6 @@
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_ENV_PASSTHROUGH _VCPKG_TEST_TRACKED _VCPKG_TEST_TRACKED2)
set(VCPKG_ENV_PASSTHROUGH_UNTRACKED _VCPKG_TEST_UNTRACKED _VCPKG_TEST_UNTRACKED2)

View File

@ -24,6 +24,7 @@ e1e74b5c-18cb-4474-a6bd-5c1c8bc81f3f")
message("c35112b6-d1ba-415b-aa5d-81de856ef8eb
VCPKG_PUBLIC_ABI_OVERRIDE=${VCPKG_PUBLIC_ABI_OVERRIDE}
VCPKG_ENV_PASSTHROUGH=${VCPKG_ENV_PASSTHROUGH}
VCPKG_ENV_PASSTHROUGH_UNTRACKED=${VCPKG_ENV_PASSTHROUGH_UNTRACKED}
VCPKG_LOAD_VCVARS_ENV=${VCPKG_LOAD_VCVARS_ENV}
e1e74b5c-18cb-4474-a6bd-5c1c8bc81f3f
8c504940-be29-4cba-9f8f-6cd83e9d87b7")

View File

@ -213,6 +213,7 @@ namespace vcpkg::Build
Optional<ConfigurationType> build_type;
Optional<std::string> public_abi_override;
std::vector<std::string> passthrough_env_vars;
std::vector<std::string> passthrough_env_vars_tracked;
fs::path toolchain_file() const;
bool using_vcvars() const;

View File

@ -896,11 +896,13 @@ namespace vcpkg::Build
Hash::Algorithm::Sha1));
}
for (const auto& env_var : pre_build_info.passthrough_env_vars)
for (const auto& env_var : pre_build_info.passthrough_env_vars_tracked)
{
abi_tag_entries.emplace_back(
"ENV:" + env_var,
Hash::get_string_hash(System::get_environment_variable(env_var).value_or(""), Hash::Algorithm::Sha1));
if (auto e = System::get_environment_variable(env_var))
{
abi_tag_entries.emplace_back(
"ENV:" + env_var, Hash::get_string_hash(e.value_or_exit(VCPKG_LINE_INFO), Hash::Algorithm::Sha1));
}
}
}
@ -1305,6 +1307,7 @@ namespace vcpkg::Build
CHAINLOAD_TOOLCHAIN_FILE,
BUILD_TYPE,
ENV_PASSTHROUGH,
ENV_PASSTHROUGH_UNTRACKED,
PUBLIC_ABI_OVERRIDE,
LOAD_VCVARS_ENV,
};
@ -1318,6 +1321,7 @@ namespace vcpkg::Build
{"VCPKG_CHAINLOAD_TOOLCHAIN_FILE", VcpkgTripletVar::CHAINLOAD_TOOLCHAIN_FILE},
{"VCPKG_BUILD_TYPE", VcpkgTripletVar::BUILD_TYPE},
{"VCPKG_ENV_PASSTHROUGH", VcpkgTripletVar::ENV_PASSTHROUGH},
{"VCPKG_ENV_PASSTHROUGH_UNTRACKED", VcpkgTripletVar::ENV_PASSTHROUGH_UNTRACKED},
{"VCPKG_PUBLIC_ABI_OVERRIDE", VcpkgTripletVar::PUBLIC_ABI_OVERRIDE},
{"VCPKG_LOAD_VCVARS_ENV", VcpkgTripletVar::LOAD_VCVARS_ENV},
};
@ -1365,7 +1369,11 @@ namespace vcpkg::Build
variable_value);
break;
case VcpkgTripletVar::ENV_PASSTHROUGH:
passthrough_env_vars = Strings::split(variable_value, ';');
passthrough_env_vars_tracked = Strings::split(variable_value, ';');
Util::Vectors::append(&passthrough_env_vars, passthrough_env_vars_tracked);
break;
case VcpkgTripletVar::ENV_PASSTHROUGH_UNTRACKED:
Util::Vectors::append(&passthrough_env_vars, Strings::split(variable_value, ';'));
break;
case VcpkgTripletVar::PUBLIC_ABI_OVERRIDE:
public_abi_override = variable_value.empty() ? nullopt : Optional<std::string>{variable_value};

View File

@ -75,6 +75,13 @@ namespace vcpkg::Commands::Env
extra_env.emplace("PYTHONPATH",
fs::u8string(paths.installed / fs::u8path(triplet.to_string()) / fs::u8path("python")));
if (path_vars.size() > 0) extra_env.emplace("PATH", Strings::join(";", path_vars));
for (auto&& passthrough : pre_build_info.passthrough_env_vars)
{
if (auto e = System::get_environment_variable(passthrough))
{
extra_env.emplace(passthrough, e.value_or_exit(VCPKG_LINE_INFO));
}
}
auto env = [&] {
auto clean_env = System::get_modified_clean_environment(extra_env);