From dc3ffcdd4c840a697cdbc71f2c0121908977af9a Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Wed, 4 Jan 2012 17:07:23 -0800 Subject: factor out the main builder call --- src/ninja.cc | 66 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/src/ninja.cc b/src/ninja.cc index 7a4ad7f..a55bfc4 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -517,6 +517,41 @@ int RunTool(const string& tool, Globals* globals, int argc, char** argv) { return 1; } +int RunBuild(Globals* globals, int argc, char** argv) { + string err; + vector targets; + if (!CollectTargetsFromArgs(globals->state, argc, argv, &targets, &err)) { + Error("%s", err.c_str()); + return 1; + } + + Builder builder(globals->state, globals->config); + for (size_t i = 0; i < targets.size(); ++i) { + if (!builder.AddTarget(targets[i], &err)) { + if (!err.empty()) { + Error("%s", err.c_str()); + return 1; + } else { + // Added a target that is already up-to-date; not really + // an error. + } + } + } + + if (builder.AlreadyUpToDate()) { + printf("ninja: no work to do.\n"); + return 0; + } + + if (!builder.Build(&err)) { + printf("ninja: build stopped: %s.\n", err.c_str()); + return 1; + } + + return 0; +} + + } // anonymous namespace int main(int argc, char** argv) { @@ -645,34 +680,5 @@ reload: } } - vector targets; - if (!CollectTargetsFromArgs(globals.state, argc, argv, &targets, &err)) { - Error("%s", err.c_str()); - return 1; - } - - Builder builder(globals.state, globals.config); - for (size_t i = 0; i < targets.size(); ++i) { - if (!builder.AddTarget(targets[i], &err)) { - if (!err.empty()) { - Error("%s", err.c_str()); - return 1; - } else { - // Added a target that is already up-to-date; not really - // an error. - } - } - } - - if (builder.AlreadyUpToDate()) { - printf("ninja: no work to do.\n"); - return 0; - } - - if (!builder.Build(&err)) { - printf("ninja: build stopped: %s.\n", err.c_str()); - return 1; - } - - return 0; + return RunBuild(&globals, argc, argv); } -- cgit v0.12