aboutsummaryrefslogtreecommitdiff
path: root/test
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 /test
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 'test')
-rw-r--r--test/link/macho/bugs/13457/build.zig4
-rw-r--r--test/link/macho/empty/build.zig3
-rw-r--r--test/link/macho/needed_library/build.zig1
-rw-r--r--test/link/macho/objc/build.zig4
-rw-r--r--test/link/macho/search_strategy/build.zig3
-rw-r--r--test/link/macho/stack_size/build.zig1
-rw-r--r--test/link/macho/uuid/build.zig76
-rw-r--r--test/link/wasm/extern/build.zig3
8 files changed, 30 insertions, 65 deletions
diff --git a/test/link/macho/bugs/13457/build.zig b/test/link/macho/bugs/13457/build.zig
index 3560b4a168..7ac1435015 100644
--- a/test/link/macho/bugs/13457/build.zig
+++ b/test/link/macho/bugs/13457/build.zig
@@ -13,6 +13,8 @@ pub fn build(b: *std.Build) void {
.target = target,
});
- const run = exe.runEmulatable();
+ const run = b.addRunArtifact(exe);
+ run.skip_foreign_checks = true;
+ run.expectStdOutEqual("");
test_step.dependOn(&run.step);
}
diff --git a/test/link/macho/empty/build.zig b/test/link/macho/empty/build.zig
index 586da1511b..12eb67d9c8 100644
--- a/test/link/macho/empty/build.zig
+++ b/test/link/macho/empty/build.zig
@@ -16,7 +16,8 @@ pub fn build(b: *std.Build) void {
exe.addCSourceFile("empty.c", &[0][]const u8{});
exe.linkLibC();
- const run_cmd = std.Build.EmulatableRunStep.create(b, "run", exe);
+ const run_cmd = b.addRunArtifact(exe);
+ run_cmd.skip_foreign_checks = true;
run_cmd.expectStdOutEqual("Hello!\n");
test_step.dependOn(&run_cmd.step);
}
diff --git a/test/link/macho/needed_library/build.zig b/test/link/macho/needed_library/build.zig
index 92a73d22b7..e8a58d5381 100644
--- a/test/link/macho/needed_library/build.zig
+++ b/test/link/macho/needed_library/build.zig
@@ -36,5 +36,6 @@ pub fn build(b: *std.Build) void {
check.checkNext("name @rpath/liba.dylib");
const run_cmd = check.runAndCompare();
+ run_cmd.expectStdOutEqual("");
test_step.dependOn(&run_cmd.step);
}
diff --git a/test/link/macho/objc/build.zig b/test/link/macho/objc/build.zig
index 10d293baab..9398e28a80 100644
--- a/test/link/macho/objc/build.zig
+++ b/test/link/macho/objc/build.zig
@@ -17,6 +17,8 @@ pub fn build(b: *std.Build) void {
// populate paths to the sysroot here.
exe.linkFramework("Foundation");
- const run_cmd = std.Build.EmulatableRunStep.create(b, "run", exe);
+ const run_cmd = b.addRunArtifact(exe);
+ run_cmd.skip_foreign_checks = true;
+ run_cmd.expectStdOutEqual("");
test_step.dependOn(&run_cmd.step);
}
diff --git a/test/link/macho/search_strategy/build.zig b/test/link/macho/search_strategy/build.zig
index 62757f885b..a8a4167865 100644
--- a/test/link/macho/search_strategy/build.zig
+++ b/test/link/macho/search_strategy/build.zig
@@ -27,7 +27,8 @@ pub fn build(b: *std.Build) void {
const exe = createScenario(b, optimize, target);
exe.search_strategy = .paths_first;
- const run = std.Build.EmulatableRunStep.create(b, "run", exe);
+ const run = b.addRunArtifact(exe);
+ run.skip_foreign_checks = true;
run.cwd = b.pathFromRoot(".");
run.expectStdOutEqual("Hello world");
test_step.dependOn(&run.step);
diff --git a/test/link/macho/stack_size/build.zig b/test/link/macho/stack_size/build.zig
index 3529a134eb..874f53fbff 100644
--- a/test/link/macho/stack_size/build.zig
+++ b/test/link/macho/stack_size/build.zig
@@ -21,5 +21,6 @@ pub fn build(b: *std.Build) void {
check_exe.checkNext("stacksize 100000000");
const run = check_exe.runAndCompare();
+ run.expectStdOutEqual("");
test_step.dependOn(&run.step);
}
diff --git a/test/link/macho/uuid/build.zig b/test/link/macho/uuid/build.zig
index ec7664cd72..6ff45e1175 100644
--- a/test/link/macho/uuid/build.zig
+++ b/test/link/macho/uuid/build.zig
@@ -1,5 +1,4 @@
const std = @import("std");
-const Builder = std.Build.Builder;
const CompileStep = std.Build.CompileStep;
const FileSource = std.Build.FileSource;
const Step = std.Build.Step;
@@ -38,13 +37,15 @@ fn testUuid(
// stay the same across builds.
{
const dylib = simpleDylib(b, optimize, target);
- const install_step = installWithRename(dylib, "test1.dylib");
+ const install_step = b.addInstallArtifact(dylib);
+ install_step.dest_sub_path = "test1.dylib";
install_step.step.dependOn(&dylib.step);
}
{
const dylib = simpleDylib(b, optimize, target);
dylib.strip = true;
- const install_step = installWithRename(dylib, "test2.dylib");
+ const install_step = b.addInstallArtifact(dylib);
+ install_step.dest_sub_path = "test2.dylib";
install_step.step.dependOn(&dylib.step);
}
@@ -68,70 +69,23 @@ fn simpleDylib(
return dylib;
}
-fn installWithRename(cs: *CompileStep, name: []const u8) *InstallWithRename {
- const step = InstallWithRename.create(cs.builder, cs.getOutputSource(), name);
- cs.builder.getInstallStep().dependOn(&step.step);
- return step;
-}
-
-const InstallWithRename = struct {
- pub const base_id = .custom;
-
- step: Step,
- builder: *Builder,
- source: FileSource,
- name: []const u8,
-
- pub fn create(
- builder: *Builder,
- source: FileSource,
- name: []const u8,
- ) *InstallWithRename {
- const self = builder.allocator.create(InstallWithRename) catch @panic("OOM");
- self.* = InstallWithRename{
- .builder = builder,
- .step = Step.init(builder.allocator, .{
- .id = .custom,
- .name = builder.fmt("install and rename: {s} -> {s}", .{
- source.getDisplayName(), name,
- }),
- .makeFn = make,
- }),
- .source = source,
- .name = builder.dupe(name),
- };
- return self;
- }
-
- fn make(step: *Step) anyerror!void {
- const self = @fieldParentPtr(InstallWithRename, "step", step);
- const source_path = self.source.getPath(self.builder);
- const target_path = self.builder.getInstallPath(.lib, self.name);
- self.builder.updateFile(source_path, target_path) catch |err| {
- std.log.err("Unable to rename: {s} -> {s}", .{ source_path, target_path });
- return err;
- };
- }
-};
-
const CompareUuid = struct {
pub const base_id = .custom;
step: Step,
- builder: *Builder,
lhs: []const u8,
rhs: []const u8,
- pub fn create(builder: *Builder, lhs: []const u8, rhs: []const u8) *CompareUuid {
- const self = builder.allocator.create(CompareUuid) catch @panic("OOM");
+ pub fn create(owner: *std.Build, lhs: []const u8, rhs: []const u8) *CompareUuid {
+ const self = owner.allocator.create(CompareUuid) catch @panic("OOM");
self.* = CompareUuid{
- .builder = builder,
- .step = Step.init(builder.allocator, .{
- .id = .custom,
- .name = builder.fmt("compare uuid: {s} and {s}", .{
+ .step = Step.init(.{
+ .id = base_id,
+ .name = owner.fmt("compare uuid: {s} and {s}", .{
lhs,
rhs,
}),
+ .owner = owner,
.makeFn = make,
}),
.lhs = lhs,
@@ -140,16 +94,18 @@ const CompareUuid = struct {
return self;
}
- fn make(step: *Step) anyerror!void {
+ fn make(step: *Step, prog_node: *std.Progress.Node) anyerror!void {
+ _ = prog_node;
+ const b = step.owner;
const self = @fieldParentPtr(CompareUuid, "step", step);
- const gpa = self.builder.allocator;
+ const gpa = b.allocator;
var lhs_uuid: [16]u8 = undefined;
- const lhs_path = self.builder.getInstallPath(.lib, self.lhs);
+ const lhs_path = b.getInstallPath(.lib, self.lhs);
try parseUuid(gpa, lhs_path, &lhs_uuid);
var rhs_uuid: [16]u8 = undefined;
- const rhs_path = self.builder.getInstallPath(.lib, self.rhs);
+ const rhs_path = b.getInstallPath(.lib, self.rhs);
try parseUuid(gpa, rhs_path, &rhs_uuid);
try std.testing.expectEqualStrings(&lhs_uuid, &rhs_uuid);
diff --git a/test/link/wasm/extern/build.zig b/test/link/wasm/extern/build.zig
index 569d94091a..fede2b18ab 100644
--- a/test/link/wasm/extern/build.zig
+++ b/test/link/wasm/extern/build.zig
@@ -11,7 +11,8 @@ pub fn build(b: *std.Build) void {
exe.use_llvm = false;
exe.use_lld = false;
- const run = exe.runEmulatable();
+ const run = b.addRunArtifact(exe);
+ run.skip_foreign_checks = true;
run.expectStdOutEqual("Result: 30");
const test_step = b.step("test", "Run linker test");