about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-02-28T11·54+0100
committerEelco Dolstra <edolstra@gmail.com>2017-02-28T11·54+0100
commit7251d048fa812d2551b7003bc9f13a8f5d4c95a5 (patch)
tree242d94f45d24a2becf373cdda7e34f3128111982 /src/libstore
parent3fab1f04a7d9a5d8ca0f7faf071d5767f93c7e22 (diff)
Support auto-configuration of build-max-jobs
"build-max-jobs" and the "-j" option can now be set to "auto" to use
the number of CPUs in the system. (Unlike build-cores, it doesn't use
0 to imply auto-configuration, because a) magic values are a bad idea
in general; b) 0 is a legitimate value used to disable local
building.)

Fixes #1198.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/globals.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 12e2a3cf43dd..07af629260af 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -147,7 +147,14 @@ int Settings::get(const string & name, int def)
 void Settings::update()
 {
     _get(tryFallback, "build-fallback");
-    _get(maxBuildJobs, "build-max-jobs");
+
+    auto s = get("build-max-jobs", std::string("1"));
+    if (s == "auto")
+        maxBuildJobs = std::max(1U, std::thread::hardware_concurrency());
+    else
+        if (!string2Int(s, maxBuildJobs))
+            throw Error("configuration setting ‘build-max-jobs’ should be ‘auto’ or an integer");
+
     _get(buildCores, "build-cores");
     _get(thisSystem, "system");
     _get(maxSilentTime, "build-max-silent-time");