Skip to content

Commit

Permalink
[vcpkg] VCPKG_ENV_PASSTHROUGH_UNTRACKED (microsoft#15115)
Browse files Browse the repository at this point in the history
* [vcpkg] Add VCPKG_ENV_PASSTHROUGH_UNTRACKED

* [vcpkg] CR comments

Co-authored-by: Robert Schumacher <[email protected]>
  • Loading branch information
2 people authored and kw.ryu committed Dec 24, 2020
1 parent cfcb59f commit 3189e27
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 8 deletions.
12 changes: 9 additions & 3 deletions docs/users/triplets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions scripts/azure-pipelines/end-to-end-tests-dir/env-passthrough.ps1
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions scripts/testing/env-passthrough/passthrough.cmake
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions scripts/vcpkg_get_tags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions toolsrc/include/vcpkg/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 13 additions & 5 deletions toolsrc/src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}

Expand Down Expand Up @@ -1305,6 +1307,7 @@ namespace vcpkg::Build
CHAINLOAD_TOOLCHAIN_FILE,
BUILD_TYPE,
ENV_PASSTHROUGH,
ENV_PASSTHROUGH_UNTRACKED,
PUBLIC_ABI_OVERRIDE,
LOAD_VCVARS_ENV,
};
Expand All @@ -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},
};
Expand Down Expand Up @@ -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};
Expand Down
7 changes: 7 additions & 0 deletions toolsrc/src/vcpkg/commands.env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3189e27

Please sign in to comment.