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

Ignore the VCPKG_ROOT environment variable when we detect a vcpkg_root. #725

Merged
merged 5 commits into from
Oct 11, 2022

Conversation

BillyONeal
Copy link
Member

This resolves https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1634907

In actions/runner-images#6196 we have yet another CI system that is trying to helpfully set VCPKG_ROOT for customers to find their vcpkg instance which yet again breaks classic-mode-as-submodule customers. This change mitigates the issue by ignoring the environment variable when we detect a valid VCPKG_ROOT, which the user can override by using the command line option.

This resolves https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1634907

In actions/runner-images#6196 we have yet another CI system that is trying to helpfully set VCPKG_ROOT for customers to find their vcpkg instance which yet again breaks classic-mode-as-submodule customers. This change mitigates the issue by ignoring the environment variable when we detect a valid VCPKG_ROOT, which the user can override by using the command line option.
# Conflicts:
#	include/vcpkg/base/messages.h
#	locales/messages.en.json
#	locales/messages.json
#	src/vcpkg/base/messages.cpp
@@ -5,13 +5,13 @@ if (-not $IsLinux -and -not $IsMacOS) {
$env:_VCPKG_TEST_UNTRACKED = "b"

$x = Run-Vcpkg "--overlay-triplets=$PSScriptRoot/../e2e_ports/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%")
if ($x -ne "%_VCPKG_TEST_TRACKED% %_VCPKG_TEST_TRACKED2% %_VCPKG_TEST_UNTRACKED% %_VCPKG_TEST_UNTRACKED2%`r`n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work on Linux? We should run the end-to-end tests on our Linux agent as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do. But this test starts with if (-not $IsLinux -and -not $IsMacOS) {. (The test wouldn't work on Linux or MacOS because they don't use %s)

Comment on lines +815 to 825
if (auto entry = obj.get(VCPKG_ROOT_ARG_NAME))
{
auto as_sv = entry->string(VCPKG_LINE_INFO);
args.vcpkg_root_dir_arg.emplace(as_sv.data(), as_sv.size());
}

if (auto entry = obj.get(VCPKG_ROOT_ENV_NAME))
{
args.vcpkg_root_dir = std::make_unique<std::string>(entry->string(VCPKG_LINE_INFO).to_string());
auto as_sv = entry->string(VCPKG_LINE_INFO);
args.vcpkg_root_dir_env.emplace(as_sv.data(), as_sv.size());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably be consolidated into a single, non-optional field -- the outer vcpkg instance will have already warned about any mismatching.

Comment on lines +851 to 859
if (auto vcpkg_root_dir_arg = args.vcpkg_root_dir_arg.get())
{
obj.insert(VCPKG_ROOT_ARG_NAME, Json::Value::string(*vcpkg_root_dir_arg));
}

if (auto vcpkg_root_dir_env = args.vcpkg_root_dir_env.get())
{
obj.insert(VCPKG_ROOT_DIR_ENV, Json::Value::string(*args.vcpkg_root_dir.get()));
obj.insert(VCPKG_ROOT_ENV_NAME, Json::Value::string(*vcpkg_root_dir_env));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably be consolidated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that the decision of what to use depends on information that isn't known until later, in VcpkgPaths.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(To clarify: Yes, the right thing to do is to determine what the correct thing is, and set that. I went with this more hacky solution so that I could get this out quickly without needing to substantially alter the relationship between VcpkgCmdArguments and VcpkgPaths.

@BillyONeal
Copy link
Member Author

microsoft/vcpkg#27188

@BillyONeal BillyONeal merged commit 0cba610 into microsoft:main Oct 11, 2022
@BillyONeal BillyONeal deleted the vcpkg-root-change branch October 11, 2022 22:28
BillyONeal added a commit to microsoft/vcpkg that referenced this pull request Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants