authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-26 20:03:36-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-29 23:50:20-07:00
log3b2af05df10a92a0ce6ec70e2f926dfddc2d4ba9
tree89e0bebc51f59ff7dfc4516a6cd5635a69e40a6f
parent2ef3f63e1ddc2c5c6b1e1881a54d4922770a2133

std.Build: prefer {q} over '{s}'


1 files changed, 18 insertions(+), 28 deletions(-)

lib/std/Build.zig+18-28
...@@ -852,10 +852,7 @@ pub fn addModule(b: *Build, name: []const u8, options: Module.CreateOptions) *Mo...@@ -852,10 +852,7 @@ pub fn addModule(b: *Build, name: []const u8, options: Module.CreateOptions) *Mo
852 module,852 module,
853 ) catch @panic("OOM");853 ) catch @panic("OOM");
854 if (gop.found_existing) {854 if (gop.found_existing) {
855 panic(855 panic("A module with the name {q} has already been added to the package. Consider creating a private module with std.Build.createModule", .{name});
856 "A module with the name '{s}' has already been added to the package. Consider creating a private module with std.Build.createModule",
857 .{name},
858 );
859 }856 }
860 return module;857 return module;
861}858}
...@@ -1016,7 +1013,7 @@ pub fn addNamedWriteFiles(b: *Build, name: []const u8) *Step.WriteFile {...@@ -1016,7 +1013,7 @@ pub fn addNamedWriteFiles(b: *Build, name: []const u8) *Step.WriteFile {
1016 ) catch @panic("OOM");1013 ) catch @panic("OOM");
1017 if (gop.found_existing) {1014 if (gop.found_existing) {
1018 panic(1015 panic(
1019 "A WriteFile step with the name '{s}' has already been added to the package. Consider creating a private WriteFile step with std.Build.addWriteFiles",1016 "A WriteFile step with the name {q} has already been added to the package. Consider creating a private WriteFile step with std.Build.addWriteFiles",
1020 .{name},1017 .{name},
1021 );1018 );
1022 }1019 }
...@@ -1031,10 +1028,7 @@ pub fn addNamedLazyPath(b: *Build, name: []const u8, lp: LazyPath) void {...@@ -1031,10 +1028,7 @@ pub fn addNamedLazyPath(b: *Build, name: []const u8, lp: LazyPath) void {
1031 lp.dupe(graph),1028 lp.dupe(graph),
1032 ) catch @panic("OOM");1029 ) catch @panic("OOM");
1033 if (gop.found_existing) {1030 if (gop.found_existing) {
1034 panic(1031 panic("A LazyPath with the name {q} has already been added to the package.", .{name});
1035 "A LazyPath with the name '{s}' has already been added to the package.",
1036 .{name},
1037 );
1038 }1032 }
1039}1033}
10401034
...@@ -1137,7 +1131,7 @@ pub fn option(b: *Build, comptime T: type, name_raw: []const u8, description_raw...@@ -1137,7 +1131,7 @@ pub fn option(b: *Build, comptime T: type, name_raw: []const u8, description_raw
1137 .enum_options = enum_options,1131 .enum_options = enum_options,
1138 };1132 };
1139 if ((b.available_options_map.fetchPut(arena, name, available_option) catch @panic("OOM")) != null) {1133 if ((b.available_options_map.fetchPut(arena, name, available_option) catch @panic("OOM")) != null) {
1140 panic("option '{s}' declared twice", .{name});1134 panic("option {q} declared twice", .{name});
1141 }1135 }
11421136
1143 const option_ptr = b.user_input_options.getPtr(name) orelse return null;1137 const option_ptr = b.user_input_options.getPtr(name) orelse return null;
...@@ -1389,7 +1383,7 @@ pub fn parseTargetQuery(options: std.Target.Query.ParseOptions) error{ParseFaile...@@ -1389,7 +1383,7 @@ pub fn parseTargetQuery(options: std.Target.Query.ParseOptions) error{ParseFaile
1389 opts_copy.diagnostics = &diags;1383 opts_copy.diagnostics = &diags;
1390 return std.Target.Query.parse(opts_copy) catch |err| switch (err) {1384 return std.Target.Query.parse(opts_copy) catch |err| switch (err) {
1391 error.UnknownCpuModel => {1385 error.UnknownCpuModel => {
1392 std.debug.print("unknown CPU: '{s}'\navailable CPUs for architecture '{t}':\n", .{1386 std.debug.print("unknown CPU: {q}\navailable CPUs for architecture {t}:\n", .{
1393 diags.cpu_name.?, diags.arch.?,1387 diags.cpu_name.?, diags.arch.?,
1394 });1388 });
1395 for (diags.arch.?.allCpuModels()) |cpu| {1389 for (diags.arch.?.allCpuModels()) |cpu| {
...@@ -1399,7 +1393,7 @@ pub fn parseTargetQuery(options: std.Target.Query.ParseOptions) error{ParseFaile...@@ -1399,7 +1393,7 @@ pub fn parseTargetQuery(options: std.Target.Query.ParseOptions) error{ParseFaile
1399 },1393 },
1400 error.UnknownCpuFeature => {1394 error.UnknownCpuFeature => {
1401 std.debug.print(1395 std.debug.print(
1402 \\unknown CPU feature: '{s}'1396 \\unknown CPU feature: {q}
1403 \\available CPU features for architecture '{t}':1397 \\available CPU features for architecture '{t}':
1404 \\1398 \\
1405 , .{1399 , .{
...@@ -1412,7 +1406,7 @@ pub fn parseTargetQuery(options: std.Target.Query.ParseOptions) error{ParseFaile...@@ -1412,7 +1406,7 @@ pub fn parseTargetQuery(options: std.Target.Query.ParseOptions) error{ParseFaile
1412 },1406 },
1413 error.UnknownOperatingSystem => {1407 error.UnknownOperatingSystem => {
1414 std.debug.print(1408 std.debug.print(
1415 \\unknown OS: '{s}'1409 \\unknown OS: {q}
1416 \\available operating systems:1410 \\available operating systems:
1417 \\1411 \\
1418 , .{diags.os_name.?});1412 , .{diags.os_name.?});
...@@ -1422,9 +1416,7 @@ pub fn parseTargetQuery(options: std.Target.Query.ParseOptions) error{ParseFaile...@@ -1422,9 +1416,7 @@ pub fn parseTargetQuery(options: std.Target.Query.ParseOptions) error{ParseFaile
1422 return error.ParseFailed;1416 return error.ParseFailed;
1423 },1417 },
1424 else => |e| {1418 else => |e| {
1425 std.debug.print("unable to parse target '{s}': {s}\n", .{1419 std.debug.print("unable to parse target {q}: {t}\n", .{ options.arch_os_abi, e });
1426 options.arch_os_abi, @errorName(e),
1427 });
1428 return error.ParseFailed;1420 return error.ParseFailed;
1429 },1421 },
1430 };1422 };
...@@ -1487,7 +1479,7 @@ pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs...@@ -1487,7 +1479,7 @@ pub fn standardTargetOptionsQueryOnly(b: *Build, args: StandardTargetOptionsArgs
1487 q.serializeCpuAlloc(arena) catch @panic("OOM"),1479 q.serializeCpuAlloc(arena) catch @panic("OOM"),
1488 });1480 });
1489 }1481 }
1490 log.err("chosen target '{s}' does not match one of the allowed targets", .{1482 log.err("chosen target {q} does not match one of the allowed targets", .{
1491 selected_target.zigTriple(arena) catch @panic("OOM"),1483 selected_target.zigTriple(arena) catch @panic("OOM"),
1492 });1484 });
1493 b.markInvalidUserInput();1485 b.markInvalidUserInput();
...@@ -1542,7 +1534,7 @@ pub fn addUserInputOption(b: *Build, name_raw: []const u8, value_raw: []const u8...@@ -1542,7 +1534,7 @@ pub fn addUserInputOption(b: *Build, name_raw: []const u8, value_raw: []const u8
1542 return true;1534 return true;
1543 },1535 },
1544 .lazy_path, .lazy_path_list => {1536 .lazy_path, .lazy_path_list => {
1545 log.warn("the lazy path value type isn't added from the CLI, but somehow '{s}' is a .{f}", .{1537 log.warn("the lazy path value type isn't added from the CLI, but somehow {q} is a .{f}", .{
1546 name, std.zig.fmtId(@tagName(gop.value_ptr.value)),1538 name, std.zig.fmtId(@tagName(gop.value_ptr.value)),
1547 });1539 });
1548 return true;1540 return true;
...@@ -1710,9 +1702,7 @@ pub fn addCheckFile(...@@ -1710,9 +1702,7 @@ pub fn addCheckFile(
1710/// References a file or directory relative to the source root.1702/// References a file or directory relative to the source root.
1711pub fn path(b: *Build, sub_path: []const u8) LazyPath {1703pub fn path(b: *Build, sub_path: []const u8) LazyPath {
1712 if (fs.path.isAbsolute(sub_path)) {1704 if (fs.path.isAbsolute(sub_path)) {
1713 panic("sub_path is expected to be relative to the build root, but was this absolute path: '{s}'. Absolute paths can cause problems but can be created via Graph.cwdRelativePath", .{1705 panic("sub_path is expected to be relative to the build root, but was this absolute path: {q}. Absolute paths can cause problems but can be created via Graph.cwdRelativePath", .{sub_path});
1714 sub_path,
1715 });
1716 }1706 }
1717 return .{ .src_path = .{1707 return .{ .src_path = .{
1718 .owner = b,1708 .owner = b,
...@@ -2033,34 +2023,34 @@ pub const Dependency = struct {...@@ -2033,34 +2023,34 @@ pub const Dependency = struct {
2033 for (d.builder.install_tls.step.dependencies.items) |dep_step| {2023 for (d.builder.install_tls.step.dependencies.items) |dep_step| {
2034 const inst = dep_step.cast(Step.InstallArtifact) orelse continue;2024 const inst = dep_step.cast(Step.InstallArtifact) orelse continue;
2035 if (mem.eql(u8, inst.artifact.name, name)) {2025 if (mem.eql(u8, inst.artifact.name, name)) {
2036 if (found != null) panic("artifact name '{s}' is ambiguous", .{name});2026 if (found != null) panic("artifact name {q} is ambiguous", .{name});
2037 found = inst.artifact;2027 found = inst.artifact;
2038 }2028 }
2039 }2029 }
2040 return found orelse {2030 return found orelse {
2041 for (d.builder.install_tls.step.dependencies.items) |dep_step| {2031 for (d.builder.install_tls.step.dependencies.items) |dep_step| {
2042 const inst = dep_step.cast(Step.InstallArtifact) orelse continue;2032 const inst = dep_step.cast(Step.InstallArtifact) orelse continue;
2043 log.info("available artifact: '{s}'", .{inst.artifact.name});2033 log.info("available artifact: {q}", .{inst.artifact.name});
2044 }2034 }
2045 panic("unable to find artifact '{s}'", .{name});2035 panic("unable to find artifact {q}", .{name});
2046 };2036 };
2047 }2037 }
20482038
2049 pub fn module(d: *Dependency, name: []const u8) *Module {2039 pub fn module(d: *Dependency, name: []const u8) *Module {
2050 return d.builder.modules.get(name) orelse {2040 return d.builder.modules.get(name) orelse {
2051 panic("unable to find module '{s}'", .{name});2041 panic("unable to find module {q}", .{name});
2052 };2042 };
2053 }2043 }
20542044
2055 pub fn namedWriteFiles(d: *Dependency, name: []const u8) *Step.WriteFile {2045 pub fn namedWriteFiles(d: *Dependency, name: []const u8) *Step.WriteFile {
2056 return d.builder.named_writefiles.get(name) orelse {2046 return d.builder.named_writefiles.get(name) orelse {
2057 panic("unable to find named writefiles '{s}'", .{name});2047 panic("unable to find named writefiles {q}", .{name});
2058 };2048 };
2059 }2049 }
20602050
2061 pub fn namedLazyPath(d: *Dependency, name: []const u8) LazyPath {2051 pub fn namedLazyPath(d: *Dependency, name: []const u8) LazyPath {
2062 return d.builder.named_lazy_paths.get(name) orelse {2052 return d.builder.named_lazy_paths.get(name) orelse {
2063 panic("unable to find named lazypath '{s}'", .{name});2053 panic("unable to find named lazypath {q}", .{name});
2064 };2054 };
2065 }2055 }
20662056
...@@ -2628,7 +2618,7 @@ fn dumpBadDirnameHelp(...@@ -2628,7 +2618,7 @@ fn dumpBadDirnameHelp(
26282618
2629 if (asking_step) |as| {2619 if (asking_step) |as| {
2630 stderr.setColor(.red) catch {};2620 stderr.setColor(.red) catch {};
2631 try w.print(" The step '{s}' that is missing a dependency on the above step was created by this stack trace:\n", .{as.name});2621 try w.print(" The step {q} that is missing a dependency on the above step was created by this stack trace:\n", .{as.name});
2632 stderr.setColor(.reset) catch {};2622 stderr.setColor(.reset) catch {};
26332623
2634 as.dump(stderr);2624 as.dump(stderr);