Skip to content

Commit 91bffbe

Browse files
committed
Propagate supbrocess' exit codes to the ninja exit code
1 parent d79d8f7 commit 91bffbe

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

src/build.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ struct CommandRunner {
155155
struct Result {
156156
Result() : edge(NULL) {}
157157
Edge* edge;
158-
ExitStatus status;
158+
int status;
159159
std::string output;
160160
bool success() const { return status == ExitSuccess; }
161161
};

src/subprocess-posix.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void Subprocess::OnPipeReady() {
147147
}
148148
}
149149

150-
ExitStatus Subprocess::Finish() {
150+
int Subprocess::Finish() {
151151
assert(pid_ != -1);
152152
int status;
153153
if (waitpid(pid_, &status, 0) < 0)
@@ -164,16 +164,17 @@ ExitStatus Subprocess::Finish() {
164164
}
165165
#endif
166166

167+
int exit = 0;
167168
if (WIFEXITED(status)) {
168-
int exit = WEXITSTATUS(status);
169+
exit = WEXITSTATUS(status);
169170
if (exit == 0)
170171
return ExitSuccess;
171172
} else if (WIFSIGNALED(status)) {
172173
if (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGTERM
173174
|| WTERMSIG(status) == SIGHUP)
174175
return ExitInterrupted;
175176
}
176-
return ExitFailure;
177+
return exit;
177178
}
178179

179180
bool Subprocess::Done() const {

src/subprocess-win32.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void Subprocess::OnPipeReady() {
185185
// function again later and get them at that point.
186186
}
187187

188-
ExitStatus Subprocess::Finish() {
188+
int Subprocess::Finish() {
189189
if (!child_)
190190
return ExitFailure;
191191

@@ -198,9 +198,8 @@ ExitStatus Subprocess::Finish() {
198198
CloseHandle(child_);
199199
child_ = NULL;
200200

201-
return exit_code == 0 ? ExitSuccess :
202-
exit_code == CONTROL_C_EXIT ? ExitInterrupted :
203-
ExitFailure;
201+
return exit_code == CONTROL_C_EXIT ? ExitInterrupted :
202+
(int)exit_code;
204203
}
205204

206205
bool Subprocess::Done() const {

src/subprocess.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct Subprocess {
4444

4545
/// Returns ExitSuccess on successful process exit, ExitInterrupted if
4646
/// the process was interrupted, ExitFailure if it otherwise failed.
47-
ExitStatus Finish();
47+
int Finish();
4848

4949
bool Done() const;
5050

src/subprocess_test.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "subprocess.h"
1616

17+
#include "exit_status.h"
1718
#include "test.h"
1819

1920
#ifndef _WIN32
@@ -50,7 +51,10 @@ TEST_F(SubprocessTest, BadCommandStderr) {
5051
subprocs_.DoWork();
5152
}
5253

53-
EXPECT_EQ(ExitFailure, subproc->Finish());
54+
int exit = subproc->Finish();
55+
EXPECT_NE(ExitSuccess, exit);
56+
EXPECT_NE(ExitFailure, exit);
57+
EXPECT_NE(ExitInterrupted, exit);
5458
EXPECT_NE("", subproc->GetOutput());
5559
}
5660

@@ -64,7 +68,10 @@ TEST_F(SubprocessTest, NoSuchCommand) {
6468
subprocs_.DoWork();
6569
}
6670

67-
EXPECT_EQ(ExitFailure, subproc->Finish());
71+
int exit = subproc->Finish();
72+
EXPECT_NE(ExitSuccess, exit);
73+
EXPECT_NE(ExitFailure, exit);
74+
EXPECT_NE(ExitInterrupted, exit);
6875
EXPECT_NE("", subproc->GetOutput());
6976
#ifdef _WIN32
7077
ASSERT_EQ("CreateProcess failed: The system cannot find the file "

0 commit comments

Comments
 (0)