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_
Generated on Wed May 12 2021 13:49:32 for Ninja by
1.8.1.2