From 5d4686bcd5600c3071e91bd53338bcb12cd44a54 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 9 Aug 2024 02:07:18 +0200 Subject: libutil: allow marking settings as deprecated this is a bit of a hack, but it's apparently the cleanest way of doing this in the absence of any kind of priority/provenance information for values of some given setting. we'll need this to deprecate build-hook. Change-Id: I03644a9c3f17681c052ecdc610b4f1301266ab9e --- src/libutil/config-impl.hh | 10 +++++++--- src/libutil/config.hh | 26 +++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/libutil/config-impl.hh b/src/libutil/config-impl.hh index 756175f95..8e3a1e408 100644 --- a/src/libutil/config-impl.hh +++ b/src/libutil/config-impl.hh @@ -66,9 +66,13 @@ void BaseSetting::appendOrSet(T newValue, bool append) template void BaseSetting::set(const std::string & str, bool append) { - if (experimentalFeatureSettings.isEnabled(experimentalFeature)) - appendOrSet(parse(str), append); - else { + if (experimentalFeatureSettings.isEnabled(experimentalFeature)) { + auto parsed = parse(str); + if (deprecated && (append || parsed != value)) { + warn("deprecated setting '%s' found (set to '%s')", name, str); + } + appendOrSet(std::move(parsed), append); + } else { assert(experimentalFeature); warn("Ignoring setting '%s' because experimental feature '%s' is not enabled", name, diff --git a/src/libutil/config.hh b/src/libutil/config.hh index 8a4d24456..d7bf9cdc9 100644 --- a/src/libutil/config.hh +++ b/src/libutil/config.hh @@ -175,6 +175,10 @@ class AbstractSetting public: + struct deprecated_t { + explicit deprecated_t() = default; + }; + const std::string name; const std::string description; const std::set aliases; @@ -225,6 +229,7 @@ protected: T value; const T defaultValue; const bool documentDefault; + const bool deprecated; /** * Parse the string into a `T`. @@ -250,11 +255,13 @@ public: const std::string & name, const std::string & description, const std::set & aliases = {}, - std::optional experimentalFeature = std::nullopt) + std::optional experimentalFeature = std::nullopt, + bool deprecated = false) : AbstractSetting(name, description, aliases, experimentalFeature) , value(def) , defaultValue(def) , documentDefault(documentDefault) + , deprecated(deprecated) { } operator const T &() const { return value; } @@ -322,12 +329,25 @@ public: const std::string & description, const std::set & aliases = {}, const bool documentDefault = true, - std::optional experimentalFeature = std::nullopt) - : BaseSetting(def, documentDefault, name, description, aliases, std::move(experimentalFeature)) + std::optional experimentalFeature = std::nullopt, + bool deprecated = false) + : BaseSetting(def, documentDefault, name, description, aliases, std::move(experimentalFeature), deprecated) { options->addSetting(this); } + Setting(AbstractSetting::deprecated_t, + Config * options, + const T & def, + const std::string & name, + const std::string & description, + const std::set & aliases = {}, + const bool documentDefault = true, + std::optional experimentalFeature = std::nullopt) + : Setting(options, def, name, description, aliases, documentDefault, std::move(experimentalFeature), true) + { + } + void operator =(const T & v) { this->assign(v); } }; -- cgit v1.2.3