summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2012-01-29 16:48:13 (GMT)
committerEvan Martin <martine@danga.com>2012-01-29 16:48:13 (GMT)
commit717ccbea94a31621918ac508f98e061e9bd82469 (patch)
tree462f879444af19d4efb62589e1d9a60a5b183760 /src
parent33206906ef36d7bebfefb9a8a798217ee6851df4 (diff)
parent50c3475f47436d375d69e505e1c474c156e484fe (diff)
downloadNinja-717ccbea94a31621918ac508f98e061e9bd82469.zip
Ninja-717ccbea94a31621918ac508f98e061e9bd82469.tar.gz
Ninja-717ccbea94a31621918ac508f98e061e9bd82469.tar.bz2
Merge pull request #199 from qhuo/create-process
Mark CreateProcess "program not found" failure as non-fatal
Diffstat (limited to 'src')
-rw-r--r--src/subprocess-win32.cc22
-rw-r--r--src/subprocess_test.cc18
2 files changed, 38 insertions, 2 deletions
diff --git a/src/subprocess-win32.cc b/src/subprocess-win32.cc
index cf61feb..e757f7e 100644
--- a/src/subprocess-win32.cc
+++ b/src/subprocess-win32.cc
@@ -95,7 +95,18 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) {
/* inherit handles */ TRUE, 0,
NULL, NULL,
&startup_info, &process_info)) {
- Win32Fatal("CreateProcess");
+ DWORD error = GetLastError();
+ if (error == ERROR_FILE_NOT_FOUND) { // file (program) not found error is treated as a normal build action failure
+ if (child_pipe)
+ CloseHandle(child_pipe);
+ CloseHandle(pipe_);
+ pipe_ = NULL;
+ // child_ is already NULL;
+ buf_ = "CreateProcess failed: The system cannot find the file specified.\n";
+ return true;
+ } else {
+ Win32Fatal("CreateProcess"); // pass all other errors to Win32Fatal
+ }
}
// Close pipe channel only used by the child.
@@ -139,6 +150,10 @@ void Subprocess::OnPipeReady() {
}
bool Subprocess::Finish() {
+ if (! child_) {
+ return false;
+ }
+
// TODO: add error handling for all of these.
WaitForSingleObject(child_, INFINITE);
@@ -170,7 +185,10 @@ SubprocessSet::~SubprocessSet() {
}
void SubprocessSet::Add(Subprocess* subprocess) {
- running_.push_back(subprocess);
+ if (subprocess->child_)
+ running_.push_back(subprocess);
+ else
+ finished_.push(subprocess);
}
void SubprocessSet::DoWork() {
diff --git a/src/subprocess_test.cc b/src/subprocess_test.cc
index 47b7b56..840287b 100644
--- a/src/subprocess_test.cc
+++ b/src/subprocess_test.cc
@@ -45,6 +45,24 @@ TEST_F(SubprocessTest, BadCommandStderr) {
EXPECT_NE("", subproc->GetOutput());
}
+// Run a command that does not exist
+TEST_F(SubprocessTest, NoSuchCommand) {
+ Subprocess* subproc = new Subprocess;
+ EXPECT_TRUE(subproc->Start(&subprocs_, "ninja_no_such_command"));
+ subprocs_.Add(subproc);
+
+ while (!subproc->Done()) {
+ // Pretend we discovered that stderr was ready for writing.
+ subprocs_.DoWork();
+ }
+
+ EXPECT_FALSE(subproc->Finish());
+ EXPECT_NE("", subproc->GetOutput());
+#ifdef _WIN32
+ ASSERT_EQ("CreateProcess failed: The system cannot find the file specified.\n", subproc->GetOutput());
+#endif
+}
+
TEST_F(SubprocessTest, SetWithSingle) {
Subprocess* subproc = new Subprocess;
EXPECT_TRUE(subproc->Start(&subprocs_, kSimpleCommand));