diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 568719d..84c0a47 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -28,11 +28,11 @@ jobs: zig build -Dstatic-rtc=2107-01-01 zig build -Dsector-size=512 zig build -Dsector-size=1024 - zig build -Dsector-size=2028 + zig build -Dsector-size=2048 zig build -Dsector-size=4096 zig build -Dsector-size=512:4096 zig build -Dsector-size=1024:4096 - zig build -Dsector-size=2028:4096 + zig build -Dsector-size=2048:4096 zig build -Dvolume-count=1 zig build -Dvolume-count=2 zig build -Dvolume-count=31 diff --git a/build.zig b/build.zig index 45ebde9..c919175 100644 --- a/build.zig +++ b/build.zig @@ -1,5 +1,10 @@ const std = @import("std"); +fn bad_config(comptime fmt: []const u8, args: anytype) noreturn { + std.debug.print(fmt ++ "\n", args); + std.process.exit(1); +} + pub fn build(b: *std.Build) void { // options: @@ -63,17 +68,16 @@ pub fn build(b: *std.Build) void { }; }; - config.rtc = rtc_config orelse { - std.debug.print("Invalid time format. Expected YYYY-MM-DD!", .{}); - std.process.exit(1); - }; + config.rtc = rtc_config orelse bad_config( + "Invalid time format. Expected YYYY-MM-DD!", + .{}, + ); } const maybe_volume_count = b.option(u5, "volume-count", "Sets the total number of volumes. Mutually exclusive with -Dvolume-names"); const maybe_volume_names = b.option([]const u8, "volume-names", "Sets the comma separated list of volume names. Mutually exclusive with -Dvolume-count"); if ((maybe_volume_count != null) and (maybe_volume_names != null)) { - std.debug.print("-Dvolume-count and -Dvolume-names are mutually exclusive.", .{}); - std.process.exit(1); + bad_config("-Dvolume-count and -Dvolume-names are mutually exclusive.", .{}); } if (maybe_volume_count) |volume_count| { @@ -98,22 +102,22 @@ pub fn build(b: *std.Build) void { config.sector_size = .{ .dynamic = .{ - .minimum = std.meta.stringToEnum(SectorOption, min) orelse { - std.debug.print("Invalid value for -Dsector-size!", .{}); - std.process.exit(1); - }, - .maximum = std.meta.stringToEnum(SectorOption, max) orelse { - std.debug.print("Invalid value for -Dsector-size!", .{}); - std.process.exit(1); - }, + .minimum = std.meta.stringToEnum(SectorOption, min) orelse bad_config( + "Invalid value for -Dsector-size: '{}'", + .{std.zig.fmtEscapes(sector_config)}, + ), + .maximum = std.meta.stringToEnum(SectorOption, max) orelse bad_config( + "Invalid value for -Dsector-size: '{}'", + .{std.zig.fmtEscapes(sector_config)}, + ), }, }; } else { config.sector_size = .{ - .static = std.meta.stringToEnum(SectorOption, sector_config) orelse { - std.debug.print("Invalid value for -Dsector-size!", .{}); - std.process.exit(1); - }, + .static = std.meta.stringToEnum(SectorOption, sector_config) orelse bad_config( + "Invalid value for -Dsector-size: '{}'", + .{std.zig.fmtEscapes(sector_config)}, + ), }; } }