Ninja
Main Page
Namespaces
Classes
Files
File List
File Members
build_log.h
Go to the documentation of this file.
1
// Copyright 2011 Google Inc. All Rights Reserved.
2
//
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
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
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.
14
15
#ifndef NINJA_BUILD_LOG_H_
16
#define NINJA_BUILD_LOG_H_
17
18
#include <string>
19
#include <stdio.h>
20
using namespace
std
;
21
22
#include "
hash_map.h
"
23
#include "
timestamp.h
"
24
#include "
util.h
"
// uint64_t
25
26
struct
Edge
;
27
28
/// Can answer questions about the manifest for the BuildLog.
29
struct
BuildLogUser
{
30
/// Return if a given output 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;
33
};
34
35
/// Store a log of every command ran for every build.
36
/// It has a few uses:
37
///
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
42
struct
BuildLog
{
43
BuildLog
();
44
~
BuildLog
();
45
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);
49
void
Close();
50
51
/// Load the on-disk log.
52
bool
Load(
const
string
& path,
string
* err);
53
54
struct
LogEntry
{
55
string
output
;
56
uint64_t
command_hash
;
57
int
start_time
;
58
int
end_time
;
59
TimeStamp
restat_mtime
;
60
61
static
uint64_t
HashCommand(
StringPiece
command);
62
63
// Used by tests.
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
;
68
}
69
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);
73
};
74
75
/// Lookup a previously-run command by its output path.
76
LogEntry* LookupByOutput(
const
string
& path);
77
78
/// Serialize an entry into a log file.
79
bool
WriteEntry(FILE* f,
const
LogEntry& entry);
80
81
/// Rewrite the known log entries, throwing away old data.
82
bool
Recompact(
const
string
& path,
const
BuildLogUser
& user,
string
* err);
83
84
typedef
ExternalStringHashMap<LogEntry*>::Type
Entries
;
85
const
Entries&
entries
()
const
{
return
entries_; }
86
87
private
:
88
Entries
entries_
;
89
FILE*
log_file_
;
90
bool
needs_recompaction_
;
91
};
92
93
#endif // NINJA_BUILD_LOG_H_
BuildLog::Entries
ExternalStringHashMap< LogEntry * >::Type Entries
Definition:
build_log.h:84
BuildLog::needs_recompaction_
bool needs_recompaction_
Definition:
build_log.h:90
BuildLog::entries
const Entries & entries() const
Definition:
build_log.h:85
BuildLog::LogEntry
Definition:
build_log.h:54
BuildLog::LogEntry::restat_mtime
TimeStamp restat_mtime
Definition:
build_log.h:59
BuildLog::LogEntry::start_time
int start_time
Definition:
build_log.h:57
BuildLog::LogEntry::end_time
int end_time
Definition:
build_log.h:58
StringPiece
StringPiece represents a slice of a string whose memory is managed externally.
Definition:
string_piece.h:27
BuildLog::LogEntry::operator==
bool operator==(const LogEntry &o)
Definition:
build_log.h:64
std
timestamp.h
BuildLog::LogEntry::output
string output
Definition:
build_log.h:55
TimeStamp
int TimeStamp
Definition:
timestamp.h:22
Edge
An edge in the dependency graph; links between Nodes using Rules.
Definition:
graph.h:137
BuildLog
Store a log of every command ran for every build.
Definition:
build_log.h:42
BuildLog::LogEntry::command_hash
uint64_t command_hash
Definition:
build_log.h:56
BuildLog::log_file_
FILE * log_file_
Definition:
build_log.h:89
ExternalStringHashMap
A template for hash_maps keyed by a StringPiece whose string is owned externally (typically by the va...
Definition:
hash_map.h:104
util.h
hash_map.h
uint64_t
unsigned long long uint64_t
Definition:
win32port.h:22
BuildLog::entries_
Entries entries_
Definition:
build_log.h:88
BuildLogUser
Can answer questions about the manifest for the BuildLog.
Definition:
build_log.h:29
Generated on Tue Nov 25 2014 14:49:07 for Ninja by
1.8.8