diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/build.cc | 4 | ||||
-rw-r--r-- | src/build.h | 12 | ||||
-rw-r--r-- | src/ninja.cc | 40 | ||||
-rw-r--r-- | src/subprocess-posix.cc | 12 | ||||
-rw-r--r-- | src/subprocess.h | 8 | ||||
-rw-r--r-- | src/subprocess_test.cc | 4 | ||||
-rw-r--r-- | src/version.cc | 2 |
7 files changed, 57 insertions, 25 deletions
diff --git a/src/build.cc b/src/build.cc index b806fb5..64710dd 100644 --- a/src/build.cc +++ b/src/build.cc @@ -220,14 +220,14 @@ string BuildStatus::FormatProgressStatus( // Overall finished edges per second. case 'o': overall_rate_.UpdateRate(finished_edges_); - snprinfRate(overall_rate_.rate(), buf, "%.1f"); + SnprintfRate(overall_rate_.rate(), buf, "%.1f"); out += buf; break; // Current rate, average over the last '-j' jobs. case 'c': current_rate_.UpdateRate(finished_edges_); - snprinfRate(current_rate_.rate(), buf, "%.1f"); + SnprintfRate(current_rate_.rate(), buf, "%.1f"); out += buf; break; diff --git a/src/build.h b/src/build.h index e633c95..66ce607 100644 --- a/src/build.h +++ b/src/build.h @@ -212,9 +212,9 @@ struct BuildStatus { /// See the user manual for more information about the available /// placeholders. /// @param progress_status_format The format of the progress status. - /// @param finished True if the edge being printed just finished + /// @param status The status of the edge. string FormatProgressStatus(const char* progress_status_format, - EdgeStatus kEdgeFinished) const; + EdgeStatus status) const; private: void PrintStatus(Edge* edge, EdgeStatus status); @@ -237,9 +237,11 @@ struct BuildStatus { const char* progress_status_format_; template<size_t S> - void snprinfRate(double rate, char(&buf)[S], const char* format) const { - if (rate == -1) snprintf(buf, S, "?"); - else snprintf(buf, S, format, rate); + void SnprintfRate(double rate, char(&buf)[S], const char* format) const { + if (rate == -1) + snprintf(buf, S, "?"); + else + snprintf(buf, S, format, rate); } struct RateInfo { diff --git a/src/ninja.cc b/src/ninja.cc index 25eafe8..5ab73e9 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -533,21 +533,51 @@ int NinjaMain::ToolTargets(const Options* options, int argc, char* argv[]) { } } -void PrintCommands(Edge* edge, set<Edge*>* seen) { +enum PrintCommandMode { PCM_Single, PCM_All }; +void PrintCommands(Edge* edge, set<Edge*>* seen, PrintCommandMode mode) { if (!edge) return; if (!seen->insert(edge).second) return; - for (vector<Node*>::iterator in = edge->inputs_.begin(); - in != edge->inputs_.end(); ++in) - PrintCommands((*in)->in_edge(), seen); + if (mode == PCM_All) { + for (vector<Node*>::iterator in = edge->inputs_.begin(); + in != edge->inputs_.end(); ++in) + PrintCommands((*in)->in_edge(), seen, mode); + } if (!edge->is_phony()) puts(edge->EvaluateCommand().c_str()); } int NinjaMain::ToolCommands(const Options* options, int argc, char* argv[]) { + // The clean tool uses getopt, and expects argv[0] to contain the name of + // the tool, i.e. "commands". + ++argc; + --argv; + + PrintCommandMode mode = PCM_All; + + optind = 1; + int opt; + while ((opt = getopt(argc, argv, const_cast<char*>("hs"))) != -1) { + switch (opt) { + case 's': + mode = PCM_Single; + break; + case 'h': + default: + printf("usage: ninja -t commands [options] [targets]\n" +"\n" +"options:\n" +" -s only print the final command to build [target], not the whole chain\n" + ); + return 1; + } + } + argv += optind; + argc -= optind; + vector<Node*> nodes; string err; if (!CollectTargetsFromArgs(argc, argv, &nodes, &err)) { @@ -557,7 +587,7 @@ int NinjaMain::ToolCommands(const Options* options, int argc, char* argv[]) { set<Edge*> seen; for (vector<Node*>::iterator in = nodes.begin(); in != nodes.end(); ++in) - PrintCommands((*in)->in_edge(), &seen); + PrintCommands((*in)->in_edge(), &seen, mode); return 0; } diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc index 3c81b7f..f1f94e5 100644 --- a/src/subprocess-posix.cc +++ b/src/subprocess-posix.cc @@ -24,13 +24,6 @@ #include <sys/wait.h> #include <spawn.h> -#ifdef __FreeBSD__ -# include <sys/param.h> -# if defined USE_PPOLL && __FreeBSD_version < 1002000 -# undef USE_PPOLL -# endif -#endif - extern char** environ; #include "util.h" @@ -80,8 +73,6 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) { // default action in the new process image, so no explicit // POSIX_SPAWN_SETSIGDEF parameter is needed. - // TODO: Consider using POSIX_SPAWN_USEVFORK on Linux with glibc? - if (!use_console_) { // Put the child in its own process group, so ctrl-c won't reach it. flags |= POSIX_SPAWN_SETPGROUP; @@ -100,6 +91,9 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) { // In the console case, output_pipe is still inherited by the child and // closed when the subprocess finishes, which then notifies ninja. } +#ifdef POSIX_SPAWN_USEVFORK + flags |= POSIX_SPAWN_USEVFORK; +#endif if (posix_spawnattr_setflags(&attr, flags) != 0) Fatal("posix_spawnattr_setflags: %s", strerror(errno)); diff --git a/src/subprocess.h b/src/subprocess.h index 51f40b2..b2d486c 100644 --- a/src/subprocess.h +++ b/src/subprocess.h @@ -26,6 +26,14 @@ using namespace std; #include <signal.h> #endif +// ppoll() exists on FreeBSD, but only on newer versions. +#ifdef __FreeBSD__ +# include <sys/param.h> +# if defined USE_PPOLL && __FreeBSD_version < 1002000 +# undef USE_PPOLL +# endif +#endif + #include "exit_status.h" /// Subprocess wraps a single async subprocess. It is entirely diff --git a/src/subprocess_test.cc b/src/subprocess_test.cc index ee16190..0a8c206 100644 --- a/src/subprocess_test.cc +++ b/src/subprocess_test.cc @@ -214,9 +214,7 @@ TEST_F(SubprocessTest, SetWithMulti) { } } -// OS X's process limit is less than 1025 by default -// (|sysctl kern.maxprocperuid| is 709 on 10.7 and 10.8 and less prior to that). -#if !defined(__APPLE__) && !defined(_WIN32) +#if defined(USE_PPOLL) TEST_F(SubprocessTest, SetWithLots) { // Arbitrary big number; needs to be over 1024 to confirm we're no longer // hostage to pselect. diff --git a/src/version.cc b/src/version.cc index f64a94d..e2a83bb 100644 --- a/src/version.cc +++ b/src/version.cc @@ -18,7 +18,7 @@ #include "util.h" -const char* kNinjaVersion = "1.7.1.git"; +const char* kNinjaVersion = "1.7.2.git"; void ParseVersion(const string& version, int* major, int* minor) { size_t end = version.find('.'); |