summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorokhowang(王沛文) <okhowang@tencent.com>2020-08-24 14:14:07 +0800
committerokhowang(王沛文) <okhowang@tencent.com>2021-11-01 10:09:35 +0800
commit2187403594b951c50bfb9ffe7fedaf4178e9455a (patch)
tree132f6c57549a5a6cf86435507b11cb7ebca7edb5
parent540be336f5639ee6a89e959e6f9f434c01900ecf (diff)
downloadninja-2187403594b951c50bfb9ffe7fedaf4178e9455a.tar.gz
feat: don't detect cpu if -j set
-rw-r--r--src/ninja.cc21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index 3e5c971..2d43b1d 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -1305,11 +1305,28 @@ int ExceptionFilter(unsigned int code, struct _EXCEPTION_POINTERS *ep) {
#endif // _MSC_VER
+class DeferGuessParallelism {
+ public:
+ bool needGuess;
+ BuildConfig* config;
+
+ DeferGuessParallelism(BuildConfig* config)
+ : config(config), needGuess(true) {}
+
+ void Refresh() {
+ if (needGuess) {
+ needGuess = false;
+ config->parallelism = GuessParallelism();
+ }
+ }
+ ~DeferGuessParallelism() { Refresh(); }
+};
+
/// Parse argv for command-line options.
/// Returns an exit code, or -1 if Ninja should continue.
int ReadFlags(int* argc, char*** argv,
Options* options, BuildConfig* config) {
- config->parallelism = GuessParallelism();
+ DeferGuessParallelism deferGuessParallelism(config);
enum { OPT_VERSION = 1, OPT_QUIET = 2 };
const option kLongOptions[] = {
@@ -1341,6 +1358,7 @@ int ReadFlags(int* argc, char*** argv,
// We want to run N jobs in parallel. For N = 0, INT_MAX
// is close enough to infinite for most sane builds.
config->parallelism = value > 0 ? value : INT_MAX;
+ deferGuessParallelism.needGuess = false;
break;
}
case 'k': {
@@ -1389,6 +1407,7 @@ int ReadFlags(int* argc, char*** argv,
return 0;
case 'h':
default:
+ deferGuessParallelism.Refresh();
Usage(*config);
return 1;
}