[vcpkg] Use a tag file rather than conditional compilation to permanently disable metrics.
MODIFY
CMakeLists.txt
CMakeLists.txt
@@ -15,7 +15,6 @@ include(cmake/utilities.cmake)
include(CMakeDependentOption)
option(BUILD_TESTING "Option for enabling testing" ON)
-option(VCPKG_DISABLE_METRICS "Option for disabling metrics" OFF)
option(VCPKG_ALLOW_APPLE_CLANG "Option for allowing apple clang, even versions that we don't know will work" OFF)
option(VCPKG_DEVELOPMENT_WARNINGS "Option for turning on all warnings" ON)
option(VCPKG_WARNINGS_AS_ERRORS "Set warnings to be errors" ${VCPKG_DEVELOPMENT_WARNINGS})
@@ -28,9 +27,9 @@ CMAKE_DEPENDENT_OPTION(VCPKG_BUILD_BENCHMARKING "Option for enabling benchmarkin
if(WERROR)
message(DEPRECATION "-DWERROR is no longer a supported flag. It doesn't do anything.")
endif()
-if(DEFINE_DISABLE_METRICS)
- message(DEPRECATION "DEFINE_DISABLE_METRICS is now called VCPKG_DISABLE_METRICS.")
- set(VCPKG_DISABLE_METRICS ${DEFINE_DISABLE_METRICS} CACHE BOOL "Option for disabling metrics" FORCE)
+if(DEFINE_DISABLE_METRICS OR VCPKG_DISABLE_METRICS)
+ message(DEPRECATION "DEFINE_DISABLE_METRICS / VCPKG_DISABLE_METRICS are now handled by creating a "
+ "file vcpkg.disable_metrics next to the binary.")
endif()
# =============

MODIFY
include/vcpkg/commands.upload-metrics.h
include/vcpkg/commands.upload-metrics.h
#pragma once
-#if !VCPKG_DISABLE_METRICS && defined(_WIN32)
-#define VCPKG_ENABLE_X_UPLOAD_METRICS_COMMAND 1
-#else
-#define VCPKG_ENABLE_X_UPLOAD_METRICS_COMMAND 0
-#endif // !VCPKG_DISABLE_METRICS && defined(_WIN32)
-
-#if VCPKG_ENABLE_X_UPLOAD_METRICS_COMMAND
-
#include <vcpkg/commands.interface.h>
namespace vcpkg::Commands::UploadMetrics
@@ -18,5 +10,3 @@ namespace vcpkg::Commands::UploadMetrics
virtual void perform_and_exit(const VcpkgCmdArguments& args, Files::Filesystem& fs) const override;
};
}
-
-#endif // VCPKG_ENABLE_X_UPLOAD_METRICS_COMMAND

MODIFY
src/vcpkg.cpp
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;
+ {
+ auto metrics = Metrics::g_metrics.lock();
+ if (const auto p = args.disable_metrics.get())
+ {
+ metrics->set_disabled(*p);
+ }
- if (args.send_metrics.has_value() && !Metrics::g_metrics.lock()->metrics_enabled())
+ 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)
{
- System::print2(System::Color::warning,
- "Warning: passed either --sendmetrics or --no-sendmetrics, but metrics are disabled.\n");
+ metrics->set_disabled(true);
}
- if (args.print_metrics.has_value() && !Metrics::g_metrics.lock()->metrics_enabled())
+
+ 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 either --printmetrics or --no-printmetrics, but metrics are disabled.\n");
+ 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();

MODIFY
src/vcpkg/metrics.cpp
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)
{

MODIFY
windows-bootstrap/vcpkg.vcxproj
windows-bootstrap/vcpkg.vcxproj
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>VCPKG_DISABLE_METRICS=$(DISABLE_METRICS);VCPKG_VERSION=$(VCPKG_VERSION);_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>VCPKG_VERSION=$(VCPKG_VERSION);_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>/std:c++latest %(AdditionalOptions)</AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>VCPKG_DISABLE_METRICS=$(DISABLE_METRICS);VCPKG_VERSION=$(VCPKG_VERSION);_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>VCPKG_VERSION=$(VCPKG_VERSION);_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>/std:c++latest %(AdditionalOptions)</AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>VCPKG_DISABLE_METRICS=$(DISABLE_METRICS);VCPKG_VERSION=$(VCPKG_VERSION);_MBCS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>VCPKG_VERSION=$(VCPKG_VERSION);_MBCS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_MBCS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>/std:c++latest %(AdditionalOptions)</AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\include</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>VCPKG_DISABLE_METRICS=$(DISABLE_METRICS);VCPKG_VERSION=$(VCPKG_VERSION);_MBCS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>VCPKG_VERSION=$(VCPKG_VERSION);_MBCS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_MBCS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>/std:c++latest %(AdditionalOptions)</AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>

[vcpkg] Use a tag file rather than conditional compilation to permanently disable metrics. (#15470)