aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src
diff options
context:
space:
mode:
authorBilly O'Neal <bion@microsoft.com>2021-01-13 14:06:06 -0800
committerGitHub <noreply@github.com>2021-01-13 14:06:06 -0800
commit8414e15973097e70fe40149e922c402799804b3d (patch)
treeca46f3f317f0eef7924f3b76828868d51bb249cf /toolsrc/src
parent4da47f758fb5e02fc017047e014d15174b85a848 (diff)
downloadvcpkg-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')
-rw-r--r--toolsrc/src/vcpkg.cpp44
-rw-r--r--toolsrc/src/vcpkg/metrics.cpp19
2 files changed, 33 insertions, 30 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();
diff --git a/toolsrc/src/vcpkg/metrics.cpp b/toolsrc/src/vcpkg/metrics.cpp
index fd5abea4b..9e9f43c15 100644
--- a/toolsrc/src/vcpkg/metrics.cpp
+++ b/toolsrc/src/vcpkg/metrics.cpp
@@ -240,20 +240,14 @@ namespace vcpkg::Metrics
static MetricMessage g_metricmessage;
static bool g_should_send_metrics =
-#if defined(NDEBUG) && (VCPKG_DISABLE_METRICS == 0)
+#if defined(NDEBUG)
true
#else
false
#endif
;
static bool g_should_print_metrics = false;
- static bool g_metrics_disabled =
-#if VCPKG_DISABLE_METRICS
- true
-#else
- false
-#endif
- ;
+ static bool g_metrics_disabled = false;
std::string get_MAC_user()
{
@@ -305,14 +299,7 @@ namespace vcpkg::Metrics
void Metrics::set_disabled(bool disabled) { g_metrics_disabled = disabled; }
- bool Metrics::metrics_enabled()
- {
-#if VCPKG_DISABLE_METRICS
- return false;
-#else
- return !g_metrics_disabled;
-#endif
- }
+ bool Metrics::metrics_enabled() { return !g_metrics_disabled; }
void Metrics::track_metric(const std::string& name, double value)
{