[vcpkg] Adding support for finding VS2019 by environment variable (#10760)

* Fixing build with VS2019

* Added support for finding VS2019 by VS160COMNTOOLS env var

* [vcpkg] Explicitly handle trailing backslash in VS140 path.

* [vcpkg] Defer instance validation for VS160COMNTOOLS

Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
This commit is contained in:
Arsen Tufankjian 2020-05-08 12:43:30 -07:00 committed by GitHub
parent 8de3f323dc
commit 644ba5d998
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -119,7 +119,23 @@ namespace vcpkg::VisualStudio
}
}
const auto append_if_has_cl = [&](fs::path&& path_root) {
// VS2019 instance from environment variable
auto maybe_vs160_comntools = System::get_environment_variable("vs160comntools");
if (const auto path_as_string = maybe_vs160_comntools.get())
{
// We want lexically_normal(), but it is not available
// Correct root path might be 2 or 3 levels up, depending on if the path has trailing backslash.
auto common7_tools = fs::u8path(*path_as_string);
if (common7_tools.filename().empty())
instances.emplace_back(common7_tools.parent_path().parent_path().parent_path(),
"16.0",
VisualStudioInstance::ReleaseType::LEGACY);
else
instances.emplace_back(
common7_tools.parent_path().parent_path(), "16.0", VisualStudioInstance::ReleaseType::LEGACY);
}
const auto append_if_has_cl_vs140 = [&](fs::path&& path_root) {
const auto cl_exe = path_root / "VC" / "bin" / "cl.exe";
const auto vcvarsall_bat = path_root / "VC" / "vcvarsall.bat";
@ -132,14 +148,16 @@ namespace vcpkg::VisualStudio
if (const auto path_as_string = maybe_vs140_comntools.get())
{
// We want lexically_normal(), but it is not available
// Correct root path might be 2 or 3 levels up, depending on if the path has trailing backslash. Try both.
auto common7_tools = fs::path{*path_as_string};
append_if_has_cl(fs::path{*path_as_string}.parent_path().parent_path());
append_if_has_cl(fs::path{*path_as_string}.parent_path().parent_path().parent_path());
// Correct root path might be 2 or 3 levels up, depending on if the path has trailing backslash.
auto common7_tools = fs::u8path(*path_as_string);
if (common7_tools.filename().empty())
append_if_has_cl_vs140(common7_tools.parent_path().parent_path().parent_path());
else
append_if_has_cl_vs140(common7_tools.parent_path().parent_path());
}
// VS2015 instance from Program Files
append_if_has_cl(program_files_32_bit / "Microsoft Visual Studio 14.0");
append_if_has_cl_vs140(program_files_32_bit / "Microsoft Visual Studio 14.0");
return instances;
}