1492 add column headers to .ninja_log

This commit is contained in:
Guilhem Charles 2019-01-12 13:35:44 +01:00
parent 6e02ebc4b5
commit cfd0bd3007
2 changed files with 8 additions and 5 deletions

View File

@ -49,6 +49,7 @@
namespace { namespace {
const char kFileSignature[] = "# ninja log v%d\n"; const char kFileSignature[] = "# ninja log v%d\n";
const char kFileColumnLabels[] = "# start_time end_time mtime command hash\n";
const int kOldestSupportedVersion = 4; const int kOldestSupportedVersion = 4;
const int kCurrentVersion = 5; const int kCurrentVersion = 5;
@ -144,7 +145,8 @@ bool BuildLog::OpenForWrite(const string& path, const BuildLogUser& user,
fseek(log_file_, 0, SEEK_END); fseek(log_file_, 0, SEEK_END);
if (ftell(log_file_) == 0) { if (ftell(log_file_) == 0) {
if (fprintf(log_file_, kFileSignature, kCurrentVersion) < 0) { if (fprintf(log_file_, kFileSignature, kCurrentVersion) < 0 ||
fprintf(log_file_, kFileColumnLabels) < 0) {
*err = strerror(errno); *err = strerror(errno);
return false; return false;
} }

View File

@ -70,8 +70,9 @@ TEST_F(BuildLogTest, WriteRead) {
} }
TEST_F(BuildLogTest, FirstWriteAddsSignature) { TEST_F(BuildLogTest, FirstWriteAddsSignature) {
const char kExpectedVersion[] = "# ninja log vX\n"; const char kExpectedContent[] = "# ninja log vX\n"
const size_t kVersionPos = strlen(kExpectedVersion) - 2; // Points at 'X'. "# start_time end_time mtime command hash\n";
const size_t kVersionPos = 13; // Points at 'X'.
BuildLog log; BuildLog log;
string contents, err; string contents, err;
@ -84,7 +85,7 @@ TEST_F(BuildLogTest, FirstWriteAddsSignature) {
ASSERT_EQ("", err); ASSERT_EQ("", err);
if (contents.size() >= kVersionPos) if (contents.size() >= kVersionPos)
contents[kVersionPos] = 'X'; contents[kVersionPos] = 'X';
EXPECT_EQ(kExpectedVersion, contents); EXPECT_EQ(kExpectedContent, contents);
// Opening the file anew shouldn't add a second version string. // Opening the file anew shouldn't add a second version string.
EXPECT_TRUE(log.OpenForWrite(kTestFilename, *this, &err)); EXPECT_TRUE(log.OpenForWrite(kTestFilename, *this, &err));
@ -96,7 +97,7 @@ TEST_F(BuildLogTest, FirstWriteAddsSignature) {
ASSERT_EQ("", err); ASSERT_EQ("", err);
if (contents.size() >= kVersionPos) if (contents.size() >= kVersionPos)
contents[kVersionPos] = 'X'; contents[kVersionPos] = 'X';
EXPECT_EQ(kExpectedVersion, contents); EXPECT_EQ(kExpectedContent, contents);
} }
TEST_F(BuildLogTest, DoubleEntry) { TEST_F(BuildLogTest, DoubleEntry) {