aboutsummaryrefslogtreecommitdiff
path: root/lib/build_runner.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-03-02 22:38:07 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-03-15 10:48:13 -0700
commitdcec4d55e36f48e459f4e8f218b8619d9be925db (patch)
tree0064e09c25715650b4e1ac641d5a33ec91245be1 /lib/build_runner.zig
parent9bf63b09963ca6ea1179dfaa9142498556bfac9d (diff)
downloadzig-dcec4d55e36f48e459f4e8f218b8619d9be925db.tar.gz
zig-dcec4d55e36f48e459f4e8f218b8619d9be925db.zip
eliminate stderr usage in std.Build make() functions
* Eliminate all uses of `std.debug.print` in make() functions, instead properly using the step failure reporting mechanism. * Introduce the concept of skipped build steps. These do not cause the build to fail, and they do allow their dependants to run. * RunStep gains a new flag, `skip_foreign_checks` which causes the RunStep to be skipped if stdio mode is `check` and the binary cannot be executed due to it being a foreign executable. - RunStep is improved to automatically use known interpreters to execute binaries if possible (integrating with flags such as -fqemu and -fwasmtime). It only does this after attempting a native execution and receiving a "exec file format" error. - Update RunStep to use an ArrayList for the checks rather than this ad-hoc reallocation/copying mechanism. - `expectStdOutEqual` now also implicitly adds an exit_code==0 check if there is not already an expected termination. This matches previously expected behavior from older API and can be overridden by directly setting the checks array. * Add `dest_sub_path` to `InstallArtifactStep` which allows choosing an arbitrary subdirectory relative to the prefix, as well as overriding the basename. - Delete the custom InstallWithRename step that I found deep in the test/ directory. * WriteFileStep will now update its step display name after the first file is added. * Add missing stdout checks to various standalone test case build scripts.
Diffstat (limited to 'lib/build_runner.zig')
-rw-r--r--lib/build_runner.zig35
1 files changed, 23 insertions, 12 deletions
diff --git a/lib/build_runner.zig b/lib/build_runner.zig
index 40f45d9ac8..aa846ce799 100644
--- a/lib/build_runner.zig
+++ b/lib/build_runner.zig
@@ -357,6 +357,7 @@ fn runStepNames(
}
var success_count: usize = 0;
+ var skipped_count: usize = 0;
var failure_count: usize = 0;
var pending_count: usize = 0;
var total_compile_errors: usize = 0;
@@ -379,6 +380,7 @@ fn runStepNames(
},
.dependency_failure => pending_count += 1,
.success => success_count += 1,
+ .skipped => skipped_count += 1,
.failure => {
failure_count += 1;
const compile_errors_len = s.result_error_bundle.errorMessageCount();
@@ -395,13 +397,13 @@ fn runStepNames(
if (failure_count == 0 and enable_summary != true) return cleanExit();
if (enable_summary != false) {
- const total_count = success_count + failure_count + pending_count;
+ const total_count = success_count + failure_count + pending_count + skipped_count;
ttyconf.setColor(stderr, .Cyan) catch {};
stderr.writeAll("Build Summary:") catch {};
ttyconf.setColor(stderr, .Reset) catch {};
- stderr.writer().print(" {d}/{d} steps succeeded; {d} failed", .{
- success_count, total_count, failure_count,
- }) catch {};
+ stderr.writer().print(" {d}/{d} steps succeeded", .{ success_count, total_count }) catch {};
+ if (skipped_count > 0) stderr.writer().print("; {d} skipped", .{skipped_count}) catch {};
+ if (failure_count > 0) stderr.writer().print("; {d} failed", .{failure_count}) catch {};
if (enable_summary == null) {
ttyconf.setColor(stderr, .Dim) catch {};
@@ -503,6 +505,12 @@ fn printTreeStep(
try ttyconf.setColor(stderr, .Reset);
},
+ .skipped => {
+ try ttyconf.setColor(stderr, .Yellow);
+ try stderr.writeAll(" skipped\n");
+ try ttyconf.setColor(stderr, .Reset);
+ },
+
.failure => {
try ttyconf.setColor(stderr, .Red);
if (s.result_error_bundle.errorMessageCount() > 0) {
@@ -569,6 +577,7 @@ fn checkForDependencyLoop(
.running => unreachable,
.success => unreachable,
.failure => unreachable,
+ .skipped => unreachable,
}
}
@@ -587,7 +596,7 @@ fn workerMakeOneStep(
// queue this step up again when dependencies are met.
for (s.dependencies.items) |dep| {
switch (@atomicLoad(Step.State, &dep.state, .SeqCst)) {
- .success => continue,
+ .success, .skipped => continue,
.failure, .dependency_failure => {
@atomicStore(Step.State, &s.state, .dependency_failure, .SeqCst);
return;
@@ -639,13 +648,15 @@ fn workerMakeOneStep(
}
}
- make_result catch |err| {
- assert(err == error.MakeFailed);
- @atomicStore(Step.State, &s.state, .failure, .SeqCst);
- return;
- };
-
- @atomicStore(Step.State, &s.state, .success, .SeqCst);
+ if (make_result) |_| {
+ @atomicStore(Step.State, &s.state, .success, .SeqCst);
+ } else |err| switch (err) {
+ error.MakeFailed => {
+ @atomicStore(Step.State, &s.state, .failure, .SeqCst);
+ return;
+ },
+ error.MakeSkipped => @atomicStore(Step.State, &s.state, .skipped, .SeqCst),
+ }
// Successful completion of a step, so we queue up its dependants as well.
for (s.dependants.items) |dep| {