Imported Upstream version 1.9.0
[platform/upstream/ninja.git] / src / deps_log.cc
index 9514446..0bb96f3 100644 (file)
@@ -20,6 +20,9 @@
 #include <string.h>
 #ifndef _WIN32
 #include <unistd.h>
+#elif defined(_MSC_VER) && (_MSC_VER < 1900)
+typedef __int32 int32_t;
+typedef unsigned __int32 uint32_t;
 #endif
 
 #include "graph.h"
@@ -124,7 +127,7 @@ bool DepsLog::RecordDeps(Node* node, TimeStamp mtime,
     return true;
 
   // Update on-disk representation.
-  unsigned size = 4 * (1 + 1 + node_count);
+  unsigned size = 4 * (1 + 2 + node_count);
   if (size > kMaxRecordSize) {
     errno = ERANGE;
     return false;
@@ -135,8 +138,11 @@ bool DepsLog::RecordDeps(Node* node, TimeStamp mtime,
   int id = node->id();
   if (fwrite(&id, 4, 1, file_) < 1)
     return false;
-  int timestamp = mtime;
-  if (fwrite(&timestamp, 4, 1, file_) < 1)
+  uint32_t mtime_part = static_cast<uint32_t>(mtime & 0xffffffff);
+  if (fwrite(&mtime_part, 4, 1, file_) < 1)
+    return false;
+  mtime_part = static_cast<uint32_t>((mtime >> 32) & 0xffffffff);
+  if (fwrite(&mtime_part, 4, 1, file_) < 1)
     return false;
   for (int i = 0; i < node_count; ++i) {
     id = nodes[i]->id();
@@ -209,7 +215,7 @@ bool DepsLog::Load(const string& path, State* state, string* err) {
     bool is_deps = (size >> 31) != 0;
     size = size & 0x7FFFFFFF;
 
-    if (fread(buf, size, 1, f) < 1 || size > kMaxRecordSize) {
+    if (size > kMaxRecordSize || fread(buf, size, 1, f) < 1) {
       read_failed = true;
       break;
     }
@@ -218,9 +224,11 @@ bool DepsLog::Load(const string& path, State* state, string* err) {
       assert(size % 4 == 0);
       int* deps_data = reinterpret_cast<int*>(buf);
       int out_id = deps_data[0];
-      int mtime = deps_data[1];
-      deps_data += 2;
-      int deps_count = (size / 4) - 2;
+      TimeStamp mtime;
+      mtime = (TimeStamp)(((uint64_t)(unsigned int)deps_data[2] << 32) |
+                          (uint64_t)(unsigned int)deps_data[1]);
+      deps_data += 3;
+      int deps_count = (size / 4) - 3;
 
       Deps* deps = new Deps(mtime, deps_count);
       for (int i = 0; i < deps_count; ++i) {
@@ -233,16 +241,19 @@ bool DepsLog::Load(const string& path, State* state, string* err) {
       if (!UpdateDeps(out_id, deps))
         ++unique_dep_record_count;
     } else {
-      int path_size = size - 8;
+      int path_size = size - 4;
       assert(path_size > 0);  // CanonicalizePath() rejects empty paths.
       // There can be up to 3 bytes of padding.
       if (buf[path_size - 1] == '\0') --path_size;
       if (buf[path_size - 1] == '\0') --path_size;
       if (buf[path_size - 1] == '\0') --path_size;
-      StringPiece path(buf, path_size);
-      unsigned int slash_bits =
-          *reinterpret_cast<unsigned int*>(buf + size - 8);
-      Node* node = state->GetNode(path, slash_bits);
+      StringPiece subpath(buf, path_size);
+      // It is not necessary to pass in a correct slash_bits here. It will
+      // either be a Node that's in the manifest (in which case it will already
+      // have a correct slash_bits that GetNode will look up), or it is an
+      // implicit dependency from a .d which does not affect the build command
+      // (and so need not have its slashes maintained).
+      Node* node = state->GetNode(subpath, 0);
 
       // Check that the expected index matches the actual index. This can only
       // happen if two ninja processes write to the same deps log concurrently.
@@ -272,7 +283,7 @@ bool DepsLog::Load(const string& path, State* state, string* err) {
     }
     fclose(f);
 
-    if (!Truncate(path.c_str(), offset, err))
+    if (!Truncate(path, offset, err))
       return false;
 
     // The truncate succeeded; we'll just report the load error as a
@@ -304,8 +315,6 @@ DepsLog::Deps* DepsLog::GetDeps(Node* node) {
 
 bool DepsLog::Recompact(const string& path, string* err) {
   METRIC_RECORD(".ninja_deps recompact");
-  if (!quiet_)
-    printf("Recompacting deps...\n");
 
   Close();
   string temp_path = path + ".recompact";
@@ -382,7 +391,7 @@ bool DepsLog::RecordId(Node* node) {
   int path_size = node->path().size();
   int padding = (4 - path_size % 4) % 4;  // Pad path to 4 byte boundary.
 
-  unsigned size = path_size + padding + 4 + 4;
+  unsigned size = path_size + padding + 4;
   if (size > kMaxRecordSize) {
     errno = ERANGE;
     return false;
@@ -395,9 +404,6 @@ bool DepsLog::RecordId(Node* node) {
   }
   if (padding && fwrite("\0\0", padding, 1, file_) < 1)
     return false;
-  unsigned int slash_bits = node->slash_bits();
-  if (fwrite(&slash_bits, 4, 1, file_) < 1)
-    return false;
   int id = nodes_.size();
   unsigned checksum = ~(unsigned)id;
   if (fwrite(&checksum, 4, 1, file_) < 1)