about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-06-04T14·04+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-06-04T14·30+0200
commitb64988bb3585478676585a0f0aecbcf4e11d4432 (patch)
treeb8c34a16fc76a42f4e9f8ea9beecd453bea05712 /src/libstore
parentb190f771e7e23db363f7cb40db0e538557bbea30 (diff)
Allow substitutes for builds that have preferLocalBuild set
Not substituting builds with "preferLocalBuild = true" was a bad idea,
because it didn't take the cost of dependencies into account. For
instance, if we can't substitute a fetchgit call, then we have to
download/build git and all its dependencies.

Partially reverts 5558652709f27e8a887580b77b93c705659d7a4b and adds a
new derivation attribute "allowSubstitutes" to specify whether a
derivation may be substituted.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/build.cc22
-rw-r--r--src/libstore/misc.cc4
-rw-r--r--src/libstore/misc.hh2
3 files changed, 18 insertions, 10 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 04f8e23c5230..f0a1c1396cfd 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -999,7 +999,7 @@ void DerivationGoal::haveDerivation()
     /* We are first going to try to create the invalid output paths
        through substitutes.  If that doesn't work, we'll build
        them. */
-    if (settings.useSubstitutes && !willBuildLocally(drv))
+    if (settings.useSubstitutes && substitutesAllowed(drv))
         foreach (PathSet::iterator, i, invalidOutputs)
             addWaitee(worker.makeSubstitutionGoal(*i, buildMode == bmRepair));
 
@@ -1196,13 +1196,6 @@ PathSet outputPaths(const DerivationOutputs & outputs)
 }
 
 
-static string get(const StringPairs & map, const string & key)
-{
-    StringPairs::const_iterator i = map.find(key);
-    return i == map.end() ? (string) "" : i->second;
-}
-
-
 static bool canBuildLocally(const string & platform)
 {
     return platform == settings.thisSystem
@@ -1213,12 +1206,25 @@ static bool canBuildLocally(const string & platform)
 }
 
 
+static string get(const StringPairs & map, const string & key, const string & def = "")
+{
+    StringPairs::const_iterator i = map.find(key);
+    return i == map.end() ? def : i->second;
+}
+
+
 bool willBuildLocally(const Derivation & drv)
 {
     return get(drv.env, "preferLocalBuild") == "1" && canBuildLocally(drv.platform);
 }
 
 
+bool substitutesAllowed(const Derivation & drv)
+{
+    return get(drv.env, "allowSubstitutes", "1") == "1";
+}
+
+
 void DerivationGoal::tryToBuild()
 {
     trace("trying to build");
diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc
index 2facda81583d..736434ca4895 100644
--- a/src/libstore/misc.cc
+++ b/src/libstore/misc.cc
@@ -120,7 +120,7 @@ void queryMissing(StoreAPI & store, const PathSet & targets,
                 if (invalid.empty()) continue;
 
                 todoDrv.insert(*i);
-                if (settings.useSubstitutes && !willBuildLocally(drv))
+                if (settings.useSubstitutes && substitutesAllowed(drv))
                     query.insert(invalid.begin(), invalid.end());
             }
 
@@ -144,7 +144,7 @@ void queryMissing(StoreAPI & store, const PathSet & targets,
 
             PathSet outputs;
             bool mustBuild = false;
-            if (settings.useSubstitutes && !willBuildLocally(drv)) {
+            if (settings.useSubstitutes && substitutesAllowed(drv)) {
                 foreach (DerivationOutputs::iterator, j, drv.outputs) {
                     if (!wantOutput(j->first, i2.second)) continue;
                     if (!store.isValidPath(j->second.path)) {
diff --git a/src/libstore/misc.hh b/src/libstore/misc.hh
index 144cb7f457cd..d3e31d51f72c 100644
--- a/src/libstore/misc.hh
+++ b/src/libstore/misc.hh
@@ -34,5 +34,7 @@ void queryMissing(StoreAPI & store, const PathSet & targets,
 
 bool willBuildLocally(const Derivation & drv);
 
+bool substitutesAllowed(const Derivation & drv);
+
 
 }