From 735b6eefe92b222a0405671517b67e3b6c5cdded Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Sat, 9 Jul 2022 16:28:41 +0200 Subject: [PATCH] rename:RunCompareStep -> EmulatableRunStep Renamed to better convery the intention of the step --- lib/std/build.zig | 4 +-- lib/std/build/CheckObjectStep.zig | 6 ++-- ...nCompareStep.zig => EmulatableRunStep.zig} | 28 +++++++++++-------- 3 files changed, 21 insertions(+), 17 deletions(-) rename lib/std/build/{RunCompareStep.zig => EmulatableRunStep.zig} (93%) diff --git a/lib/std/build.zig b/lib/std/build.zig index d338aef4fb..fa778b9eab 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -26,7 +26,7 @@ pub const CheckFileStep = @import("build/CheckFileStep.zig"); pub const CheckObjectStep = @import("build/CheckObjectStep.zig"); pub const InstallRawStep = @import("build/InstallRawStep.zig"); pub const OptionsStep = @import("build/OptionsStep.zig"); -pub const RunCompareStep = @import("build/RunCompareStep.zig"); +pub const EmulatableRunStep = @import("build/EmulatableRunStep.zig"); pub const Builder = struct { install_tls: TopLevelStep, @@ -3605,7 +3605,7 @@ pub const Step = struct { translate_c, write_file, run, - run_and_compare, + emulatable_run, check_file, check_object, install_raw, diff --git a/lib/std/build/CheckObjectStep.zig b/lib/std/build/CheckObjectStep.zig index be1e741ce6..0525bbf034 100644 --- a/lib/std/build/CheckObjectStep.zig +++ b/lib/std/build/CheckObjectStep.zig @@ -12,7 +12,7 @@ const CheckObjectStep = @This(); const Allocator = mem.Allocator; const Builder = build.Builder; const Step = build.Step; -const RunCompareStep = build.RunCompareStep; +const EmulatableRunStep = build.EmulatableRunStep; pub const base_id = .check_obj; @@ -40,12 +40,12 @@ pub fn create(builder: *Builder, source: build.FileSource, obj_format: std.Targe /// Runs and (optionally) compares the output of a binary. /// Asserts `self` was generated from an executable step. -pub fn runAndCompare(self: *CheckObjectStep) *RunCompareStep { +pub fn runAndCompare(self: *CheckObjectStep) *EmulatableRunStep { const dependencies_len = self.step.dependencies.items.len; assert(dependencies_len > 0); const exe_step = self.step.dependencies.items[dependencies_len - 1]; const exe = exe_step.cast(std.build.LibExeObjStep).?; - return RunCompareStep.create(self.builder, "RunCompare", exe); + return EmulatableRunStep.create(self.builder, "EmulatableRun", exe); } /// There two types of actions currently suported: diff --git a/lib/std/build/RunCompareStep.zig b/lib/std/build/EmulatableRunStep.zig similarity index 93% rename from lib/std/build/RunCompareStep.zig rename to lib/std/build/EmulatableRunStep.zig index 635f469b39..1f36401599 100644 --- a/lib/std/build/RunCompareStep.zig +++ b/lib/std/build/EmulatableRunStep.zig @@ -14,9 +14,9 @@ const fs = std.fs; const process = std.process; const EnvMap = process.EnvMap; -const RunCompareStep = @This(); +const EmulatableRunStep = @This(); -pub const step_id = .run_and_compare; +pub const step_id = .emulatable_run; const max_stdout_size = 1 * 1024 * 1024; // 1 MiB @@ -49,13 +49,17 @@ pub const StdIoAction = union(enum) { expect_matches: []const []const u8, }; -pub fn create(builder: *Builder, name: []const u8, artifact: *LibExeObjStep) *RunCompareStep { +/// Creates a step that will execute the given artifact. This step will allow running the +/// binary through emulation when any of the emulation options such as `enable_rosetta` are set to true. +/// When set to false, and the binary is foreign, running the executable is skipped. +/// Asserts given artifact is an executable. +pub fn create(builder: *Builder, name: []const u8, artifact: *LibExeObjStep) *EmulatableRunStep { std.debug.assert(artifact.kind == .exe or artifact.kind == .test_exe); - const self = builder.allocator.create(RunCompareStep) catch unreachable; + const self = builder.allocator.create(EmulatableRunStep) catch unreachable; const hide_warnings = builder.option(bool, "hide-foreign-warnings", "Hide the warning when a foreign binary which is incompatible is skipped") orelse false; self.* = .{ .builder = builder, - .step = Step.init(.run_and_compare, name, builder.allocator, make), + .step = Step.init(.emulatable_run, name, builder.allocator, make), .exe = artifact, .env_map = null, .cwd = null, @@ -67,7 +71,7 @@ pub fn create(builder: *Builder, name: []const u8, artifact: *LibExeObjStep) *Ru } fn make(step: *Step) !void { - const self = @fieldParentPtr(RunCompareStep, "step", step); + const self = @fieldParentPtr(EmulatableRunStep, "step", step); const host_info = self.builder.host; const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root; @@ -266,7 +270,7 @@ fn make(step: *Step) !void { } } -fn addPathForDynLibs(self: *RunCompareStep, artifact: *LibExeObjStep) void { +fn addPathForDynLibs(self: *EmulatableRunStep, artifact: *LibExeObjStep) void { for (artifact.link_objects.items) |link_object| { switch (link_object) { .other_step => |other| { @@ -280,7 +284,7 @@ fn addPathForDynLibs(self: *RunCompareStep, artifact: *LibExeObjStep) void { } } -pub fn addPathDir(self: *RunCompareStep, search_path: []const u8) void { +pub fn addPathDir(self: *EmulatableRunStep, search_path: []const u8) void { const env_map = self.getEnvMap(); const key = "PATH"; @@ -294,7 +298,7 @@ pub fn addPathDir(self: *RunCompareStep, search_path: []const u8) void { } } -pub fn getEnvMap(self: *RunCompareStep) *EnvMap { +pub fn getEnvMap(self: *EmulatableRunStep) *EnvMap { return self.env_map orelse { const env_map = self.builder.allocator.create(EnvMap) catch unreachable; env_map.* = process.getEnvMap(self.builder.allocator) catch unreachable; @@ -303,11 +307,11 @@ pub fn getEnvMap(self: *RunCompareStep) *EnvMap { }; } -pub fn expectStdErrEqual(self: *RunCompareStep, bytes: []const u8) void { +pub fn expectStdErrEqual(self: *EmulatableRunStep, bytes: []const u8) void { self.stderr_action = .{ .expect_exact = self.builder.dupe(bytes) }; } -pub fn expectStdOutEqual(self: *RunCompareStep, bytes: []const u8) void { +pub fn expectStdOutEqual(self: *EmulatableRunStep, bytes: []const u8) void { self.stdout_action = .{ .expect_exact = self.builder.dupe(bytes) }; } @@ -327,7 +331,7 @@ fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void { std.debug.print("\n", .{}); } -fn warnAboutForeignBinaries(step: *RunCompareStep) void { +fn warnAboutForeignBinaries(step: *EmulatableRunStep) void { if (step.hide_foreign_binaries_warning) return; const builder = step.builder; const artifact = step.exe;