Skip to content

Commit

Permalink
[C++] Add support for .POSIX:
Browse files Browse the repository at this point in the history
Add a global flag that is set to "true" when .POSIX: is encountered. The
flag will switch the bash flags from "-c" to "-ec", i.e. enable correct
error handling of shell command lines.

Fixes google/kati#48

Change-Id: Ieea386742b05b52d209b74e640e14212f0e2da88
  • Loading branch information
Stefan Becker committed Apr 12, 2016
1 parent cd060c5 commit 187bf08
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion dep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "eval.h"
#include "fileutil.h"
#include "flags.h"
#include "log.h"
#include "rule.h"
#include "stats.h"
Expand Down Expand Up @@ -261,6 +262,10 @@ class DepBuilder {
for (Symbol t : targets)
phony_.insert(t);
}
if (GetRuleInputs(Intern(".POSIX"), &targets, &loc)) {
// .POSIX: enables bash -e command line option globally
g_flags.posix_shell = true;
}
if (GetRuleInputs(Intern(".KATI_RESTAT"), &targets, &loc)) {
for (Symbol t : targets)
restat_.insert(t);
Expand All @@ -287,7 +292,6 @@ class DepBuilder {
".EXPORT_ALL_VARIABLES",
".NOTPARALLEL",
".ONESHELL",
".POSIX",
NULL
};
for (const char** p = kUnsupportedBuiltinTargets; *p; p++) {
Expand Down
1 change: 1 addition & 0 deletions flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct Flags {
bool is_dry_run;
bool is_silent_mode;
bool is_syntax_check_only;
bool posix_shell;
bool regen;
bool regen_ignoring_kati_binary;
bool use_find_emulator;
Expand Down
4 changes: 3 additions & 1 deletion ninja.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class NinjaGenerator {
default_target_(NULL) {
ev_->set_avoid_io(true);
shell_ = EscapeNinja(ev->EvalVar(kShellSym));
shell_flags_ = g_flags.posix_shell ? "ec" : "c";
const string use_goma_str = ev->EvalVar(Intern("USE_GOMA"));
use_goma_ = !(use_goma_str.empty() || use_goma_str == "false");
if (g_flags.goma_dir)
Expand Down Expand Up @@ -501,7 +502,7 @@ class NinjaGenerator {
*o << " command = " << shell_ << " $out.rsp\n";
} else {
EscapeShell(&cmd_buf);
*o << " command = " << shell_ << " -c \"" << cmd_buf << "\"\n";
*o << " command = " << shell_ << " -" << shell_flags_ << " \"" << cmd_buf << "\"\n";
}
if (node->is_restat) {
*o << " restat = 1\n";
Expand Down Expand Up @@ -769,6 +770,7 @@ class NinjaGenerator {
bool use_goma_;
string gomacc_;
string shell_;
string shell_flags_;
map<string, string> used_envs_;
string kati_binary_;
const double start_time_;
Expand Down

0 comments on commit 187bf08

Please sign in to comment.