aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2020-04-21 12:18:45 -0700
committerGitHub <noreply@github.com>2020-04-21 12:18:45 -0700
commitd555ba8ee8c53fee55e4532fcacff2a03fca2d6e (patch)
tree862c9dc0c00580e162b491079554316ebb5544a2
parent2ed78597a2530631a7edd000d1623f8ccae07596 (diff)
parent0cf3d2d5c0204fed5023575698da9c8b9d8681fe (diff)
downloadplatform_build_kati-d555ba8ee8c53fee55e4532fcacff2a03fca2d6e.tar.gz
platform_build_kati-d555ba8ee8c53fee55e4532fcacff2a03fca2d6e.tar.bz2
platform_build_kati-d555ba8ee8c53fee55e4532fcacff2a03fca2d6e.zip
Merge pull request #186 from danw/improve_regen_dump
Improve regen dump
-rw-r--r--func.cc4
-rw-r--r--func.h2
-rw-r--r--ninja.cc2
-rw-r--r--regen.cc5
-rw-r--r--regen_dump.cc162
5 files changed, 155 insertions, 20 deletions
diff --git a/func.cc b/func.cc
index e38e0e7..b0837da 100644
--- a/func.cc
+++ b/func.cc
@@ -590,6 +590,7 @@ void ShellFunc(const vector<Value*>& args, Evaluator* ev, string* s) {
cr->cmd = cmd;
cr->find.reset(fc);
cr->result = out;
+ cr->loc = ev->loc();
g_command_results.push_back(cr);
}
*s += out;
@@ -712,6 +713,7 @@ static void FileReadFunc(Evaluator* ev, const string& filename, string* s) {
CommandResult* cr = new CommandResult();
cr->op = CommandOp::READ_MISSING;
cr->cmd = filename;
+ cr->loc = ev->loc();
g_command_results.push_back(cr);
}
return;
@@ -745,6 +747,7 @@ static void FileReadFunc(Evaluator* ev, const string& filename, string* s) {
CommandResult* cr = new CommandResult();
cr->op = CommandOp::READ;
cr->cmd = filename;
+ cr->loc = ev->loc();
g_command_results.push_back(cr);
}
*s += out;
@@ -772,6 +775,7 @@ static void FileWriteFunc(Evaluator* ev,
cr->op = CommandOp::WRITE;
cr->cmd = filename;
cr->result = text;
+ cr->loc = ev->loc();
g_command_results.push_back(cr);
}
}
diff --git a/func.h b/func.h
index 4ba03b6..72f90fd 100644
--- a/func.h
+++ b/func.h
@@ -20,6 +20,7 @@
#include <vector>
#include "expr.h"
+#include "loc.h"
using namespace std;
@@ -57,6 +58,7 @@ struct CommandResult {
string cmd;
unique_ptr<FindCommand> find;
string result;
+ Loc loc;
};
const vector<CommandResult*>& GetShellCommandResults();
diff --git a/ninja.cc b/ninja.cc
index 1a8332e..f53b15b 100644
--- a/ninja.cc
+++ b/ninja.cc
@@ -771,6 +771,8 @@ class NinjaGenerator {
DumpString(fp, cr->shellflag);
DumpString(fp, cr->cmd);
DumpString(fp, cr->result);
+ DumpString(fp, cr->loc.filename);
+ DumpInt(fp, cr->loc.lineno);
if (cr->op == CommandOp::FIND) {
vector<string> missing_dirs;
diff --git a/regen.cc b/regen.cc
index 4374f81..1cb94e0 100644
--- a/regen.cc
+++ b/regen.cc
@@ -245,6 +245,11 @@ class StampChecker {
LOAD_STRING(fp, &sr->cmd);
LOAD_STRING(fp, &sr->result);
+ string file;
+ // Ignore debug info
+ LOAD_STRING(fp, &file);
+ LOAD_INT(fp);
+
if (sr->op == CommandOp::FIND) {
int num_missing_dirs = LOAD_INT(fp);
for (int j = 0; j < num_missing_dirs; j++) {
diff --git a/regen_dump.cc b/regen_dump.cc
index 255add1..9916a3f 100644
--- a/regen_dump.cc
+++ b/regen_dump.cc
@@ -22,17 +22,38 @@
#include <stdio.h>
#include <string>
+#include <vector>
+#include "func.h"
#include "io.h"
#include "log.h"
#include "strutil.h"
+vector<string> LoadVecString(FILE* fp) {
+ int count = LoadInt(fp);
+ if (count < 0) {
+ ERROR("Incomplete stamp file");
+ }
+ vector<string> ret(count);
+ for (int i = 0; i < count; i++) {
+ if (!LoadString(fp, &ret[i])) {
+ ERROR("Incomplete stamp file");
+ }
+ }
+ return ret;
+}
+
int main(int argc, char* argv[]) {
bool dump_files = false;
bool dump_env = false;
+ bool dump_globs = false;
+ bool dump_cmds = false;
+ bool dump_finds = false;
if (argc == 1) {
- fprintf(stderr, "Usage: ckati_stamp_dump [--env] [--files] <stamp>\n");
+ fprintf(stderr,
+ "Usage: ckati_stamp_dump [--env] [--files] [--globs] [--cmds] "
+ "[--finds] <stamp>\n");
return 1;
}
@@ -42,13 +63,19 @@ int main(int argc, char* argv[]) {
dump_env = true;
} else if (!strcmp(arg, "--files")) {
dump_files = true;
+ } else if (!strcmp(arg, "--globs")) {
+ dump_globs = true;
+ } else if (!strcmp(arg, "--cmds")) {
+ dump_cmds = true;
+ } else if (!strcmp(arg, "--finds")) {
+ dump_finds = true;
} else {
fprintf(stderr, "Unknown option: %s", arg);
return 1;
}
}
- if (!dump_files && !dump_env) {
+ if (!dump_files && !dump_env && !dump_globs && !dump_cmds && !dump_finds) {
dump_files = true;
}
@@ -62,26 +89,26 @@ int main(int argc, char* argv[]) {
if (r != 1)
ERROR("Incomplete stamp file");
- int num_files = LoadInt(fp);
- if (num_files < 0)
- ERROR("Incomplete stamp file");
- for (int i = 0; i < num_files; i++) {
- string s;
- if (!LoadString(fp, &s))
- ERROR("Incomplete stamp file");
- if (dump_files)
- printf("%s\n", s.c_str());
+ //
+ // See regen.cc CheckStep1 for how this is read normally
+ //
+
+ {
+ auto files = LoadVecString(fp);
+ if (dump_files) {
+ for (auto f : files) {
+ printf("%s\n", f.c_str());
+ }
+ }
}
- int num_undefineds = LoadInt(fp);
- if (num_undefineds < 0)
- ERROR("Incomplete stamp file");
- for (int i = 0; i < num_undefineds; i++) {
- string s;
- if (!LoadString(fp, &s))
- ERROR("Incomplete stamp file");
- if (dump_env)
- printf("undefined: %s\n", s.c_str());
+ {
+ auto undefined = LoadVecString(fp);
+ if (dump_env) {
+ for (auto s : undefined) {
+ printf("undefined: %s\n", s.c_str());
+ }
+ }
}
int num_envs = LoadInt(fp);
@@ -98,5 +125,100 @@ int main(int argc, char* argv[]) {
printf("%s: %s\n", name.c_str(), val.c_str());
}
+ int num_globs = LoadInt(fp);
+ if (num_globs < 0)
+ ERROR("Incomplete stamp file");
+ for (int i = 0; i < num_globs; i++) {
+ string pat;
+ if (!LoadString(fp, &pat))
+ ERROR("Incomplete stamp file");
+
+ auto files = LoadVecString(fp);
+ if (dump_globs) {
+ printf("%s\n", pat.c_str());
+
+ for (auto s : files) {
+ printf(" %s\n", s.c_str());
+ }
+ }
+ }
+
+ int num_cmds = LoadInt(fp);
+ if (num_cmds < 0)
+ ERROR("Incomplete stamp file");
+ for (int i = 0; i < num_cmds; i++) {
+ CommandOp op = static_cast<CommandOp>(LoadInt(fp));
+ string shell, shellflag, cmd, result, file;
+ if (!LoadString(fp, &shell))
+ ERROR("Incomplete stamp file");
+ if (!LoadString(fp, &shellflag))
+ ERROR("Incomplete stamp file");
+ if (!LoadString(fp, &cmd))
+ ERROR("Incomplete stamp file");
+ if (!LoadString(fp, &result))
+ ERROR("Incomplete stamp file");
+ if (!LoadString(fp, &file))
+ ERROR("Incomplete stamp file");
+ int line = LoadInt(fp);
+ if (line < 0)
+ ERROR("Incomplete stamp file");
+
+ if (op == CommandOp::FIND) {
+ auto missing_dirs = LoadVecString(fp);
+ auto files = LoadVecString(fp);
+ auto read_dirs = LoadVecString(fp);
+
+ if (dump_finds) {
+ printf("cmd type: FIND\n");
+ printf(" shell: %s\n", shell.c_str());
+ printf(" shell flags: %s\n", shellflag.c_str());
+ printf(" loc: %s:%d\n", file.c_str(), line);
+ printf(" cmd: %s\n", cmd.c_str());
+ if (result.length() > 0 && result.length() < 500 &&
+ result.find('\n') == std::string::npos) {
+ printf(" output: %s\n", result.c_str());
+ } else {
+ printf(" output: <%zu bytes>\n", result.length());
+ }
+ printf(" missing dirs:\n");
+ for (auto d : missing_dirs) {
+ printf(" %s\n", d.c_str());
+ }
+ printf(" files:\n");
+ for (auto f : files) {
+ printf(" %s\n", f.c_str());
+ }
+ printf(" read dirs:\n");
+ for (auto d : read_dirs) {
+ printf(" %s\n", d.c_str());
+ }
+ printf("\n");
+ }
+ } else if (dump_cmds) {
+ if (op == CommandOp::SHELL) {
+ printf("cmd type: SHELL\n");
+ printf(" shell: %s\n", shell.c_str());
+ printf(" shell flags: %s\n", shellflag.c_str());
+ } else if (op == CommandOp::READ) {
+ printf("cmd type: READ\n");
+ } else if (op == CommandOp::READ_MISSING) {
+ printf("cmd type: READ_MISSING\n");
+ } else if (op == CommandOp::WRITE) {
+ printf("cmd type: WRITE\n");
+ } else if (op == CommandOp::APPEND) {
+ printf("cmd type: APPEND\n");
+ }
+ printf(" loc: %s:%d\n", file.c_str(), line);
+ printf(" cmd: %s\n", cmd.c_str());
+ if (result.length() > 0 && result.length() < 500 &&
+ result.find('\n') == std::string::npos) {
+ printf(" output: %s\n", result.c_str());
+ } else {
+ printf(" output: <%zu bytes>\n", result.length());
+ }
+ printf("\n");
+ }
+ }
+
return 0;
}