aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg.cpp
diff options
context:
space:
mode:
authorBilly O'Neal <bion@microsoft.com>2020-06-03 19:31:28 -0700
committerGitHub <noreply@github.com>2020-06-03 19:31:28 -0700
commit4fb225608532e9fb2fd2f5f1dbe9ec092cdc7c93 (patch)
treed4ccfc78c9043c6c136dc2ec72a3f005366564a3 /toolsrc/src/vcpkg.cpp
parent20e6626d8758f5e46c1777e3e1ff4d98ed5d2e7a (diff)
downloadvcpkg-4fb225608532e9fb2fd2f5f1dbe9ec092cdc7c93.tar.gz
vcpkg-4fb225608532e9fb2fd2f5f1dbe9ec092cdc7c93.zip
[vcpkg] Allow CI to pass in all relevant directories and remove use of symbolic links (#11483)
Diffstat (limited to 'toolsrc/src/vcpkg.cpp')
-rw-r--r--toolsrc/src/vcpkg.cpp119
1 files changed, 21 insertions, 98 deletions
diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp
index 95cd39778..d4b51e96b 100644
--- a/toolsrc/src/vcpkg.cpp
+++ b/toolsrc/src/vcpkg.cpp
@@ -38,18 +38,16 @@ static constexpr int SURVEY_INITIAL_OFFSET_IN_HOURS = SURVEY_INTERVAL_IN_HOURS -
static void invalid_command(const std::string& cmd)
{
System::print2(System::Color::error, "invalid command: ", cmd, '\n');
- Help::print_usage();
+ print_usage();
Checks::exit_fail(VCPKG_LINE_INFO);
}
-static void inner(const VcpkgCmdArguments& args)
+static void inner(vcpkg::Files::Filesystem& fs, const VcpkgCmdArguments& args)
{
- auto& fs = Files::get_real_filesystem();
-
Metrics::g_metrics.lock()->track_property("command", args.command);
if (args.command.empty())
{
- Help::print_usage();
+ print_usage();
Checks::exit_fail(VCPKG_LINE_INFO);
}
@@ -63,86 +61,18 @@ static void inner(const VcpkgCmdArguments& args)
return &*it;
}
else
+ {
return static_cast<decltype(&*it)>(nullptr);
+ }
};
if (const auto command_function = find_command(Commands::get_available_commands_type_c()))
{
- return command_function->function(args);
- }
-
- fs::path vcpkg_root_dir;
- if (args.vcpkg_root_dir)
- {
- vcpkg_root_dir = fs.absolute(VCPKG_LINE_INFO, fs::u8path(*args.vcpkg_root_dir));
- }
- else
- {
- const auto vcpkg_root_dir_env = System::get_environment_variable("VCPKG_ROOT");
- if (const auto v = vcpkg_root_dir_env.get())
- {
- vcpkg_root_dir = fs.absolute(VCPKG_LINE_INFO, *v);
- }
- else
- {
- const fs::path current_path = fs.current_path(VCPKG_LINE_INFO);
- vcpkg_root_dir = fs.find_file_recursively_up(current_path, ".vcpkg-root");
-
- if (vcpkg_root_dir.empty())
- {
- vcpkg_root_dir = fs.find_file_recursively_up(
- fs.absolute(VCPKG_LINE_INFO, System::get_exe_path_of_current_process()), ".vcpkg-root");
- }
- }
- }
-
- Checks::check_exit(VCPKG_LINE_INFO, !vcpkg_root_dir.empty(), "Error: Could not detect vcpkg-root.");
-
- Debug::print("Using vcpkg-root: ", vcpkg_root_dir.u8string(), '\n');
-
- Optional<fs::path> install_root_dir;
- if (args.install_root_dir)
- {
- install_root_dir = Files::get_real_filesystem().canonical(VCPKG_LINE_INFO, fs::u8path(*args.install_root_dir));
- Debug::print("Using install-root: ", install_root_dir.value_or_exit(VCPKG_LINE_INFO).u8string(), '\n');
- }
-
- Optional<fs::path> vcpkg_scripts_root_dir;
- if (args.scripts_root_dir)
- {
- vcpkg_scripts_root_dir =
- Files::get_real_filesystem().canonical(VCPKG_LINE_INFO, fs::u8path(*args.scripts_root_dir));
- Debug::print("Using scripts-root: ", vcpkg_scripts_root_dir.value_or_exit(VCPKG_LINE_INFO).u8string(), '\n');
+ return command_function->function(args, fs);
}
- auto default_vs_path = System::get_environment_variable("VCPKG_VISUAL_STUDIO_PATH").value_or("");
-
- auto original_cwd = Files::get_real_filesystem().current_path(VCPKG_LINE_INFO);
-
- const Expected<VcpkgPaths> expected_paths = VcpkgPaths::create(vcpkg_root_dir,
- install_root_dir,
- vcpkg_scripts_root_dir,
- default_vs_path,
- args.overlay_triplets.get(),
- original_cwd);
- Checks::check_exit(VCPKG_LINE_INFO,
- !expected_paths.error(),
- "Error: Invalid vcpkg root directory %s: %s",
- vcpkg_root_dir.string(),
- expected_paths.error().message());
- const VcpkgPaths& paths = expected_paths.value_or_exit(VCPKG_LINE_INFO);
-
-#if defined(_WIN32)
- const int exit_code = _wchdir(paths.root.c_str());
-#else
- const int exit_code = chdir(paths.root.c_str());
-#endif
- Checks::check_exit(
- VCPKG_LINE_INFO,
- exit_code == 0,
- "Changing the working directory to the vcpkg root directory failed. Did you incorrectly define the VCPKG_ROOT "
- "environment variable, or did you mistakenly create a file named .vcpkg-root somewhere?");
-
+ const VcpkgPaths paths(fs, args);
+ fs.current_path(paths.root, VCPKG_LINE_INFO);
if (args.command == "install" || args.command == "remove" || args.command == "export" || args.command == "update")
{
Commands::Version::warn_if_vcpkg_version_mismatch(paths);
@@ -213,10 +143,8 @@ static void inner(const VcpkgCmdArguments& args)
return invalid_command(args.command);
}
-static void load_config()
+static void load_config(vcpkg::Files::Filesystem& fs)
{
- auto& fs = Files::get_real_filesystem();
-
auto config = UserConfig::try_read_data(fs);
bool write_config = false;
@@ -280,6 +208,7 @@ int main(const int argc, const char* const* const argv)
{
if (argc == 0) std::abort();
+ auto& fs = Files::get_real_filesystem();
*GlobalState::timer.lock() = Chrono::ElapsedTimer::create_started();
#if defined(_WIN32)
@@ -301,7 +230,7 @@ int main(const int argc, const char* const* const argv)
auto metrics = Metrics::g_metrics.lock();
metrics->track_metric("elapsed_us", elapsed_us_inner);
Debug::g_debugging = false;
- metrics->flush();
+ metrics->flush(Files::get_real_filesystem());
#if defined(_WIN32)
if (GlobalState::g_init_console_initialized)
@@ -325,7 +254,7 @@ int main(const int argc, const char* const* const argv)
System::register_console_ctrl_handler();
- load_config();
+ load_config(fs);
const auto vcpkg_feature_flags_env = System::get_environment_variable("VCPKG_FEATURE_FLAGS");
if (const auto v = vcpkg_feature_flags_env.get())
@@ -333,27 +262,21 @@ int main(const int argc, const char* const* const argv)
auto flags = Strings::split(*v, ',');
if (std::find(flags.begin(), flags.end(), "binarycaching") != flags.end()) GlobalState::g_binary_caching = true;
}
- const auto vcpkg_disable_metrics_env = System::get_environment_variable("VCPKG_DISABLE_METRICS");
- if (vcpkg_disable_metrics_env.has_value())
- {
- Metrics::g_metrics.lock()->set_disabled(true);
- }
-
- const VcpkgCmdArguments args = VcpkgCmdArguments::create_from_command_line(argc, argv);
-
- if (const auto p = args.binarycaching.get()) GlobalState::g_binary_caching = *p;
- if (const auto p = args.printmetrics.get()) Metrics::g_metrics.lock()->set_print_metrics(*p);
- if (const auto p = args.sendmetrics.get()) Metrics::g_metrics.lock()->set_send_metrics(*p);
+ VcpkgCmdArguments args = VcpkgCmdArguments::create_from_command_line(fs, argc, argv);
+ args.imbue_from_environment();
+ if (const auto p = args.binary_caching.get()) GlobalState::g_binary_caching = *p;
+ if (const auto p = args.print_metrics.get()) Metrics::g_metrics.lock()->set_print_metrics(*p);
+ if (const auto p = args.send_metrics.get()) Metrics::g_metrics.lock()->set_send_metrics(*p);
if (const auto p = args.disable_metrics.get()) Metrics::g_metrics.lock()->set_disabled(*p);
if (const auto p = args.debug.get()) Debug::g_debugging = *p;
- if (args.sendmetrics.has_value() && !Metrics::g_metrics.lock()->metrics_enabled())
+ if (args.send_metrics.has_value() && !Metrics::g_metrics.lock()->metrics_enabled())
{
System::print2(System::Color::warning,
"Warning: passed either --sendmetrics or --no-sendmetrics, but metrics are disabled.\n");
}
- if (args.printmetrics.has_value() && !Metrics::g_metrics.lock()->metrics_enabled())
+ if (args.print_metrics.has_value() && !Metrics::g_metrics.lock()->metrics_enabled())
{
System::print2(System::Color::warning,
"Warning: passed either --printmetrics or --no-printmetrics, but metrics are disabled.\n");
@@ -361,14 +284,14 @@ int main(const int argc, const char* const* const argv)
if (Debug::g_debugging)
{
- inner(args);
+ inner(fs, args);
Checks::exit_fail(VCPKG_LINE_INFO);
}
std::string exc_msg;
try
{
- inner(args);
+ inner(fs, args);
Checks::exit_fail(VCPKG_LINE_INFO);
}
catch (std::exception& e)