Date: Wed, 6 Apr 2016 17:15:45 +0300 Subject: [PATCH] [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 --- func.cc | 1 + func.h | 1 + ninja.cc | 1 + regen.cc | 4 +++- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/func.cc b/func.cc index e313c9e..42b8c62 100644 --- a/func.cc +++ b/func.cc @@ -569,6 +569,7 @@ void ShellFunc(const vector& args, Evaluator* ev, string* s) { 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 @@ FuncInfo* GetFuncInfo(StringPiece name); struct FindCommand; struct CommandResult { + string shell; string cmd; unique_ptr find; string result; diff --git a/ninja.cc b/ninja.cc index f6e0481..41a28a5 100644 --- a/ninja.cc +++ b/ninja.cc @@ -735,6 +735,7 @@ class NinjaGenerator { const vector& 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 @@ class StampChecker { }; struct ShellResult { + string shell; string cmd; string result; vector missing_dirs; @@ -230,6 +231,7 @@ class StampChecker { 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 @@ class StampChecker { 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) { -- 2.5.5