summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-10-04 15:22:25 -0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-10-04 15:22:25 -0400
commit70f75be199d8db959d313dc40111893fba56415f (patch)
treef099812cc963ba6e1235a3cea95b32a0a83c0f47
parentad328bea15e2708e5aa784c33ba8bfbc86d02e0d (diff)
downloadguix-70f75be199d8db959d313dc40111893fba56415f.tar.gz
getDerivation(): Don't always quietly ignore assertion failure
Ignoring assertion failures makes some sense for nix-env -qa, but not
for nix-instantiate/nix-build or hydra-eval-jobs.
-rw-r--r--src/libexpr/get-drvs.cc30
-rw-r--r--src/libexpr/get-drvs.hh6
-rw-r--r--src/nix-env/nix-env.cc6
-rw-r--r--src/nix-env/user-env.cc4
-rw-r--r--src/nix-instantiate/nix-instantiate.cc2
5 files changed, 27 insertions, 21 deletions
diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc
index 6670d0636a..f9e7dc6dbe 100644
--- a/src/libexpr/get-drvs.cc
+++ b/src/libexpr/get-drvs.cc
@@ -84,7 +84,8 @@ typedef set<Bindings *> Done;
    makes sense for the caller to recursively search for derivations in
    `v'. */
 static bool getDerivation(EvalState & state, Value & v,
-    const string & attrPath, DrvInfos & drvs, Done & done)
+    const string & attrPath, DrvInfos & drvs, Done & done,
+    bool ignoreAssertionFailures)
 {
     try {
         state.forceValue(v);
@@ -116,16 +117,18 @@ static bool getDerivation(EvalState & state, Value & v,
         return false;
     
     } catch (AssertionError & e) {
-        return false;
+        if (ignoreAssertionFailures) return false;
+        throw;
     }
 }
 
 
-bool getDerivation(EvalState & state, Value & v, DrvInfo & drv)
+bool getDerivation(EvalState & state, Value & v, DrvInfo & drv,
+    bool ignoreAssertionFailures)
 {
     Done done;
     DrvInfos drvs;
-    getDerivation(state, v, "", drvs, done);
+    getDerivation(state, v, "", drvs, done, ignoreAssertionFailures);
     if (drvs.size() != 1) return false;
     drv = drvs.front();
     return true;
@@ -140,7 +143,8 @@ static string addToPath(const string & s1, const string & s2)
 
 static void getDerivations(EvalState & state, Value & vIn,
     const string & pathPrefix, Bindings & autoArgs,
-    DrvInfos & drvs, Done & done)
+    DrvInfos & drvs, Done & done,
+    bool ignoreAssertionFailures)
 {
     Value v;
     state.autoCallFunction(autoArgs, vIn, v);
@@ -148,7 +152,7 @@ static void getDerivations(EvalState & state, Value & vIn,
     /* Process the expression. */
     DrvInfo drv;
 
-    if (!getDerivation(state, v, pathPrefix, drvs, done)) ;
+    if (!getDerivation(state, v, pathPrefix, drvs, done, ignoreAssertionFailures)) ;
 
     else if (v.type == tAttrs) {
 
@@ -171,8 +175,8 @@ static void getDerivations(EvalState & state, Value & vIn,
             string pathPrefix2 = addToPath(pathPrefix, i->first);
             Value & v2(*v.attrs->find(i->second)->value);
             if (combineChannels)
-                getDerivations(state, v2, pathPrefix2, autoArgs, drvs, done);
-            else if (getDerivation(state, v2, pathPrefix2, drvs, done)) {
+                getDerivations(state, v2, pathPrefix2, autoArgs, drvs, done, ignoreAssertionFailures);
+            else if (getDerivation(state, v2, pathPrefix2, drvs, done, ignoreAssertionFailures)) {
                 /* If the value of this attribute is itself an
                    attribute set, should we recurse into it?  => Only
                    if it has a `recurseForDerivations = true'
@@ -180,7 +184,7 @@ static void getDerivations(EvalState & state, Value & vIn,
                 if (v2.type == tAttrs) {
                     Bindings::iterator j = v2.attrs->find(state.symbols.create("recurseForDerivations"));
                     if (j != v2.attrs->end() && state.forceBool(*j->value))
-                        getDerivations(state, v2, pathPrefix2, autoArgs, drvs, done);
+                        getDerivations(state, v2, pathPrefix2, autoArgs, drvs, done, ignoreAssertionFailures);
                 }
             }
         }
@@ -191,8 +195,8 @@ static void getDerivations(EvalState & state, Value & vIn,
             startNest(nest, lvlDebug,
                 format("evaluating list element"));
             string pathPrefix2 = addToPath(pathPrefix, (format("%1%") % n).str());
-            if (getDerivation(state, *v.list.elems[n], pathPrefix2, drvs, done))
-                getDerivations(state, *v.list.elems[n], pathPrefix2, autoArgs, drvs, done);
+            if (getDerivation(state, *v.list.elems[n], pathPrefix2, drvs, done, ignoreAssertionFailures))
+                getDerivations(state, *v.list.elems[n], pathPrefix2, autoArgs, drvs, done, ignoreAssertionFailures);
         }
     }
 
@@ -201,10 +205,10 @@ static void getDerivations(EvalState & state, Value & vIn,
 
 
 void getDerivations(EvalState & state, Value & v, const string & pathPrefix,
-    Bindings & autoArgs, DrvInfos & drvs)
+    Bindings & autoArgs, DrvInfos & drvs, bool ignoreAssertionFailures)
 {
     Done done;
-    getDerivations(state, v, pathPrefix, autoArgs, drvs, done);
+    getDerivations(state, v, pathPrefix, autoArgs, drvs, done, ignoreAssertionFailures);
 }
 
  
diff --git a/src/libexpr/get-drvs.hh b/src/libexpr/get-drvs.hh
index 25d8baa559..8159417a01 100644
--- a/src/libexpr/get-drvs.hh
+++ b/src/libexpr/get-drvs.hh
@@ -75,10 +75,12 @@ typedef list<DrvInfo> DrvInfos;
 
 /* If value `v' denotes a derivation, store information about the
    derivation in `drv' and return true.  Otherwise, return false. */
-bool getDerivation(EvalState & state, Value & v, DrvInfo & drv);
+bool getDerivation(EvalState & state, Value & v, DrvInfo & drv,
+    bool ignoreAssertionFailures);
 
 void getDerivations(EvalState & state, Value & v, const string & pathPrefix,
-    Bindings & autoArgs, DrvInfos & drvs);
+    Bindings & autoArgs, DrvInfos & drvs,
+    bool ignoreAssertionFailures);
 
  
 }
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index bb6df32d0f..5e171d0a0b 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -166,7 +166,7 @@ static void loadDerivations(EvalState & state, Path nixExprPath,
     Value v;
     findAlongAttrPath(state, pathPrefix, autoArgs, loadSourceExpr(state, nixExprPath), v);
     
-    getDerivations(state, v, pathPrefix, autoArgs, elems);
+    getDerivations(state, v, pathPrefix, autoArgs, elems, true);
 
     /* Filter out all derivations not applicable to the current
        system. */
@@ -362,7 +362,7 @@ static void queryInstSources(EvalState & state,
                 Expr * e2 = state.parseExprFromString(*i, absPath("."));
                 Expr * call = new ExprApp(e2, e1);
                 Value v; state.eval(call, v);
-                getDerivations(state, v, "", instSource.autoArgs, elems);
+                getDerivations(state, v, "", instSource.autoArgs, elems, true);
             }
             
             break;
@@ -417,7 +417,7 @@ static void queryInstSources(EvalState & state,
                 Value v;
                 findAlongAttrPath(state, *i, instSource.autoArgs,
                     loadSourceExpr(state, instSource.nixExprPath), v);
-                getDerivations(state, v, "", instSource.autoArgs, elems);
+                getDerivations(state, v, "", instSource.autoArgs, elems, true);
             }
             break;
         }
diff --git a/src/nix-env/user-env.cc b/src/nix-env/user-env.cc
index d7de179010..5b754bc8ca 100644
--- a/src/nix-env/user-env.cc
+++ b/src/nix-env/user-env.cc
@@ -25,7 +25,7 @@ DrvInfos queryInstalled(EvalState & state, const Path & userEnv)
         Value v;
         state.evalFile(manifestFile, v);
         Bindings bindings;
-        getDerivations(state, v, "", bindings, elems);
+        getDerivations(state, v, "", bindings, elems, false);
     } else if (pathExists(oldManifestFile))
         readLegacyManifest(oldManifestFile, elems);
 
@@ -127,7 +127,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
     /* Evaluate it. */
     debug("evaluating user environment builder");
     DrvInfo topLevelDrv;
-    if (!getDerivation(state, topLevel, topLevelDrv))
+    if (!getDerivation(state, topLevel, topLevelDrv, false))
         abort();
     
     /* Realise the resulting store expression. */
diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc
index 4d8f43507c..ab0c8cf28b 100644
--- a/src/nix-instantiate/nix-instantiate.cc
+++ b/src/nix-instantiate/nix-instantiate.cc
@@ -56,7 +56,7 @@ void processExpr(EvalState & state, const Strings & attrPaths,
                 }
             else {
                 DrvInfos drvs;
-                getDerivations(state, v, "", autoArgs, drvs);
+                getDerivations(state, v, "", autoArgs, drvs, false);
                 foreach (DrvInfos::iterator, i, drvs) {
                     Path drvPath = i->queryDrvPath(state);
                     if (gcRoot == "")