Skip to content
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

Keep all CUDA_PATH_* environment variables when forming the clean environment on Windows #1476

Merged
merged 1 commit into from
Sep 3, 2024
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
2 changes: 1 addition & 1 deletion include/vcpkg/base/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace vcpkg
Optional<std::string> get_environment_variable(ZStringView varname) noexcept;
void set_environment_variable(ZStringView varname, Optional<ZStringView> value) noexcept;

std::string get_environment_variables();
std::vector<std::string> get_environment_variables();

const ExpectedL<Path>& get_home_dir() noexcept;

Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ int main(const int argc, const char* const* const argv)
{
msg::write_unlocalized_text(Color::none,
"[DEBUG] The following environment variables are currently set:\n" +
get_environment_variables() + '\n');
Strings::join("\n", get_environment_variables()) + '\n');
}
else if (Debug::g_debugging)
{
Expand Down
8 changes: 4 additions & 4 deletions src/vcpkg/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ namespace vcpkg
#endif
}

std::string get_environment_variables()
std::vector<std::string> get_environment_variables()
{
std::string result;
std::vector<std::string> result;
#if defined(_WIN32)
const struct EnvironmentStringsW
{
Expand All @@ -382,12 +382,12 @@ namespace vcpkg
for (LPWCH i = env_block.strings; *i; i += len + 1)
{
len = wcslen(i);
result.append(Strings::to_utf8(i, len)).push_back('\n');
result.emplace_back(Strings::to_utf8(i, len));
}
#else
for (char** s = environ; *s; s++)
{
result.append(*s).push_back('\n');
result.emplace_back(*s);
}
#endif
return result;
Expand Down
33 changes: 16 additions & 17 deletions src/vcpkg/base/system.process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ namespace vcpkg
system32_env,
"\\WindowsPowerShell\\v1.0\\");

std::vector<std::string> env_strings = {
std::unordered_set<std::string> env_strings = {
"ALLUSERSPROFILE",
"APPDATA",
"CommonProgramFiles",
Expand Down Expand Up @@ -610,15 +610,6 @@ namespace vcpkg
"SSH_AUTH_SOCK",
"SSH_AGENT_PID",
// Enables find_package(CUDA) and enable_language(CUDA) in CMake
"CUDA_PATH",
"CUDA_PATH_V9_0",
"CUDA_PATH_V9_1",
"CUDA_PATH_V10_0",
"CUDA_PATH_V10_1",
"CUDA_PATH_V10_2",
"CUDA_PATH_V11_0",
"CUDA_PATH_V11_1",
"CUDA_PATH_V11_2",
"CUDA_TOOLKIT_ROOT_DIR",
// Environment variable generated automatically by CUDA after installation
"NVCUDASAMPLES_ROOT",
Expand All @@ -643,6 +634,11 @@ namespace vcpkg
"GXDKLatest",
};

std::vector<std::string> env_prefix_string = {
// Enables find_package(CUDA) and enable_language(CUDA) in CMake
"CUDA_PATH",
};

const Optional<std::string> keep_vars = get_environment_variable(EnvironmentVariableVcpkgKeepEnvVars);
const auto k = keep_vars.get();

Expand All @@ -660,20 +656,23 @@ namespace vcpkg
}
else
{
env_strings.push_back(std::move(var));
env_strings.emplace(std::move(var));
}
}
}

Environment env;

for (auto&& env_string : env_strings)
for (auto&& env_var : get_environment_variables())
{
const Optional<std::string> value = get_environment_variable(env_string);
const auto v = value.get();
if (!v || v->empty()) continue;

env.add_entry(env_string, *v);
auto pos = env_var.find('=');
auto key = env_var.substr(0, pos);
if (Util::Sets::contains(env_strings, key) ||
Util::any_of(env_prefix_string, [&](auto&& group) { return Strings::starts_with(key, group); }))
{
auto value = pos == std::string::npos ? "" : env_var.substr(pos + 1);
env.add_entry(key, value);
}
}

const auto path_iter = extra_env.find(EnvironmentVariablePath.to_string());
Expand Down
Loading