diff options
-rw-r--r-- | flags.cc | 1 | ||||
-rw-r--r-- | flags.h | 1 | ||||
-rw-r--r-- | main.cc | 16 | ||||
-rw-r--r-- | ninja.cc | 4 |
4 files changed, 20 insertions, 2 deletions
@@ -20,3 +20,4 @@ bool g_enable_stat_logs; bool g_is_dry_run; const char* g_ignore_optional_include_pattern; const char* g_goma_dir; +int g_num_jobs; @@ -19,5 +19,6 @@ extern bool g_is_dry_run; extern bool g_enable_stat_logs; extern const char* g_ignore_optional_include_pattern; extern const char* g_goma_dir; +extern int g_num_jobs; #endif // FLAGS_H_ @@ -17,6 +17,7 @@ #include <limits.h> #include <stdio.h> #include <string.h> +#include <stdlib.h> #include <unistd.h> #include "ast.h" @@ -62,12 +63,21 @@ static bool ParseCommandLineOptionWithArg(StringPiece option, *out_arg = arg + option.size() + 1; return true; } + // E.g, -j999 + if (option.size() == 2) { + *out_arg = arg + option.size(); + return true; + } return false; } static void ParseCommandLine(int argc, char* argv[], vector<Symbol>* targets, vector<StringPiece>* cl_vars) { + // TODO: Decide the appropriate number based on the number of cores. + g_num_jobs = 32; + const char* num_jobs_str; + for (int i = 1; i < argc; i++) { const char* arg = argv[i]; if (!strcmp(arg, "-f")) { @@ -81,6 +91,12 @@ static void ParseCommandLine(int argc, char* argv[], } else if (!strcmp(arg, "--ninja")) { g_generate_ninja = true; } else if (ParseCommandLineOptionWithArg( + "-j", argv, &i, &num_jobs_str)) { + g_num_jobs = strtol(num_jobs_str, NULL, 10); + if (g_num_jobs <= 0) { + ERROR("Invalid -j flag: %s", num_jobs_str); + } + } else if (ParseCommandLineOptionWithArg( "--ninja_suffix", argv, &i, &g_ninja_suffix)) { } else if (!strcmp(arg, "--use_find_emulator")) { g_use_find_emulator = true; @@ -27,6 +27,7 @@ #include "command.h" #include "dep.h" #include "eval.h" +#include "flags.h" #include "log.h" #include "string_piece.h" #include "stringprintf.h" @@ -355,8 +356,7 @@ class NinjaGenerator { if (g_goma_dir) { fprintf(fp_, "pool local_pool\n"); - // TODO: Decide the appropriate number based on the number of cores. - fprintf(fp_, " depth = %d\n", 32); + fprintf(fp_, " depth = %d\n", g_num_jobs); } for (DepNode* node : nodes) { |