summaryrefslogtreecommitdiffstats
path: root/src/ninja.cc
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2015-01-26 21:52:20 (GMT)
committerColin Cross <ccross@android.com>2015-02-03 20:49:15 (GMT)
commit5fbfa4ba72883cc0ecd199d17a70da3698be0402 (patch)
tree164a28a3233e01581c958ba76c89627adc3419c6 /src/ninja.cc
parent62458b6f19dd134d2a4a38ff81e368c8b7e5605d (diff)
downloadNinja-5fbfa4ba72883cc0ecd199d17a70da3698be0402.zip
Ninja-5fbfa4ba72883cc0ecd199d17a70da3698be0402.tar.gz
Ninja-5fbfa4ba72883cc0ecd199d17a70da3698be0402.tar.bz2
Allow manifest rebuild to loop up to 100 times
Ninja generators that bootstrap themselves with Ninja may need to rebuild build.ninja multiple times. Replace the 2 cycle loop with a 100 cycle loop, and print the pass number each time it restarts. Original-author: Jamie Gennis <jgennis@gmail.com>
Diffstat (limited to 'src/ninja.cc')
-rw-r--r--src/ninja.cc27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index 3e99782..48c7239 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -1061,9 +1061,9 @@ int real_main(int argc, char** argv) {
return (ninja.*options.tool->func)(argc, argv);
}
- // The build can take up to 2 passes: one to rebuild the manifest, then
- // another to build the desired target.
- for (int cycle = 0; cycle < 2; ++cycle) {
+ // Limit number of rebuilds, to prevent infinite loops.
+ const int kCycleLimit = 100;
+ for (int cycle = 1; cycle <= kCycleLimit; ++cycle) {
NinjaMain ninja(ninja_command, config);
RealFileReader file_reader;
@@ -1086,16 +1086,13 @@ int real_main(int argc, char** argv) {
if (options.tool && options.tool->when == Tool::RUN_AFTER_LOGS)
return (ninja.*options.tool->func)(argc, argv);
- // The first time through, attempt to rebuild the manifest before
- // building anything else.
- if (cycle == 0) {
- if (ninja.RebuildManifest(options.input_file, &err)) {
- // Start the build over with the new manifest.
- continue;
- } else if (!err.empty()) {
- Error("rebuilding '%s': %s", options.input_file, err.c_str());
- return 1;
- }
+ // Attempt to rebuild the manifest before building anything else
+ if (ninja.RebuildManifest(options.input_file, &err)) {
+ // Start the build over with the new manifest.
+ continue;
+ } else if (!err.empty()) {
+ Error("rebuilding '%s': %s", options.input_file, err.c_str());
+ return 1;
}
int result = ninja.RunBuild(argc, argv);
@@ -1104,7 +1101,9 @@ int real_main(int argc, char** argv) {
return result;
}
- return 1; // Shouldn't be reached.
+ Error("manifest '%s' still dirty after %d tries\n",
+ options.input_file, kCycleLimit);
+ return 1;
}
} // anonymous namespace