[C++] Store SHELL value in command result
$(shell ...) command lines are executed using $(SHELL). We need to use
the same shell during regeneration check instead of hard-coding /bin/sh
or otherwise the results might be different when $(SHELL) is redefined
in the makefile.
Fixes https://github.com/google/kati/issues/53
Change-Id: I1f9809106f29f7e806324a82e2323a2f8df64b63
diff --git a/func.cc b/func.cc
index e313c9e..42b8c62 100644
--- a/func.cc
+++ b/func.cc
@@ -569,6 +569,7 @@
ShellFuncImpl(shell, cmd, &out, &fc);
if (ShouldStoreCommandResult(cmd)) {
CommandResult* cr = new CommandResult();
+ cr->shell = shell;
cr->cmd = cmd;
cr->find.reset(fc);
cr->result = out;
diff --git a/func.h b/func.h
index 8db2c7a..e78deb7 100644
--- a/func.h
+++ b/func.h
@@ -42,6 +42,7 @@
struct FindCommand;
struct CommandResult {
+ string shell;
string cmd;
unique_ptr<FindCommand> find;
string result;
diff --git a/ninja.cc b/ninja.cc
index 6fe6876..762f602 100644
--- a/ninja.cc
+++ b/ninja.cc
@@ -728,6 +728,7 @@
const vector<CommandResult*>& crs = GetShellCommandResults();
DumpInt(fp, crs.size());
for (CommandResult* cr : crs) {
+ DumpString(fp, cr->shell);
DumpString(fp, cr->cmd);
DumpString(fp, cr->result);
if (!cr->find.get()) {
diff --git a/regen.cc b/regen.cc
index 23151b4..3d03f67 100644
--- a/regen.cc
+++ b/regen.cc
@@ -52,6 +52,7 @@
};
struct ShellResult {
+ string shell;
string cmd;
string result;
vector<string> missing_dirs;
@@ -230,6 +231,7 @@
for (int i = 0; i < num_crs; i++) {
ShellResult* sr = new ShellResult;
commands_.push_back(sr);
+ LOAD_STRING(fp, &sr->shell);
LOAD_STRING(fp, &sr->cmd);
LOAD_STRING(fp, &sr->result);
sr->has_condition = LOAD_INT(fp);
@@ -339,7 +341,7 @@
COLLECT_STATS_WITH_SLOW_REPORT("shell time (regen)", sr->cmd.c_str());
string result;
- RunCommand("/bin/sh", sr->cmd, RedirectStderr::DEV_NULL, &result);
+ RunCommand(sr->shell, sr->cmd, RedirectStderr::DEV_NULL, &result);
FormatForCommandSubstitution(&result);
if (sr->result != result) {
if (g_flags.dump_kati_stamp) {