diff options
-rw-r--r-- | func.cc | 16 | ||||
-rw-r--r-- | testcase/shell_arith_in_recipe.mk | 2 |
2 files changed, 17 insertions, 1 deletions
@@ -422,9 +422,23 @@ static string SortWordsInString(StringPiece s) { } #endif + +// A hack for Android build. We need to evaluate things like $((3+4)) +// when we emit ninja file, because the result of such expressions +// will be passed to other make functions. +// TODO: Maybe we should introduce a helper binary which evaluate +// make expressions at ninja-time. +static bool HasNoIoInShellScript(const string& cmd) { + if (cmd.empty()) + return true; + if (HasPrefix(cmd, "echo $((") && cmd[cmd.size()-1] == ')') + return true; + return false; +} + void ShellFunc(const vector<Value*>& args, Evaluator* ev, string* s) { shared_ptr<string> cmd = args[0]->Eval(ev); - if (ev->avoid_io()) { + if (ev->avoid_io() && !HasNoIoInShellScript(*cmd)) { *s += "$("; *s += *cmd; *s += ")"; diff --git a/testcase/shell_arith_in_recipe.mk b/testcase/shell_arith_in_recipe.mk new file mode 100644 index 0000000..c21fa12 --- /dev/null +++ b/testcase/shell_arith_in_recipe.mk @@ -0,0 +1,2 @@ +test: + echo $(filter 0,$(shell echo $$((1-1)))) |