System::get_program_files() now returns Optional<fs::path>
MODIFY
include/vcpkg/base/system.h
include/vcpkg/base/system.h
@@ -110,9 +110,9 @@ namespace vcpkg::System
std::vector<CPUArchitecture> get_supported_host_architectures();
- const fs::path& get_program_files_32_bit();
+ const Optional<fs::path>& get_program_files_32_bit();
- const fs::path& get_program_files_platform_bitness();
+ const Optional<fs::path>& get_program_files_platform_bitness();
}
namespace vcpkg::Debug

MODIFY
src/vcpkg/base/system.cpp
src/vcpkg/base/system.cpp
@@ -531,23 +531,24 @@ namespace vcpkg::System
}
#endif
- static const fs::path& get_program_files()
+ static const Optional<fs::path>& get_program_files()
{
- static const fs::path PATH = []() -> fs::path {
+ static const auto PATH = []() -> Optional<fs::path> {
auto value = System::get_environment_variable("PROGRAMFILES");
if (auto v = value.get())
{
return *v;
}
- Checks::exit_with_message(VCPKG_LINE_INFO, "Could not find PROGRAMFILES environment variable");
+
+ return nullopt;
}();
return PATH;
}
- const fs::path& get_program_files_32_bit()
+ const Optional<fs::path>& get_program_files_32_bit()
{
- static const fs::path PATH = []() -> fs::path {
+ static const auto PATH = []() -> Optional<fs::path> {
auto value = System::get_environment_variable("ProgramFiles(x86)");
if (auto v = value.get())
{
@@ -558,9 +559,9 @@ namespace vcpkg::System
return PATH;
}
- const fs::path& get_program_files_platform_bitness()
+ const Optional<fs::path>& get_program_files_platform_bitness()
{
- static const fs::path PATH = []() -> fs::path {
+ static const auto PATH = []() -> Optional<fs::path> {
auto value = System::get_environment_variable("ProgramW6432");
if (auto v = value.get())
{

MODIFY
src/vcpkg/commands.edit.cpp
src/vcpkg/commands.edit.cpp
@@ -69,14 +69,24 @@ namespace vcpkg::Commands::Edit
std::vector<fs::path> candidate_paths;
auto maybe_editor_path = System::get_environment_variable("EDITOR");
- if (auto editor_path = maybe_editor_path.get())
+ if (const std::string* editor_path = maybe_editor_path.get())
{
candidate_paths.emplace_back(*editor_path);
}
- candidate_paths.push_back(System::get_program_files_platform_bitness() / VS_CODE_INSIDERS);
- candidate_paths.push_back(System::get_program_files_32_bit() / VS_CODE_INSIDERS);
- candidate_paths.push_back(System::get_program_files_platform_bitness() / VS_CODE);
- candidate_paths.push_back(System::get_program_files_32_bit() / VS_CODE);
+
+ const auto& program_files = System::get_program_files_platform_bitness();
+ if (const fs::path* pf = program_files.get())
+ {
+ candidate_paths.push_back(*pf / VS_CODE_INSIDERS);
+ candidate_paths.push_back(*pf / VS_CODE);
+ }
+
+ const auto& program_files_32_bit = System::get_program_files_32_bit();
+ if (const fs::path* pf = program_files_32_bit.get())
+ {
+ candidate_paths.push_back(*pf / VS_CODE_INSIDERS);
+ candidate_paths.push_back(*pf / VS_CODE);
+ }
const std::vector<fs::path> from_registry = find_from_registry();
candidate_paths.insert(candidate_paths.end(), from_registry.cbegin(), from_registry.cend());

MODIFY
src/vcpkg/commands.integrate.cpp
src/vcpkg/commands.integrate.cpp
@@ -148,12 +148,12 @@ namespace vcpkg::Commands::Integrate
static void integrate_install(const VcpkgPaths& paths)
{
static const std::array<fs::path, 2> OLD_SYSTEM_TARGET_FILES = {
- System::get_program_files_32_bit() /
+ System::get_program_files_32_bit().value_or_exit(VCPKG_LINE_INFO) /
"MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.nuget.targets",
- System::get_program_files_32_bit() /
+ System::get_program_files_32_bit().value_or_exit(VCPKG_LINE_INFO) /
"MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.system.targets"};
static const fs::path SYSTEM_WIDE_TARGETS_FILE =
- System::get_program_files_32_bit() /
+ System::get_program_files_32_bit().value_or_exit(VCPKG_LINE_INFO) /
"MSBuild/Microsoft.Cpp/v4.0/V140/ImportBefore/Default/vcpkg.system.props";
auto& fs = paths.get_filesystem();

MODIFY
src/vcpkg/vcpkgpaths.cpp
src/vcpkg/vcpkgpaths.cpp
@@ -190,10 +190,11 @@ namespace vcpkg
#endif
const std::vector<fs::path> from_path = Files::find_from_PATH("cmake");
candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend());
-#if defined(_WIN32)
- candidate_paths.push_back(System::get_program_files_platform_bitness() / "CMake" / "bin" / "cmake.exe");
- candidate_paths.push_back(System::get_program_files_32_bit() / "CMake" / "bin");
-#endif
+
+ const auto& program_files = System::get_program_files_platform_bitness();
+ if (const auto pf = program_files.get()) candidate_paths.push_back(*pf / "CMake" / "bin" / "cmake.exe");
+ const auto& program_files_32_bit = System::get_program_files_32_bit();
+ if (const auto pf = program_files_32_bit.get()) candidate_paths.push_back(*pf / "CMake" / "bin" / "cmake.exe");
const Optional<fs::path> path =
find_if_has_equal_or_greater_version(candidate_paths, VERSION_CHECK_ARGUMENTS, TOOL_DATA.required_version);
@@ -252,10 +253,11 @@ namespace vcpkg
#endif
const std::vector<fs::path> from_path = Files::find_from_PATH("git");
candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend());
-#if defined(_WIN32)
- candidate_paths.push_back(System::get_program_files_platform_bitness() / "git" / "cmd" / "git.exe");
- candidate_paths.push_back(System::get_program_files_32_bit() / "git" / "cmd" / "git.exe");
-#endif
+
+ const auto& program_files = System::get_program_files_platform_bitness();
+ if (const auto pf = program_files.get()) candidate_paths.push_back(*pf / "git" / "cmd" / "git.exe");
+ const auto& program_files_32_bit = System::get_program_files_32_bit();
+ if (const auto pf = program_files_32_bit.get()) candidate_paths.push_back(*pf / "git" / "cmd" / "git.exe");
const Optional<fs::path> path =
find_if_has_equal_or_greater_version(candidate_paths, VERSION_CHECK_ARGUMENTS, TOOL_DATA.required_version);

System::get_program_files() now returns Optional<fs::path>