Ninja
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
BuildLog Struct Reference

Store a log of every command ran for every build. More...

#include <build_log.h>

Classes

struct  LogEntry
 

Public Types

typedef ExternalStringHashMap< std::unique_ptr< LogEntry > >::Type Entries
 

Public Member Functions

 BuildLog ()
 
void Close ()
 
const Entriesentries () const
 
LoadStatus Load (const std::string &path, std::string *err)
 Load the on-disk log. More...
 
LogEntryLookupByOutput (const std::string &path)
 Lookup a previously-run command by its output path. More...
 
bool OpenForWrite (const std::string &path, const BuildLogUser &user, std::string *err)
 Prepares writing to the log file without actually opening it - that will happen when/if it's needed. More...
 
bool Recompact (const std::string &path, const BuildLogUser &user, std::string *err)
 Rewrite the known log entries, throwing away old data. More...
 
bool RecordCommand (Edge *edge, int start_time, int end_time, TimeStamp mtime=0)
 
bool Restat (StringPiece path, const DiskInterface &disk_interface, int output_count, char **outputs, std::string *err)
 Restat all outputs in the log. More...
 
bool WriteEntry (FILE *f, const LogEntry &entry)
 Serialize an entry into a log file. More...
 
 ~BuildLog ()
 

Private Member Functions

bool OpenForWriteIfNeeded ()
 Should be called before using log_file_. More...
 

Private Attributes

Entries entries_
 
FILE * log_file_ = nullptr
 
std::string log_file_path_
 
bool needs_recompaction_ = false
 

Detailed Description

Store a log of every command ran for every build.

It has a few uses:

1) (hashes of) command lines for existing output files, so we know when we need to rebuild due to the command changing 2) timing information, perhaps for generating reports 3) restat information

Definition at line 45 of file build_log.h.

Member Typedef Documentation

◆ Entries

typedef ExternalStringHashMap<std::unique_ptr<LogEntry> >::Type BuildLog::Entries

Definition at line 95 of file build_log.h.

Constructor & Destructor Documentation

◆ BuildLog()

BuildLog::BuildLog ( )
default

◆ ~BuildLog()

BuildLog::~BuildLog ( )

Definition at line 73 of file build_log.cc.

References Close().

Member Function Documentation

◆ Close()

void BuildLog::Close ( )

Definition at line 125 of file build_log.cc.

References log_file_, and OpenForWriteIfNeeded().

Referenced by Builder::Build(), Recompact(), Restat(), and ~BuildLog().

◆ entries()

const Entries& BuildLog::entries ( ) const
inline

Definition at line 96 of file build_log.h.

References entries_.

◆ Load()

LoadStatus BuildLog::Load ( const std::string &  path,
std::string *  err 
)

◆ LookupByOutput()

BuildLog::LogEntry * BuildLog::LookupByOutput ( const std::string &  path)

Lookup a previously-run command by its output path.

Definition at line 327 of file build_log.cc.

References entries_.

Referenced by TEST_F().

◆ OpenForWrite()

bool BuildLog::OpenForWrite ( const std::string &  path,
const BuildLogUser user,
std::string *  err 
)

Prepares writing to the log file without actually opening it - that will happen when/if it's needed.

Definition at line 77 of file build_log.cc.

References log_file_, log_file_path_, needs_recompaction_, and Recompact().

Referenced by BuildTest::RebuildTarget(), TEST_F(), and WriteTestData().

◆ OpenForWriteIfNeeded()

bool BuildLog::OpenForWriteIfNeeded ( )
private

Should be called before using log_file_.

When false is returned, errno will be set.

Definition at line 132 of file build_log.cc.

References kCurrentVersion, kFileSignature, log_file_, log_file_path_, and SetCloseOnExec().

Referenced by Close(), and RecordCommand().

◆ Recompact()

bool BuildLog::Recompact ( const std::string &  path,
const BuildLogUser user,
std::string *  err 
)

Rewrite the known log entries, throwing away old data.

Definition at line 340 of file build_log.cc.

References Close(), entries_, BuildLogUser::IsPathDead(), kCurrentVersion, kFileSignature, METRIC_RECORD, platformAwareUnlink(), and WriteEntry().

Referenced by OpenForWrite().

◆ RecordCommand()

bool BuildLog::RecordCommand ( Edge edge,
int  start_time,
int  end_time,
TimeStamp  mtime = 0 
)

◆ Restat()

bool BuildLog::Restat ( StringPiece  path,
const DiskInterface disk_interface,
int  output_count,
char **  outputs,
std::string *  err 
)

◆ WriteEntry()

bool BuildLog::WriteEntry ( FILE *  f,
const LogEntry entry 
)

Member Data Documentation

◆ entries_

Entries BuildLog::entries_
private

Definition at line 103 of file build_log.h.

Referenced by entries(), Load(), LookupByOutput(), Recompact(), RecordCommand(), and Restat().

◆ log_file_

FILE* BuildLog::log_file_ = nullptr
private

Definition at line 104 of file build_log.h.

Referenced by Close(), OpenForWrite(), OpenForWriteIfNeeded(), and RecordCommand().

◆ log_file_path_

std::string BuildLog::log_file_path_
private

Definition at line 105 of file build_log.h.

Referenced by OpenForWrite(), and OpenForWriteIfNeeded().

◆ needs_recompaction_

bool BuildLog::needs_recompaction_ = false
private

Definition at line 106 of file build_log.h.

Referenced by Load(), and OpenForWrite().


The documentation for this struct was generated from the following files: