1 // Copyright 2011 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #ifndef NINJA_BUILD_LOG_H_
16 #define NINJA_BUILD_LOG_H_
23 #include "timestamp.h"
24 #include "util.h" // uint64_t
28 /// Can answer questions about the manifest for the BuildLog.
30 /// Return if a given output is no longer part of the build manifest.
31 /// This is only called during recompaction and doesn't have to be fast.
32 virtual bool IsPathDead(StringPiece s) const = 0;
35 /// Store a log of every command ran for every build.
36 /// It has a few uses:
38 /// 1) (hashes of) command lines for existing output files, so we know
39 /// when we need to rebuild due to the command changing
40 /// 2) timing information, perhaps for generating reports
41 /// 3) restat information
46 bool OpenForWrite(const string& path, const BuildLogUser& user, string* err);
47 bool RecordCommand(Edge* edge, int start_time, int end_time,
48 TimeStamp restat_mtime = 0);
51 /// Load the on-disk log.
52 bool Load(const string& path, string* err);
56 uint64_t command_hash;
59 TimeStamp restat_mtime;
61 static uint64_t HashCommand(StringPiece command);
64 bool operator==(const LogEntry& o) {
65 return output == o.output && command_hash == o.command_hash &&
66 start_time == o.start_time && end_time == o.end_time &&
67 restat_mtime == o.restat_mtime;
70 explicit LogEntry(const string& output);
71 LogEntry(const string& output, uint64_t command_hash,
72 int start_time, int end_time, TimeStamp restat_mtime);
75 /// Lookup a previously-run command by its output path.
76 LogEntry* LookupByOutput(const string& path);
78 /// Serialize an entry into a log file.
79 bool WriteEntry(FILE* f, const LogEntry& entry);
81 /// Rewrite the known log entries, throwing away old data.
82 bool Recompact(const string& path, const BuildLogUser& user, string* err);
84 typedef ExternalStringHashMap<LogEntry*>::Type Entries;
85 const Entries& entries() const { return entries_; }
90 bool needs_recompaction_;
93 #endif // NINJA_BUILD_LOG_H_