From 1eb51cc427c3cdfb5cbc940776cc5032a109e4ec Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 19 Sep 2016 19:12:46 -0700 Subject: vcpkg.exe now detects the root dir via the .vcpkg-root file --- toolsrc/src/main.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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 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(); -- cgit v1.2.3