[vcpkg] Add VCPKG_DEFAULT_VS_PATH environment variable
MODIFY
include/vcpkg/vcpkgpaths.h
include/vcpkg/vcpkgpaths.h
@@ -33,7 +33,7 @@ namespace vcpkg
struct VcpkgPaths
{
- static Expected<VcpkgPaths> create(const fs::path& vcpkg_root_dir);
+ static Expected<VcpkgPaths> create(const fs::path& vcpkg_root_dir, const std::string& default_vs_path);
fs::path package_dir(const PackageSpec& spec) const;
fs::path port_dir(const PackageSpec& spec) const;
@@ -90,5 +90,7 @@ namespace vcpkg
Lazy<fs::path> ifw_repogen_exe;
Lazy<std::vector<Toolset>> toolsets;
Lazy<std::vector<Toolset>> toolsets_vs2013;
+
+ fs::path default_vs_path;
};
}

MODIFY
src/vcpkg.cpp
src/vcpkg.cpp
@@ -94,7 +94,9 @@ static void inner(const VcpkgCmdArguments& args)
Checks::check_exit(VCPKG_LINE_INFO, !vcpkg_root_dir.empty(), "Error: Could not detect vcpkg-root.");
- const Expected<VcpkgPaths> expected_paths = VcpkgPaths::create(vcpkg_root_dir);
+ auto default_vs_path = System::get_environment_variable("VCPKG_DEFAULT_VS_PATH").value_or("");
+
+ const Expected<VcpkgPaths> expected_paths = VcpkgPaths::create(vcpkg_root_dir, default_vs_path);
Checks::check_exit(VCPKG_LINE_INFO,
!expected_paths.error(),
"Error: Invalid vcpkg root directory %s: %s",

MODIFY
src/vcpkg/vcpkgpaths.cpp
src/vcpkg/vcpkgpaths.cpp
@@ -293,7 +293,7 @@ namespace vcpkg
return fetch_tool(paths.scripts, "installerbase", TOOL_DATA);
}
- Expected<VcpkgPaths> VcpkgPaths::create(const fs::path& vcpkg_root_dir)
+ Expected<VcpkgPaths> VcpkgPaths::create(const fs::path& vcpkg_root_dir, const std::string& default_vs_path)
{
std::error_code ec;
const fs::path canonical_vcpkg_root_dir = fs::stdfs::canonical(vcpkg_root_dir, ec);
@@ -304,6 +304,7 @@ namespace vcpkg
VcpkgPaths paths;
paths.root = canonical_vcpkg_root_dir;
+ paths.default_vs_path = default_vs_path;
if (paths.root.empty())
{
@@ -643,7 +644,11 @@ namespace vcpkg
std::vector<const Toolset*> candidates = Util::element_pointers(vs_toolsets);
const auto tsv = prebuildinfo.platform_toolset.get();
- const auto vsp = prebuildinfo.visual_studio_path.get();
+ auto vsp = prebuildinfo.visual_studio_path.get();
+ if (!vsp && !default_vs_path.empty())
+ {
+ vsp = &default_vs_path;
+ }
if (tsv && vsp)
{

[vcpkg] Add VCPKG_DEFAULT_VS_PATH environment variable