Ninja
|
As build commands run they can output extra dependency information (e.g. More...
#include <deps_log.h>
Classes | |
struct | Deps |
Public Member Functions | |
void | Close () |
const vector< Deps * > & | deps () const |
DepsLog () | |
Deps * | GetDeps (Node *node) |
bool | IsDepsEntryLiveFor (Node *node) |
Returns if the deps entry for a node is still reachable from the manifest. More... | |
bool | Load (const string &path, State *state, string *err) |
const vector< Node * > & | nodes () const |
Used for tests. More... | |
bool | OpenForWrite (const string &path, string *err) |
bool | Recompact (const string &path, string *err) |
Rewrite the known log entries, throwing away old data. More... | |
bool | RecordDeps (Node *node, TimeStamp mtime, const vector< Node * > &nodes) |
bool | RecordDeps (Node *node, TimeStamp mtime, int node_count, Node **nodes) |
~DepsLog () | |
Private Member Functions | |
bool | RecordId (Node *node) |
bool | UpdateDeps (int out_id, Deps *deps) |
Private Attributes | |
vector< Deps * > | deps_ |
Maps id -> deps of that id. More... | |
FILE * | file_ |
bool | needs_recompaction_ |
vector< Node * > | nodes_ |
Maps id -> Node. More... | |
Friends | |
struct | DepsLogTest |
As build commands run they can output extra dependency information (e.g.
header dependencies for C source) dynamically. DepsLog collects that information at build time and uses it for subsequent builds.
The on-disk format is based on two primary design constraints:
Based on these stats, here's the current design. The file is structured as version header followed by a sequence of records. Each record is either a path string or a dependency list. Numbering the path strings in file order gives them dense integer ids. A dependency list maps an output id to a list of input ids.
Concretely, a record is: four bytes record length, high bit indicates record type (but max record sizes are capped at 512kB) path records contain the string name of the path, followed by up to 3 padding bytes to align on 4 byte boundaries, followed by the one's complement of the expected index of the record (to detect concurrent writes of multiple ninja processes to the log). dependency records are an array of 4-byte integers output path id, output path mtime, input path id, input path id... If two records reference the same output the latter one in the file wins, allowing updates to just be appended to the file. A separate repacking step can run occasionally to remove dead records.
Definition at line 66 of file deps_log.h.
|
inline |
Definition at line 67 of file deps_log.h.
DepsLog::~DepsLog | ( | ) |
Definition at line 39 of file deps_log.cc.
References Close().
void DepsLog::Close | ( | ) |
Definition at line 158 of file deps_log.cc.
References file_.
Referenced by Recompact(), TEST_F(), and ~DepsLog().
|
inline |
Definition at line 101 of file deps_log.h.
Referenced by Load(), Recompact(), RecordDeps(), and UpdateDeps().
DepsLog::Deps * DepsLog::GetDeps | ( | Node * | node | ) |
Definition at line 295 of file deps_log.cc.
References deps_, and Node::id().
Referenced by RecordDeps().
bool DepsLog::IsDepsEntryLiveFor | ( | Node * | node | ) |
Returns if the deps entry for a node is still reachable from the manifest.
The deps log can contain deps entries for files that were built in the past but are no longer part of the manifest. This function returns if this is the case for a given node. This function is slow, don't call it from code that runs on every build.
Definition at line 357 of file deps_log.cc.
References Edge::GetBinding(), and Node::in_edge().
Referenced by Recompact().
bool DepsLog::Load | ( | const string & | path, |
State * | state, | ||
string * | err | ||
) |
Definition at line 164 of file deps_log.cc.
References deps(), State::GetNode(), Node::id(), kCurrentVersion, kFileSignature, kMaxRecordSize, METRIC_RECORD, needs_recompaction_, DepsLog::Deps::nodes, nodes_, Node::set_id(), Truncate(), and UpdateDeps().
Referenced by BuildTest::RebuildTarget(), and TEST_F().
|
inline |
Used for tests.
Definition at line 100 of file deps_log.h.
bool DepsLog::OpenForWrite | ( | const string & | path, |
string * | err | ||
) |
Definition at line 43 of file deps_log.cc.
References file_, kCurrentVersion, kFileSignature, kMaxRecordSize, needs_recompaction_, Recompact(), and SetCloseOnExec().
Referenced by BuildTest::RebuildTarget(), and TEST_F().
bool DepsLog::Recompact | ( | const string & | path, |
string * | err | ||
) |
Rewrite the known log entries, throwing away old data.
Definition at line 303 of file deps_log.cc.
References Close(), deps(), deps_, IsDepsEntryLiveFor(), METRIC_RECORD, DepsLog::Deps::mtime, DepsLog::Deps::node_count, DepsLog::Deps::nodes, and nodes_.
Referenced by OpenForWrite().
Definition at line 80 of file deps_log.cc.
Referenced by Builder::FinishCommand().
Definition at line 86 of file deps_log.cc.
References deps(), file_, GetDeps(), Node::id(), kMaxRecordSize, DepsLog::Deps::mtime, DepsLog::Deps::node_count, DepsLog::Deps::nodes, RecordId(), and UpdateDeps().
|
private |
Definition at line 378 of file deps_log.cc.
References file_, kMaxRecordSize, nodes_, Node::path(), and Node::set_id().
Referenced by RecordDeps().
|
private |
Definition at line 367 of file deps_log.cc.
Referenced by Load(), and RecordDeps().
|
friend |
Definition at line 118 of file deps_log.h.
|
private |
Maps id -> deps of that id.
Definition at line 116 of file deps_log.h.
Referenced by GetDeps(), Recompact(), and UpdateDeps().
|
private |
Definition at line 111 of file deps_log.h.
Referenced by Close(), OpenForWrite(), RecordDeps(), and RecordId().
|
private |
Definition at line 110 of file deps_log.h.
Referenced by Load(), and OpenForWrite().
|
private |
Maps id -> Node.
Definition at line 114 of file deps_log.h.
Referenced by Load(), Recompact(), and RecordId().