aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
authornicole mazzuca <mazzucan@outlook.com>2020-05-29 14:09:03 -0700
committerGitHub <noreply@github.com>2020-05-29 14:09:03 -0700
commit09319cd79e3bee6a41bb76db739aef3f3644f19f (patch)
tree36e6b5bd5c17268edc062aa9c462f47fc4f400cf /toolsrc/include
parenta64dc07690bc8806e717e190f62eb58e198b599c (diff)
downloadvcpkg-09319cd79e3bee6a41bb76db739aef3f3644f19f.tar.gz
vcpkg-09319cd79e3bee6a41bb76db739aef3f3644f19f.zip
[vcpkg metrics] Allow someone to opt out after build (#11542)
* [vcpkg metrics] start using json library Additionally, add floats to the JSON library since they're required. * [vcpkg metrics] allow users to disable metrics after the build Additionally, as a drive by, fix UUID generation * fix metrics data * code review
Diffstat (limited to 'toolsrc/include')
-rw-r--r--toolsrc/include/pch.h10
-rw-r--r--toolsrc/include/vcpkg/base/json.h67
-rw-r--r--toolsrc/include/vcpkg/metrics.h4
-rw-r--r--toolsrc/include/vcpkg/vcpkgcmdarguments.h2
4 files changed, 60 insertions, 23 deletions
diff --git a/toolsrc/include/pch.h b/toolsrc/include/pch.h
index e23230f6e..46ba6fa37 100644
--- a/toolsrc/include/pch.h
+++ b/toolsrc/include/pch.h
@@ -9,6 +9,12 @@
#include <winhttp.h>
#endif
+#include <math.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+
#include <algorithm>
#include <array>
#include <atomic>
@@ -16,10 +22,6 @@
#include <cctype>
#include <chrono>
#include <codecvt>
-#include <cstdarg>
-#include <cstddef>
-#include <cstdint>
-#include <cstring>
#if VCPKG_USE_STD_FILESYSTEM
#include <filesystem>
diff --git a/toolsrc/include/vcpkg/base/json.h b/toolsrc/include/vcpkg/base/json.h
index 2a1808857..69502fedc 100644
--- a/toolsrc/include/vcpkg/base/json.h
+++ b/toolsrc/include/vcpkg/base/json.h
@@ -70,6 +70,7 @@ namespace vcpkg::Json
{
Null,
Boolean,
+ Integer,
Number,
String,
Array,
@@ -84,10 +85,19 @@ namespace vcpkg::Json
struct Value
{
+ Value() noexcept; // equivalent to Value::null()
+ Value(Value&&) noexcept;
+ Value& operator=(Value&&) noexcept;
+ ~Value();
+
+ Value clone() const noexcept;
+
ValueKind kind() const noexcept;
bool is_null() const noexcept;
bool is_boolean() const noexcept;
+ bool is_integer() const noexcept;
+ // either integer _or_ number
bool is_number() const noexcept;
bool is_string() const noexcept;
bool is_array() const noexcept;
@@ -95,7 +105,8 @@ namespace vcpkg::Json
// a.x() asserts when !a.is_x()
bool boolean() const noexcept;
- int64_t number() const noexcept;
+ int64_t integer() const noexcept;
+ double number() const noexcept;
StringView string() const noexcept;
const Array& array() const noexcept;
@@ -104,18 +115,13 @@ namespace vcpkg::Json
const Object& object() const noexcept;
Object& object() noexcept;
- Value(Value&&) noexcept;
- Value& operator=(Value&&) noexcept;
- ~Value();
-
- Value() noexcept; // equivalent to Value::null()
static Value null(std::nullptr_t) noexcept;
static Value boolean(bool) noexcept;
- static Value number(int64_t i) noexcept;
+ static Value integer(int64_t i) noexcept;
+ static Value number(double d) noexcept;
static Value string(StringView) noexcept;
static Value array(Array&&) noexcept;
static Value object(Object&&) noexcept;
- Value clone() const noexcept;
private:
friend struct impl::ValueImpl;
@@ -128,11 +134,24 @@ namespace vcpkg::Json
using underlying_t = std::vector<Value>;
public:
+ Array() = default;
+ Array(Array const&) = delete;
+ Array(Array&&) = default;
+ Array& operator=(Array const&) = delete;
+ Array& operator=(Array&&) = default;
+ ~Array() = default;
+
+ Array clone() const noexcept;
+
using iterator = underlying_t::iterator;
using const_iterator = underlying_t::const_iterator;
- void push_back(Value&& value) { this->underlying_.push_back(std::move(value)); }
- void insert_before(iterator it, Value&& value) { this->underlying_.insert(it, std::move(value)); }
+ Value& push_back(Value&& value);
+ Object& push_back(Object&& value);
+ Array& push_back(Array&& value);
+ Value& insert_before(iterator it, Value&& value);
+ Object& insert_before(iterator it, Object&& value);
+ Array& insert_before(iterator it, Array&& value);
std::size_t size() const noexcept { return this->underlying_.size(); }
@@ -148,8 +167,6 @@ namespace vcpkg::Json
return this->underlying_[idx];
}
- Array clone() const noexcept;
-
iterator begin() { return underlying_.begin(); }
iterator end() { return underlying_.end(); }
const_iterator begin() const { return cbegin(); }
@@ -160,7 +177,6 @@ namespace vcpkg::Json
private:
underlying_t underlying_;
};
-
struct Object
{
private:
@@ -169,12 +185,26 @@ namespace vcpkg::Json
underlying_t::const_iterator internal_find_key(StringView key) const noexcept;
public:
+ // these are here for better diagnostics
+ Object() = default;
+ Object(Object const&) = delete;
+ Object(Object&&) = default;
+ Object& operator=(Object const&) = delete;
+ Object& operator=(Object&&) = default;
+ ~Object() = default;
+
+ Object clone() const noexcept;
+
// asserts if the key is found
- void insert(std::string key, Value value) noexcept;
+ Value& insert(std::string key, Value&& value);
+ Object& insert(std::string key, Object&& value);
+ Array& insert(std::string key, Array&& value);
// replaces the value if the key is found, otherwise inserts a new
// value.
- void insert_or_replace(std::string key, Value value) noexcept;
+ Value& insert_or_replace(std::string key, Value&& value);
+ Object& insert_or_replace(std::string key, Object&& value);
+ Array& insert_or_replace(std::string key, Array&& value);
// returns whether the key existed
bool remove(StringView key) noexcept;
@@ -200,8 +230,6 @@ namespace vcpkg::Json
std::size_t size() const noexcept { return this->underlying_.size(); }
- Object clone() const noexcept;
-
struct const_iterator
{
using value_type = std::pair<StringView, const Value&>;
@@ -245,6 +273,9 @@ namespace vcpkg::Json
const Files::Filesystem&, const fs::path&, std::error_code& ec) noexcept;
ExpectedT<std::pair<Value, JsonStyle>, std::unique_ptr<Parse::IParseError>> parse(
StringView text, const fs::path& filepath = "") noexcept;
- std::string stringify(const Value&, JsonStyle style) noexcept;
+
+ std::string stringify(const Value&, JsonStyle style);
+ std::string stringify(const Object&, JsonStyle style);
+ std::string stringify(const Array&, JsonStyle style);
}
diff --git a/toolsrc/include/vcpkg/metrics.h b/toolsrc/include/vcpkg/metrics.h
index cb27ba58d..c56a227f3 100644
--- a/toolsrc/include/vcpkg/metrics.h
+++ b/toolsrc/include/vcpkg/metrics.h
@@ -10,6 +10,7 @@ namespace vcpkg::Metrics
{
void set_send_metrics(bool should_send_metrics);
void set_print_metrics(bool should_print_metrics);
+ void set_disabled(bool disabled);
void set_user_information(const std::string& user_id, const std::string& first_use_time);
static void init_user_information(std::string& user_id, std::string& first_use_time);
@@ -17,6 +18,8 @@ namespace vcpkg::Metrics
void track_buildtime(const std::string& name, double value);
void track_property(const std::string& name, const std::string& value);
+ bool metrics_enabled();
+
void upload(const std::string& payload);
void flush();
};
@@ -24,5 +27,4 @@ namespace vcpkg::Metrics
extern Util::LockGuarded<Metrics> g_metrics;
std::string get_MAC_user();
- bool get_compiled_metrics_enabled();
}
diff --git a/toolsrc/include/vcpkg/vcpkgcmdarguments.h b/toolsrc/include/vcpkg/vcpkgcmdarguments.h
index 92584fc6a..f8602b1e9 100644
--- a/toolsrc/include/vcpkg/vcpkgcmdarguments.h
+++ b/toolsrc/include/vcpkg/vcpkgcmdarguments.h
@@ -94,6 +94,8 @@ namespace vcpkg
std::vector<std::string> binarysources;
Optional<bool> debug = nullopt;
Optional<bool> sendmetrics = nullopt;
+ // fully disable metrics -- both printing and sending
+ Optional<bool> disable_metrics = nullopt;
Optional<bool> printmetrics = nullopt;
// feature flags