diff options
| author | Billy O'Neal <bion@microsoft.com> | 2021-01-13 14:06:06 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-13 14:06:06 -0800 |
| commit | 8414e15973097e70fe40149e922c402799804b3d (patch) | |
| tree | ca46f3f317f0eef7924f3b76828868d51bb249cf /toolsrc/src/vcpkg.cpp | |
| parent | 4da47f758fb5e02fc017047e014d15174b85a848 (diff) | |
| download | vcpkg-8414e15973097e70fe40149e922c402799804b3d.tar.gz vcpkg-8414e15973097e70fe40149e922c402799804b3d.zip | |
[vcpkg] Use a tag file rather than conditional compilation to permanently disable metrics. (#15470)
Diffstat (limited to 'toolsrc/src/vcpkg.cpp')
| -rw-r--r-- | toolsrc/src/vcpkg.cpp | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index f128210fd..f3a6ac6a0 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -227,24 +227,40 @@ int main(const int argc, const char* const* const argv) #endif VcpkgCmdArguments args = VcpkgCmdArguments::create_from_command_line(fs, argc, argv); + if (const auto p = args.debug.get()) Debug::g_debugging = *p; args.imbue_from_environment(); args.check_feature_flag_consistency(); - if (const auto p = args.disable_metrics.get()) Metrics::g_metrics.lock()->set_disabled(*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.debug.get()) Debug::g_debugging = *p; - - 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.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"); - } + auto metrics = Metrics::g_metrics.lock(); + if (const auto p = args.disable_metrics.get()) + { + metrics->set_disabled(*p); + } + + auto disable_metrics_tag_file_path = + System::get_exe_path_of_current_process().replace_filename(fs::u8path("vcpkg.disable-metrics")); + std::error_code ec; + if (fs.exists(disable_metrics_tag_file_path, ec) || ec) + { + metrics->set_disabled(true); + } + + if (const auto p = args.print_metrics.get()) + { + metrics->set_print_metrics(*p); + } + + if (const auto p = args.send_metrics.get()) + { + metrics->set_send_metrics(*p); + } + + if (args.send_metrics.value_or(true) && !metrics->metrics_enabled()) + { + System::print2(System::Color::warning, "Warning: passed --sendmetrics, but metrics are disabled.\n"); + } + } // unlock Metrics::g_metrics args.debug_print_feature_flags(); args.track_feature_flag_metrics(); |
