Setting: Remove "Tag" template argument

This commit is contained in:
Eelco Dolstra 2017-04-20 16:52:53 +02:00
parent f05d5f89ff
commit 4410e9d995
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
5 changed files with 90 additions and 74 deletions

View file

@ -73,7 +73,7 @@ unsigned int Settings::getDefaultCores()
const string nixVersion = PACKAGE_VERSION;
template<> void Setting<SandboxMode>::set(const std::string & str)
template<> void BaseSetting<SandboxMode>::set(const std::string & str)
{
if (str == "true") value = smEnabled;
else if (str == "relaxed") value = smRelaxed;
@ -81,7 +81,7 @@ template<> void Setting<SandboxMode>::set(const std::string & str)
else throw UsageError("option '%s' has invalid value '%s'", name, str);
}
template<> std::string Setting<SandboxMode>::to_string()
template<> std::string BaseSetting<SandboxMode>::to_string()
{
if (value == smEnabled) return "true";
else if (value == smRelaxed) return "relaxed";
@ -89,27 +89,11 @@ template<> std::string Setting<SandboxMode>::to_string()
else abort();
}
template<> void Setting<unsigned int, Settings::MaxBuildJobsTag>::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<unsigned int, Settings::MaxBuildJobsTag>::to_string()
{
return std::to_string(value);
}
template<> void Setting<bool, Settings::CaseHackTag>::set(const std::string & str)
{
value = parseBool(str);
nix::useCaseHack = true;
}
template<> std::string Setting<bool, Settings::CaseHackTag>::to_string()
{
return printBool(value);
}
}

View file

@ -13,6 +13,39 @@ typedef enum { smEnabled, smRelaxed, smDisabled } SandboxMode;
extern bool useCaseHack; // FIXME
struct CaseHackSetting : public BaseSetting<bool>
{
CaseHackSetting(Config * options,
const std::string & name,
const std::string & description,
const std::set<std::string> & aliases = {})
: BaseSetting<bool>(useCaseHack, name, description, aliases)
{
options->addSetting(this);
}
void set(const std::string & str) override
{
BaseSetting<bool>::set(str);
nix::useCaseHack = true;
}
};
struct MaxBuildJobsSetting : public BaseSetting<unsigned int>
{
MaxBuildJobsSetting(Config * options,
unsigned int def,
const std::string & name,
const std::string & description,
const std::set<std::string> & aliases = {})
: BaseSetting<unsigned int>(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<unsigned int, MaxBuildJobsTag> 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<unsigned int> buildCores{this, getDefaultCores(), "build-cores",
@ -268,8 +300,7 @@ public:
Setting<bool> enableImportFromDerivation{this, true, "allow-import-from-derivation",
"Whether the evaluator allows importing the result of a derivation."};
struct CaseHackTag { };
Setting<bool, CaseHackTag> 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<unsigned long> connectTimeout{this, 0, "connect-timeout",