From 4410e9d995bcd53a7a4cff0bbee3917375adcba3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 20 Apr 2017 16:52:53 +0200 Subject: Setting: Remove "Tag" template argument --- src/libstore/globals.cc | 22 +++------------------- src/libstore/globals.hh | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 23 deletions(-) (limited to 'src/libstore') diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index 6b9d07746..3242ef9d6 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -73,7 +73,7 @@ unsigned int Settings::getDefaultCores() const string nixVersion = PACKAGE_VERSION; -template<> void Setting::set(const std::string & str) +template<> void BaseSetting::set(const std::string & str) { if (str == "true") value = smEnabled; else if (str == "relaxed") value = smRelaxed; @@ -81,7 +81,7 @@ template<> void Setting::set(const std::string & str) else throw UsageError("option '%s' has invalid value '%s'", name, str); } -template<> std::string Setting::to_string() +template<> std::string BaseSetting::to_string() { if (value == smEnabled) return "true"; else if (value == smRelaxed) return "relaxed"; @@ -89,27 +89,11 @@ template<> std::string Setting::to_string() else abort(); } -template<> void Setting::set(const std::string & str) +void MaxBuildJobsSetting::set(const std::string & str) { if (str == "auto") value = std::max(1U, std::thread::hardware_concurrency()); else if (!string2Int(str, value)) throw UsageError("configuration setting ‘%s’ should be ‘auto’ or an integer", name); } -template<> std::string Setting::to_string() -{ - return std::to_string(value); -} - -template<> void Setting::set(const std::string & str) -{ - value = parseBool(str); - nix::useCaseHack = true; -} - -template<> std::string Setting::to_string() -{ - return printBool(value); -} - } diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index d3ecaadb6..b4f44de2e 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -13,6 +13,39 @@ typedef enum { smEnabled, smRelaxed, smDisabled } SandboxMode; extern bool useCaseHack; // FIXME +struct CaseHackSetting : public BaseSetting +{ + CaseHackSetting(Config * options, + const std::string & name, + const std::string & description, + const std::set & aliases = {}) + : BaseSetting(useCaseHack, name, description, aliases) + { + options->addSetting(this); + } + + void set(const std::string & str) override + { + BaseSetting::set(str); + nix::useCaseHack = true; + } +}; + +struct MaxBuildJobsSetting : public BaseSetting +{ + MaxBuildJobsSetting(Config * options, + unsigned int def, + const std::string & name, + const std::string & description, + const std::set & aliases = {}) + : BaseSetting(def, name, description, aliases) + { + options->addSetting(this); + } + + void set(const std::string & str) override; +}; + class Settings : public Config { unsigned int getDefaultCores(); @@ -66,8 +99,7 @@ public: the log to show if a build fails. */ size_t logLines = 10; - struct MaxBuildJobsTag { }; - Setting maxBuildJobs{this, 1, "build-max-jobs", + MaxBuildJobsSetting maxBuildJobs{this, 1, "build-max-jobs", "Maximum number of parallel build jobs. \"auto\" means use number of cores."}; Setting buildCores{this, getDefaultCores(), "build-cores", @@ -268,8 +300,7 @@ public: Setting enableImportFromDerivation{this, true, "allow-import-from-derivation", "Whether the evaluator allows importing the result of a derivation."}; - struct CaseHackTag { }; - Setting useCaseHack{this, nix::useCaseHack, "use-case-hack", + CaseHackSetting useCaseHack{this, "use-case-hack", "Whether to enable a Darwin-specific hack for dealing with file name collisions."}; Setting connectTimeout{this, 0, "connect-timeout", -- cgit v1.2.3