Optionally ignore null-valued derivation attributes
This allows adding attributes like attr = if stdenv.system == "bla" then something else null; without changing the resulting derivation on non-<bla> platforms. We once considered adding a special "ignore" value for this purpose, but using null seems more elegant.
This commit is contained in:
parent
8b8ee53bc7
commit
6c98e6a5de
3 changed files with 24 additions and 11 deletions
|
@ -139,6 +139,7 @@ EvalState::EvalState()
|
||||||
, sSystem(symbols.create("system"))
|
, sSystem(symbols.create("system"))
|
||||||
, sOverrides(symbols.create("__overrides"))
|
, sOverrides(symbols.create("__overrides"))
|
||||||
, sOutputName(symbols.create("outputName"))
|
, sOutputName(symbols.create("outputName"))
|
||||||
|
, sIgnoreNulls(symbols.create("__ignoreNulls"))
|
||||||
, baseEnv(allocEnv(128))
|
, baseEnv(allocEnv(128))
|
||||||
, baseEnvDispl(0)
|
, baseEnvDispl(0)
|
||||||
, staticBaseEnv(false, 0)
|
, staticBaseEnv(false, 0)
|
||||||
|
|
|
@ -93,7 +93,7 @@ public:
|
||||||
SymbolTable symbols;
|
SymbolTable symbols;
|
||||||
|
|
||||||
const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName,
|
const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName,
|
||||||
sSystem, sOverrides, sOutputName;
|
sSystem, sOverrides, sOutputName, sIgnoreNulls;
|
||||||
|
|
||||||
/* If set, force copying files to the Nix store even if they
|
/* If set, force copying files to the Nix store even if they
|
||||||
already exist there. */
|
already exist there. */
|
||||||
|
|
|
@ -317,6 +317,12 @@ static void prim_derivationStrict(EvalState & state, Value * * args, Value & v)
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check whether null attributes should be ignored. */
|
||||||
|
bool ignoreNulls = false;
|
||||||
|
attr = args[0]->attrs->find(state.sIgnoreNulls);
|
||||||
|
if (attr != args[0]->attrs->end())
|
||||||
|
ignoreNulls = state.forceBool(*attr->value);
|
||||||
|
|
||||||
/* Build the derivation expression by processing the attributes. */
|
/* Build the derivation expression by processing the attributes. */
|
||||||
Derivation drv;
|
Derivation drv;
|
||||||
|
|
||||||
|
@ -329,11 +335,17 @@ static void prim_derivationStrict(EvalState & state, Value * * args, Value & v)
|
||||||
outputs.insert("out");
|
outputs.insert("out");
|
||||||
|
|
||||||
foreach (Bindings::iterator, i, *args[0]->attrs) {
|
foreach (Bindings::iterator, i, *args[0]->attrs) {
|
||||||
|
if (i->name == state.sIgnoreNulls) continue;
|
||||||
string key = i->name;
|
string key = i->name;
|
||||||
startNest(nest, lvlVomit, format("processing attribute `%1%'") % key);
|
startNest(nest, lvlVomit, format("processing attribute `%1%'") % key);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
if (ignoreNulls) {
|
||||||
|
state.forceValue(*i->value);
|
||||||
|
if (i->value->type == tNull) continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* The `args' attribute is special: it supplies the
|
/* The `args' attribute is special: it supplies the
|
||||||
command-line arguments to the builder. */
|
command-line arguments to the builder. */
|
||||||
if (key == "args") {
|
if (key == "args") {
|
||||||
|
|
Loading…
Reference in a new issue