Skip to content

Commit

Permalink
Add exit code to the failed target
Browse files Browse the repository at this point in the history
  • Loading branch information
Felixoid committed Dec 9, 2024
1 parent 99722c3 commit ef5a5e6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ bool Builder::FinishCommand(CommandRunner::Result* result, string* err) {
running_edges_.erase(it);

status_->BuildEdgeFinished(edge, start_time_millis, end_time_millis,
result->success(), result->output);
result->status, result->output);

// The rest of this function only applies to successful commands.
if (!result->success()) {
Expand Down
3 changes: 2 additions & 1 deletion src/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define NINJA_STATUS_H_

#include <string>
#include "exit_status.h"

struct BuildConfig;
struct Edge;
Expand All @@ -29,7 +30,7 @@ struct Status {
virtual void BuildEdgeStarted(const Edge* edge,
int64_t start_time_millis) = 0;
virtual void BuildEdgeFinished(Edge* edge, int64_t start_time_millis,
int64_t end_time_millis, bool success,
int64_t end_time_millis, ExitStatus exit_code,
const std::string& output) = 0;
virtual void BuildStarted() = 0;
virtual void BuildFinished() = 0;
Expand Down
11 changes: 7 additions & 4 deletions src/status_printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "status_printer.h"
#include "exit_status.h"

#ifdef _WIN32
#include "win32port.h"
Expand All @@ -25,6 +26,7 @@

#include <stdarg.h>
#include <stdlib.h>
#include <string>

#ifdef _WIN32
#include <fcntl.h>
Expand Down Expand Up @@ -174,7 +176,7 @@ void StatusPrinter::RecalculateProgressPrediction() {
}

void StatusPrinter::BuildEdgeFinished(Edge* edge, int64_t start_time_millis,
int64_t end_time_millis, bool success,
int64_t end_time_millis, ExitStatus exit_code,
const string& output) {
time_millis_ = end_time_millis;
++finished_edges_;
Expand Down Expand Up @@ -202,16 +204,17 @@ void StatusPrinter::BuildEdgeFinished(Edge* edge, int64_t start_time_millis,
--running_edges_;

// Print the command that is spewing before printing its output.
if (!success) {
if (exit_code != 0) {
string outputs;
for (vector<Node*>::const_iterator o = edge->outputs_.begin();
o != edge->outputs_.end(); ++o)
outputs += (*o)->path() + " ";

string failed = "FAILED [code " + std::to_string(exit_code) + "]: ";
if (printer_.supports_color()) {
printer_.PrintOnNewLine("\x1B[31m" "FAILED: " "\x1B[0m" + outputs + "\n");
printer_.PrintOnNewLine("\x1B[31m" + failed + "\x1B[0m" + outputs + "\n");
} else {
printer_.PrintOnNewLine("FAILED: " + outputs + "\n");
printer_.PrintOnNewLine(failed + outputs + "\n");
}
printer_.PrintOnNewLine(edge->EvaluateCommand() + "\n");
}
Expand Down
3 changes: 2 additions & 1 deletion src/status_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <cstdint>
#include <queue>

#include "exit_status.h"
#include "explanations.h"
#include "line_printer.h"
#include "status.h"
Expand All @@ -31,7 +32,7 @@ struct StatusPrinter : Status {

void BuildEdgeStarted(const Edge* edge, int64_t start_time_millis) override;
void BuildEdgeFinished(Edge* edge, int64_t start_time_millis,
int64_t end_time_millis, bool success,
int64_t end_time_millis, ExitStatus exit_code,
const std::string& output) override;
void BuildStarted() override;
void BuildFinished() override;
Expand Down

0 comments on commit ef5a5e6

Please sign in to comment.