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
/// Store a log of every command ran for every build.
29
/// It has a few uses:
30
///
31
/// 1) (hashes of) command lines for existing output files, so we know
32
/// when we need to rebuild due to the command changing
33
/// 2) timing information, perhaps for generating reports
34
/// 3) restat information
35
struct
BuildLog
{
36
BuildLog
();
37
~
BuildLog
();
38
39
bool
OpenForWrite(
const
string
& path,
string
* err);
40
void
RecordCommand(
Edge
* edge,
int
start_time,
int
end_time,
41
TimeStamp
restat_mtime = 0);
42
void
Close();
43
44
/// Load the on-disk log.
45
bool
Load(
const
string
& path,
string
* err);
46
47
struct
LogEntry
{
48
string
output
;
49
uint64_t
command_hash
;
50
int
start_time
;
51
int
end_time
;
52
TimeStamp
restat_mtime
;
53
54
static
uint64_t
HashCommand(
StringPiece
command);
55
56
// Used by tests.
57
bool
operator==
(
const
LogEntry
& o) {
58
return
output == o.
output
&& command_hash == o.
command_hash
&&
59
start_time == o.
start_time
&& end_time == o.
end_time
&&
60
restat_mtime == o.
restat_mtime
;
61
}
62
63
explicit
LogEntry
(
const
string
& output);
64
LogEntry
(
const
string
& output,
uint64_t
command_hash,
65
int
start_time,
int
end_time,
TimeStamp
restat_mtime);
66
};
67
68
/// Lookup a previously-run command by its output path.
69
LogEntry* LookupByOutput(
const
string
& path);
70
71
/// Serialize an entry into a log file.
72
void
WriteEntry(FILE* f,
const
LogEntry& entry);
73
74
/// Rewrite the known log entries, throwing away old data.
75
bool
Recompact(
const
string
& path,
string
* err);
76
77
typedef
ExternalStringHashMap<LogEntry*>::Type
Entries
;
78
const
Entries
&
entries
()
const
{
return
entries_; }
79
80
private
:
81
Entries
entries_
;
82
FILE*
log_file_
;
83
bool
needs_recompaction_
;
84
};
85
86
#endif // NINJA_BUILD_LOG_H_
BuildLog::Entries
ExternalStringHashMap< LogEntry * >::Type Entries
Definition:
build_log.h:77
BuildLog::needs_recompaction_
bool needs_recompaction_
Definition:
build_log.h:83
BuildLog::entries
const Entries & entries() const
Definition:
build_log.h:78
BuildLog::LogEntry
Definition:
build_log.h:47
BuildLog::LogEntry::restat_mtime
TimeStamp restat_mtime
Definition:
build_log.h:52
BuildLog::LogEntry::start_time
int start_time
Definition:
build_log.h:50
BuildLog::LogEntry::end_time
int end_time
Definition:
build_log.h:51
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:57
timestamp.h
BuildLog::LogEntry::output
string output
Definition:
build_log.h:48
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:35
BuildLog::LogEntry::command_hash
uint64_t command_hash
Definition:
build_log.h:49
BuildLog::log_file_
FILE * log_file_
Definition:
build_log.h:82
ExternalStringHashMap
A template for hash_maps keyed by a StringPiece whose string is owned externally (typically by the va...
Definition:
hash_map.h:101
util.h
hash_map.h
uint64_t
unsigned long long uint64_t
Definition:
win32port.h:22
BuildLog::entries_
Entries entries_
Definition:
build_log.h:81
Generated on Sat May 31 2014 08:04:22 for Ninja by
1.8.7