aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/main.cpp
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2016-09-19 19:12:46 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2016-09-19 19:12:46 -0700
commit1eb51cc427c3cdfb5cbc940776cc5032a109e4ec (patch)
treeda35478a259513041e11b7f0c174d8b904a960e0 /toolsrc/src/main.cpp
parentf78c64e3a958a0aa7688af9710d4969eb286bff3 (diff)
downloadvcpkg-1eb51cc427c3cdfb5cbc940776cc5032a109e4ec.tar.gz
vcpkg-1eb51cc427c3cdfb5cbc940776cc5032a109e4ec.zip
vcpkg.exe now detects the root dir via the .vcpkg-root file
Diffstat (limited to 'toolsrc/src/main.cpp')
-rw-r--r--toolsrc/src/main.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp
index bba1f3c63..d3fb855d1 100644
--- a/toolsrc/src/main.cpp
+++ b/toolsrc/src/main.cpp
@@ -23,6 +23,21 @@ void invalid_command(const std::string& cmd)
exit(EXIT_FAILURE);
}
+static fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename)
+{
+ fs::path current_dir = starting_dir;
+ for (; !current_dir.empty(); current_dir = current_dir.parent_path())
+ {
+ const fs::path candidate = current_dir / filename;
+ if (fs::exists(candidate))
+ {
+ break;
+ }
+ }
+
+ return current_dir;
+}
+
static void inner(const vcpkg_cmd_arguments& args)
{
TrackProperty("command", args.command);
@@ -47,11 +62,17 @@ static void inner(const vcpkg_cmd_arguments& args)
auto vcpkg_root_dir_env = System::wdupenv_str(L"VCPKG_ROOT");
if (!vcpkg_root_dir_env.empty())
+ {
vcpkg_root_dir = fs::absolute(vcpkg_root_dir_env);
+ }
else
- vcpkg_root_dir = fs::absolute(System::get_exe_path_of_current_process()).parent_path();
+ {
+ vcpkg_root_dir = find_file_recursively_up(fs::absolute(System::get_exe_path_of_current_process()), ".vcpkg-root");
+ }
}
+ Checks::check_exit(!vcpkg_root_dir.empty(), "Error: Could not detect vcpkg-root.");
+
const expected<vcpkg_paths> expected_paths = vcpkg_paths::create(vcpkg_root_dir);
Checks::check_exit(!expected_paths.error_code(), "Error: Invalid vcpkg root directory %s: %s", vcpkg_root_dir.string(), expected_paths.error_code().message());
const vcpkg_paths paths = expected_paths.get_or_throw();