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
This commit is contained in:
eldritch horrors 2024-08-09 02:07:18 +02:00
parent baa4fda340
commit 5d4686bcd5
2 changed files with 30 additions and 6 deletions

View file

@ -66,9 +66,13 @@ void BaseSetting<T>::appendOrSet(T newValue, bool append)
template<typename T> template<typename T>
void BaseSetting<T>::set(const std::string & str, bool append) void BaseSetting<T>::set(const std::string & str, bool append)
{ {
if (experimentalFeatureSettings.isEnabled(experimentalFeature)) if (experimentalFeatureSettings.isEnabled(experimentalFeature)) {
appendOrSet(parse(str), append); auto parsed = parse(str);
else { if (deprecated && (append || parsed != value)) {
warn("deprecated setting '%s' found (set to '%s')", name, str);
}
appendOrSet(std::move(parsed), append);
} else {
assert(experimentalFeature); assert(experimentalFeature);
warn("Ignoring setting '%s' because experimental feature '%s' is not enabled", warn("Ignoring setting '%s' because experimental feature '%s' is not enabled",
name, name,

View file

@ -175,6 +175,10 @@ class AbstractSetting
public: public:
struct deprecated_t {
explicit deprecated_t() = default;
};
const std::string name; const std::string name;
const std::string description; const std::string description;
const std::set<std::string> aliases; const std::set<std::string> aliases;
@ -225,6 +229,7 @@ protected:
T value; T value;
const T defaultValue; const T defaultValue;
const bool documentDefault; const bool documentDefault;
const bool deprecated;
/** /**
* Parse the string into a `T`. * Parse the string into a `T`.
@ -250,11 +255,13 @@ public:
const std::string & name, const std::string & name,
const std::string & description, const std::string & description,
const std::set<std::string> & aliases = {}, const std::set<std::string> & aliases = {},
std::optional<ExperimentalFeature> experimentalFeature = std::nullopt) std::optional<ExperimentalFeature> experimentalFeature = std::nullopt,
bool deprecated = false)
: AbstractSetting(name, description, aliases, experimentalFeature) : AbstractSetting(name, description, aliases, experimentalFeature)
, value(def) , value(def)
, defaultValue(def) , defaultValue(def)
, documentDefault(documentDefault) , documentDefault(documentDefault)
, deprecated(deprecated)
{ } { }
operator const T &() const { return value; } operator const T &() const { return value; }
@ -322,12 +329,25 @@ public:
const std::string & description, const std::string & description,
const std::set<std::string> & aliases = {}, const std::set<std::string> & aliases = {},
const bool documentDefault = true, const bool documentDefault = true,
std::optional<ExperimentalFeature> experimentalFeature = std::nullopt) std::optional<ExperimentalFeature> experimentalFeature = std::nullopt,
: BaseSetting<T>(def, documentDefault, name, description, aliases, std::move(experimentalFeature)) bool deprecated = false)
: BaseSetting<T>(def, documentDefault, name, description, aliases, std::move(experimentalFeature), deprecated)
{ {
options->addSetting(this); options->addSetting(this);
} }
Setting(AbstractSetting::deprecated_t,
Config * options,
const T & def,
const std::string & name,
const std::string & description,
const std::set<std::string> & aliases = {},
const bool documentDefault = true,
std::optional<ExperimentalFeature> experimentalFeature = std::nullopt)
: Setting(options, def, name, description, aliases, documentDefault, std::move(experimentalFeature), true)
{
}
void operator =(const T & v) { this->assign(v); } void operator =(const T & v) { this->assign(v); }
}; };