diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/build_log.cc | 4 | ||||
-rw-r--r-- | src/depfile_parser.cc | 2 | ||||
-rw-r--r-- | src/edit_distance.cc | 10 | ||||
-rw-r--r-- | src/eval_env.cc | 2 | ||||
-rw-r--r-- | src/graph.cc | 3 | ||||
-rw-r--r-- | src/graph_test.cc | 19 | ||||
-rw-r--r-- | src/hash_map.h | 2 | ||||
-rw-r--r-- | src/lexer.cc | 6 | ||||
-rw-r--r-- | src/ninja.cc | 33 | ||||
-rw-r--r-- | src/string_piece.h | 4 | ||||
-rw-r--r-- | src/subprocess_test.cc | 6 | ||||
-rw-r--r-- | src/util.cc | 52 | ||||
-rw-r--r-- | src/util.h | 11 |
13 files changed, 80 insertions, 74 deletions
diff --git a/src/build_log.cc b/src/build_log.cc index c35b0e4..1b27be3 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -80,7 +80,7 @@ uint64_t MurmurHash64A(const void* key, int len) { h *= m; h ^= h >> r; return h; -} +} #undef BIG_CONSTANT @@ -88,7 +88,7 @@ uint64_t MurmurHash64A(const void* key, int len) { // static uint64_t BuildLog::LogEntry::HashCommand(StringPiece command) { - return MurmurHash64A(command.str(), command.len()); + return MurmurHash64A(command.str_, command.len_); } BuildLog::BuildLog() diff --git a/src/depfile_parser.cc b/src/depfile_parser.cc index 47b64d1..03dad92 100644 --- a/src/depfile_parser.cc +++ b/src/depfile_parser.cc @@ -203,7 +203,7 @@ yy13: if (!is_target) { ins_.push_back(StringPiece(filename, len)); - } else if (!out_.str()) { + } else if (!out_.str_) { out_ = StringPiece(filename, len); } else if (out_ != StringPiece(filename, len)) { *err = "depfile has multiple output paths."; diff --git a/src/edit_distance.cc b/src/edit_distance.cc index 50e641d..22db4fe 100644 --- a/src/edit_distance.cc +++ b/src/edit_distance.cc @@ -29,8 +29,8 @@ int EditDistance(const StringPiece& s1, // Although the algorithm is typically described using an m x n // array, only two rows are used at a time, so this implemenation // just keeps two separate vectors for those two rows. - int m = s1.len(); - int n = s2.len(); + int m = s1.len_; + int n = s2.len_; std::vector<int> previous(n + 1); std::vector<int> current(n + 1); @@ -44,11 +44,11 @@ int EditDistance(const StringPiece& s1, for (int x = 1; x <= n; ++x) { if (allow_replacements) { - current[x] = min(previous[x-1] + (s1.str()[y-1] == s2.str()[x-1] ? - 0 : 1), min(current[x-1], previous[x]) + 1); + current[x] = min(previous[x-1] + (s1.str_[y-1] == s2.str_[x-1] ? 0 : 1), + min(current[x-1], previous[x])+1); } else { - if (s1.str()[y-1] == s2.str()[x-1]) + if (s1.str_[y-1] == s2.str_[x-1]) current[x] = previous[x-1]; else current[x] = min(current[x-1], previous[x]) + 1; diff --git a/src/eval_env.cc b/src/eval_env.cc index 793ea64..81a8765 100644 --- a/src/eval_env.cc +++ b/src/eval_env.cc @@ -41,7 +41,7 @@ string EvalString::Evaluate(Env* env) const { void EvalString::AddText(StringPiece text) { // Add it to the end of an existing RAW token if possible. if (!parsed_.empty() && parsed_.back().second == RAW) { - parsed_.back().first.append(text.str(), text.len()); + parsed_.back().first.append(text.str_, text.len_); } else { parsed_.push_back(make_pair(text.AsString(), RAW)); } diff --git a/src/graph.cc b/src/graph.cc index caf2aca..18adeee 100644 --- a/src/graph.cc +++ b/src/graph.cc @@ -295,8 +295,7 @@ bool Edge::LoadDepFile(State* state, DiskInterface* disk_interface, // Add all its in-edges. for (vector<StringPiece>::iterator i = depfile.ins_.begin(); i != depfile.ins_.end(); ++i, ++implicit_dep) { - int length = i->len(); - if (!CanonicalizePath(const_cast<char*>(i->str()), &length, err)) + if (!CanonicalizePath(const_cast<char*>(i->str_), &i->len_, err)) return false; Node* node = state->GetNode(*i); diff --git a/src/graph_test.cc b/src/graph_test.cc index 07a1936..38ff28a 100644 --- a/src/graph_test.cc +++ b/src/graph_test.cc @@ -140,3 +140,22 @@ TEST_F(GraphTest, VarInOutQuoteSpaces) { EXPECT_EQ("cat nospace \"with space\" nospace2 > \"a b\"", edge->EvaluateCommand()); } + +// Regression test for https://github.com/martine/ninja/issues/380 +TEST_F(GraphTest, DepfileWithCanonicalizablePath) { + ASSERT_NO_FATAL_FAILURE(AssertParse(&state_, +"rule catdep\n" +" depfile = $out.d\n" +" command = cat $in > $out\n" +"build ./out.o: catdep ./foo.cc\n")); + fs_.Create("foo.cc", 1, ""); + fs_.Create("out.o.d", 1, "out.o: bar/../foo.cc\n"); + fs_.Create("out.o", 1, ""); + + Edge* edge = GetNode("out.o")->in_edge(); + string err; + EXPECT_TRUE(edge->RecomputeDirty(&state_, &fs_, &err)); + ASSERT_EQ("", err); + + EXPECT_FALSE(GetNode("out.o")->dirty()); +} diff --git a/src/hash_map.h b/src/hash_map.h index ff2f7ba..658f699 100644 --- a/src/hash_map.h +++ b/src/hash_map.h @@ -86,7 +86,7 @@ struct hash<std::string> { template<> struct hash<StringPiece> { size_t operator()(StringPiece key) const { - return MurmurHash2(key.str(), key.len()); + return MurmurHash2(key.str_, key.len_); } }; diff --git a/src/lexer.cc b/src/lexer.cc index 45bf4ef..ca6f367 100644 --- a/src/lexer.cc +++ b/src/lexer.cc @@ -23,8 +23,8 @@ bool Lexer::Error(const string& message, string* err) { // Compute line/column. int line = 1; - const char* context = input_.str(); - for (const char* p = input_.str(); p < last_token_; ++p) { + const char* context = input_.str_; + for (const char* p = input_.str_; p < last_token_; ++p) { if (*p == '\n') { ++line; context = p + 1; @@ -66,7 +66,7 @@ Lexer::Lexer(const char* input) { void Lexer::Start(StringPiece filename, StringPiece input) { filename_ = filename; input_ = input; - ofs_ = input_.str(); + ofs_ = input_.str_; last_token_ = NULL; } diff --git a/src/ninja.cc b/src/ninja.cc index 538d0d7..778eb53 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -19,12 +19,6 @@ #include <sys/stat.h> #include <sys/types.h> -#if defined(__APPLE__) || defined(__FreeBSD__) -#include <sys/sysctl.h> -#elif defined(linux) -#include <sys/sysinfo.h> -#endif - #ifdef _WIN32 #include "getopt.h" #include <direct.h> @@ -91,6 +85,9 @@ void Usage(const BuildConfig& config) { "\n" " -j N run N jobs in parallel [default=%d]\n" " -l N do not start new jobs if the load average is greater than N\n" +#ifdef _WIN32 +" (not yet implemented on Windows)\n" +#endif " -k N keep going until N jobs fail [default=1]\n" " -n dry run (don't run commands but pretend they succeeded)\n" " -v show all command lines while building\n" @@ -104,25 +101,7 @@ void Usage(const BuildConfig& config) { /// Choose a default value for the -j (parallelism) flag. int GuessParallelism() { - int processors = 0; - -#if defined(linux) - processors = get_nprocs(); -#elif defined(__APPLE__) || defined(__FreeBSD__) - size_t processors_size = sizeof(processors); - int name[] = {CTL_HW, HW_NCPU}; - if (sysctl(name, sizeof(name) / sizeof(int), - &processors, &processors_size, - NULL, 0) < 0) { - processors = 1; - } -#elif defined(_WIN32) - SYSTEM_INFO info; - GetSystemInfo(&info); - processors = info.dwNumberOfProcessors; -#endif - - switch (processors) { + switch (int processors = GetProcessorCount()) { case 0: case 1: return 2; @@ -739,11 +718,7 @@ int NinjaMain(int argc, char** argv) { // can be piped into a file without this string showing up. if (tool == "") printf("ninja: Entering directory `%s'\n", working_dir); -#ifdef _WIN32 - if (_chdir(working_dir) < 0) { -#else if (chdir(working_dir) < 0) { -#endif Fatal("chdir to '%s' - %s", working_dir, strerror(errno)); } } diff --git a/src/string_piece.h b/src/string_piece.h index 76679f1..ad1153e 100644 --- a/src/string_piece.h +++ b/src/string_piece.h @@ -46,10 +46,6 @@ struct StringPiece { return len_ ? string(str_, len_) : string(); } - const char* str() const { return str_; } - int len() const { return len_; } - - private: const char* str_; int len_; }; diff --git a/src/subprocess_test.cc b/src/subprocess_test.cc index 7dbaf97..d89525e 100644 --- a/src/subprocess_test.cc +++ b/src/subprocess_test.cc @@ -149,7 +149,9 @@ TEST_F(SubprocessTest, SetWithMulti) { } } -#ifndef _WIN32 +// 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). +#ifdef linux TEST_F(SubprocessTest, SetWithLots) { // Arbitrary big number; needs to be over 1024 to confirm we're no longer // hostage to pselect. @@ -176,4 +178,4 @@ TEST_F(SubprocessTest, SetWithLots) { } ASSERT_EQ(kNumProcs, subprocs_.finished_.size()); } -#endif // _WIN32 +#endif // linux diff --git a/src/util.cc b/src/util.cc index cb3e141..be2347c 100644 --- a/src/util.cc +++ b/src/util.cc @@ -38,6 +38,12 @@ #include <direct.h> // _mkdir #endif +#if defined(__APPLE__) || defined(__FreeBSD__) +#include <sys/sysctl.h> +#elif defined(linux) +#include <sys/sysinfo.h> +#endif + #include "edit_distance.h" #include "metrics.h" @@ -283,18 +289,40 @@ string StripAnsiEscapeCodes(const string& in) { return stripped; } +#if defined(linux) +int GetProcessorCount() { + return get_nprocs(); +} +#elif defined(__APPLE__) || defined(__FreeBSD__) +int GetProcessorCount() { + int processors; + size_t processors_size = sizeof(processors); + int name[] = {CTL_HW, HW_NCPU}; + if (sysctl(name, sizeof(name) / sizeof(int), + &processors, &processors_size, + NULL, 0) < 0) { + return 0; + } + return processors; +} +#elif defined(_WIN32) +int GetProcessorCount() { + SYSTEM_INFO info; + GetSystemInfo(&info); + return info.dwNumberOfProcessors; +} +#endif + #ifdef _WIN32 -static double GetLoadAverage_win32() -{ +double GetLoadAverage() { // TODO(nicolas.despres@gmail.com): Find a way to implement it on Windows. + // Remember to also update Usage() when this is fixed. return -0.0f; } #else -static double GetLoadAverage_unix() -{ +double GetLoadAverage() { double loadavg[3] = { 0.0f, 0.0f, 0.0f }; - if (getloadavg(loadavg, 3) < 0) - { + if (getloadavg(loadavg, 3) < 0) { // Maybe we should return an error here or the availability of // getloadavg(3) should be checked when ninja is configured. return -0.0f; @@ -303,17 +331,7 @@ static double GetLoadAverage_unix() } #endif // _WIN32 -double GetLoadAverage() -{ -#ifdef _WIN32 - return GetLoadAverage_win32(); -#else - return GetLoadAverage_unix(); -#endif // _WIN32 -} - -string ElideMiddle(const string& str, size_t width) -{ +string ElideMiddle(const string& str, size_t width) { const int kMargin = 3; // Space for "...". string result = str; if (result.size() + kMargin > width) { @@ -62,6 +62,10 @@ const char* SpellcheckString(const string& text, ...); /// Removes all Ansi escape codes (http://www.termsys.demon.co.uk/vtansi.htm). string StripAnsiEscapeCodes(const string& in); +/// @return the number of processors on the machine. Useful for an initial +/// guess for how many jobs to run in parallel. @return 0 on error. +int GetProcessorCount(); + /// @return the load average of the machine. A negative value is returned /// on error. double GetLoadAverage(); @@ -79,13 +83,6 @@ string ElideMiddle(const string& str, size_t width); #endif #ifdef _WIN32 - -/// Handler for __except block -int exception_filter(unsigned int code, struct _EXCEPTION_POINTERS *ep); - -/// Write a windows minidump file in temp directory. User can specify null 'pep' argument. -void Create_Win32_MiniDump( struct _EXCEPTION_POINTERS* pep ); - /// Convert the value returned by GetLastError() into a string. string GetLastErrorString(); #endif |