diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 3bfd8c9a7d..bac7abdd98 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -1164,7 +1164,14 @@ pub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run { // It doesn't have to be native. We catch that if you actually try to run it. // Consider that this is declarative; the run step may not be run unless a user // option is supplied. - const run_step = Step.Run.create(b, b.fmt("run {s}", .{exe.name})); + + // Avoid the common case of the step name looking like "run test test". + const step_name = if (exe.kind.isTest() and mem.eql(u8, exe.name, "test")) + b.fmt("run {s}", .{@tagName(exe.kind)}) + else + b.fmt("run {s} {s}", .{ @tagName(exe.kind), exe.name }); + + const run_step = Step.Run.create(b, step_name); run_step.producer = exe; if (exe.kind == .@"test") { if (exe.exec_cmd_args) |exec_cmd_args| { diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 924dc18f91..fa84ac5e6e 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -292,6 +292,13 @@ pub const Kind = enum { obj, @"test", test_obj, + + pub fn isTest(kind: Kind) bool { + return switch (kind) { + .exe, .lib, .obj => false, + .@"test", .test_obj => true, + }; + } }; pub const HeaderInstallation = union(enum) { @@ -368,19 +375,16 @@ pub fn create(owner: *std.Build, options: Options) *Compile { panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name}); } - // Avoid the common case of the step name looking like "zig test test". - const name_adjusted = if ((options.kind == .@"test" or options.kind == .test_obj) and mem.eql(u8, name, "test")) - "" - else - owner.fmt("{s} ", .{name}); - const resolved_target = options.root_module.resolved_target orelse @panic("the root Module of a Compile step must be created with a known 'target' field"); const target = resolved_target.result; - const step_name = owner.fmt("compile {s} {s}{s} {s}", .{ - @tagName(options.kind), - name_adjusted, + const step_name = owner.fmt("compile {s} {s} {s}", .{ + // Avoid the common case of the step name looking like "compile test test". + if (options.kind.isTest() and mem.eql(u8, name, "test")) + @tagName(options.kind) + else + owner.fmt("{s} {s}", .{ @tagName(options.kind), name }), @tagName(options.root_module.optimize orelse .Debug), resolved_target.query.zigTriple(owner.allocator) catch @panic("OOM"), }); diff --git a/test/behavior/x86_64/build.zig b/test/behavior/x86_64/build.zig index 8d0e27f964..5aea349297 100644 --- a/test/behavior/x86_64/build.zig +++ b/test/behavior/x86_64/build.zig @@ -115,6 +115,7 @@ pub fn build(b: *std.Build) void { }, }) |query| { const target = b.resolveTargetQuery(query); + const triple = query.zigTriple(b.allocator) catch @panic("OOM"); const cpu = query.serializeCpuAlloc(b.allocator) catch @panic("OOM"); for ([_][]const u8{ "access.zig", @@ -133,16 +134,14 @@ pub fn build(b: *std.Build) void { .use_lld = false, .root_module = test_mod, }); + test_exe.step.name = b.fmt("{s} {s}", .{ test_exe.step.name, cpu }); if (!target.result.cpu.has(.x86, .sse2)) { test_exe.bundle_compiler_rt = false; test_mod.linkLibrary(compiler_rt_lib); } const test_run = b.addRunArtifact(test_exe); + test_run.step.name = b.fmt("{s} {s} {s}", .{ test_run.step.name, triple, cpu }); b.default_step.dependOn(&test_run.step); - for ([_]*std.Build.Step{ - &test_exe.step, - &test_run.step, - }) |step| step.name = b.fmt("{s} {s}", .{ step.name, cpu }); } } } diff --git a/test/link/link.zig b/test/link/link.zig index 59198e6c8e..5d1a02f23e 100644 --- a/test/link/link.zig +++ b/test/link/link.zig @@ -13,7 +13,7 @@ pub const Options = struct { }; pub fn addTestStep(b: *Build, prefix: []const u8, opts: Options) *Step { - const target = opts.target.result.zigTriple(b.allocator) catch @panic("OOM"); + const target = opts.target.query.zigTriple(b.allocator) catch @panic("OOM"); const optimize = @tagName(opts.optimize); const use_llvm = if (opts.use_llvm) "llvm" else "no-llvm"; const use_lld = if (opts.use_lld) "lld" else "no-lld"; diff --git a/test/src/Cases.zig b/test/src/Cases.zig index a36f4f3f7c..4c8eed85b6 100644 --- a/test/src/Cases.zig +++ b/test/src/Cases.zig @@ -610,7 +610,7 @@ pub fn lowerToBuildSteps( if (std.mem.indexOf(u8, case.name, test_filter)) |_| break; } else if (test_filters.len > 0) continue; - const triple_txt = case.target.result.zigTriple(b.allocator) catch @panic("OOM"); + const triple_txt = case.target.query.zigTriple(b.allocator) catch @panic("OOM"); if (test_target_filters.len > 0) { for (test_target_filters) |filter| { diff --git a/test/src/Debugger.zig b/test/src/Debugger.zig index 08202f3130..6ed888df1d 100644 --- a/test/src/Debugger.zig +++ b/test/src/Debugger.zig @@ -2447,7 +2447,7 @@ fn addTest( } else return; } if (db.options.test_target_filters.len > 0) { - const triple_txt = target.resolved.result.zigTriple(db.b.allocator) catch @panic("OOM"); + const triple_txt = target.resolved.query.zigTriple(db.b.allocator) catch @panic("OOM"); for (db.options.test_target_filters) |filter| { if (std.mem.indexOf(u8, triple_txt, filter) != null) break; } else return; diff --git a/test/src/LlvmIr.zig b/test/src/LlvmIr.zig index f6d39505b9..76200455b9 100644 --- a/test/src/LlvmIr.zig +++ b/test/src/LlvmIr.zig @@ -75,7 +75,7 @@ pub fn addExact( pub fn addCase(self: *LlvmIr, case: TestCase) void { const target = self.b.resolveTargetQuery(case.params.target); if (self.options.test_target_filters.len > 0) { - const triple_txt = target.result.zigTriple(self.b.allocator) catch @panic("OOM"); + const triple_txt = target.query.zigTriple(self.b.allocator) catch @panic("OOM"); for (self.options.test_target_filters) |filter| { if (std.mem.indexOf(u8, triple_txt, filter) != null) break; } else return; diff --git a/test/src/TranslateC.zig b/test/src/TranslateC.zig index 18d5e1ce50..2df7536342 100644 --- a/test/src/TranslateC.zig +++ b/test/src/TranslateC.zig @@ -96,7 +96,7 @@ pub fn addCase(self: *TranslateCContext, case: *const TestCase) void { const target = b.resolveTargetQuery(case.target); if (self.test_target_filters.len > 0) { - const triple_txt = target.result.zigTriple(b.allocator) catch @panic("OOM"); + const triple_txt = target.query.zigTriple(b.allocator) catch @panic("OOM"); for (self.test_target_filters) |filter| { if (std.mem.indexOf(u8, triple_txt, filter) != null) break; diff --git a/test/tests.zig b/test/tests.zig index ef0251482a..500deb8409 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -2310,8 +2310,8 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { if (options.skip_llvm and would_use_llvm) continue; const resolved_target = b.resolveTargetQuery(test_target.target); + const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM"); const target = resolved_target.result; - const triple_txt = target.zigTriple(b.allocator) catch @panic("OOM"); if (options.test_target_filters.len > 0) { for (options.test_target_filters) |filter| { @@ -2556,8 +2556,8 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { if (options.skip_llvm and would_use_llvm) continue; const resolved_target = b.resolveTargetQuery(c_abi_target.target); + const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM"); const target = resolved_target.result; - const triple_txt = target.zigTriple(b.allocator) catch @panic("OOM"); if (options.test_target_filters.len > 0) { for (options.test_target_filters) |filter| {