summaryrefslogtreecommitdiff
path: root/tools/bit/make.cpp
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2017-01-12 19:38:49 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2017-01-12 19:38:54 +0000
commit4391fae30e29371673e3de947f344f9b1073dc12 (patch)
tree5eff581a31ad55b80871cb5958eefcf9e2d614d6 /tools/bit/make.cpp
parentd26d2af79e5bb52f4392bdbfd1858f905f80480d (diff)
parentd973affed21e490a9eef1ae76dfcc3bd0358cb0e (diff)
Merge "Compile bit on darwin, use -j when invoking make"
Diffstat (limited to 'tools/bit/make.cpp')
-rw-r--r--tools/bit/make.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/tools/bit/make.cpp b/tools/bit/make.cpp
index 60b5687bb313..a8002417b916 100644
--- a/tools/bit/make.cpp
+++ b/tools/bit/make.cpp
@@ -26,6 +26,7 @@
#include <fstream>
#include <string>
#include <map>
+#include <thread>
#include <sys/types.h>
#include <dirent.h>
@@ -35,6 +36,14 @@ using namespace std;
map<string,string> g_buildVars;
+static unsigned int
+get_thread_count()
+{
+ unsigned int threads = std::thread::hardware_concurrency();
+ // Guess if the value cannot be computed
+ return threads == 0 ? 4 : static_cast<unsigned int>(threads * 1.3f);
+}
+
string
get_build_var(const string& buildTop, const string& name, bool quiet)
{
@@ -44,6 +53,7 @@ get_build_var(const string& buildTop, const string& name, bool quiet)
if (it == g_buildVars.end()) {
Command cmd("make");
cmd.AddArg("--no-print-directory");
+ cmd.AddArg(string("-j") + std::to_string(get_thread_count()));
cmd.AddArg("-C");
cmd.AddArg(buildTop);
cmd.AddArg("-f");
@@ -199,6 +209,7 @@ int
build_goals(const vector<string>& goals)
{
Command cmd("make");
+ cmd.AddArg(string("-j") + std::to_string(get_thread_count()));
cmd.AddArg("-f");
cmd.AddArg("build/core/main.mk");
for (size_t i=0; i<goals.size(); i++) {