authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-05-04 20:21:55+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-05-18 17:10:04+01:00
loged7335ce570a2cf0099487067136a8d517902ea8
tree7b624248f7789cce1e3d310f0a125847714de0dc
parent6d7c89cb40e3a36f99c82400084aa59df27f6573
signaturelock-open Commit is signed but in an unrecognized format.

incr-check: support basic modules

Allow specifying modules which the root module depends on. More complex graphs cannot currently be specified.

1 files changed, 25 insertions(+), 3 deletions(-)

tools/incr-check.zig+25-3
......@@ -106,7 +106,6 @@ pub fn main() !void {
106106 try child_args.appendSlice(arena, &.{
107107 resolved_zig_exe,
108108 "build-exe",
109 case.root_source_file,
110109 "-fincremental",
111110 "-fno-ubsan-rt",
112111 "-target",
......@@ -135,6 +134,13 @@ pub fn main() !void {
135134 if (debug_link) {
136135 try child_args.appendSlice(arena, &.{ "--debug-log", "link", "--debug-log", "link_state", "--debug-log", "link_relocs" });
137136 }
137 for (case.modules) |mod| {
138 try child_args.appendSlice(arena, &.{ "--dep", mod.name });
139 }
140 try child_args.append(arena, try std.fmt.allocPrint(arena, "-Mroot={s}", .{case.root_source_file}));
141 for (case.modules) |mod| {
142 try child_args.append(arena, try std.fmt.allocPrint(arena, "-M{s}={s}", .{ mod.name, mod.file }));
143 }
138144
139145 const zig_prog_node = target_prog_node.start("zig build-exe", 0);
140146 defer zig_prog_node.end();
......@@ -308,9 +314,8 @@ const Eval = struct {
308314 const digest = body[@sizeOf(EbpHdr)..][0..Cache.bin_digest_len];
309315 const result_dir = ".local-cache" ++ std.fs.path.sep_str ++ "o" ++ std.fs.path.sep_str ++ Cache.binToHex(digest.*);
310316
311 const name = std.fs.path.stem(std.fs.path.basename(eval.case.root_source_file));
312317 const bin_name = try std.zig.binNameAlloc(arena, .{
313 .root_name = name,
318 .root_name = "root", // corresponds to the module name "root"
314319 .target = eval.target.resolved,
315320 .output_mode = .Exe,
316321 });
......@@ -605,6 +610,7 @@ const Case = struct {
605610 updates: []Update,
606611 root_source_file: []const u8,
607612 targets: []const Target,
613 modules: []const Module,
608614
609615 const Target = struct {
610616 query: []const u8,
......@@ -626,6 +632,11 @@ const Case = struct {
626632 };
627633 };
628634
635 const Module = struct {
636 name: []const u8,
637 file: []const u8,
638 };
639
629640 const Update = struct {
630641 name: []const u8,
631642 outcome: Outcome,
......@@ -660,6 +671,7 @@ const Case = struct {
660671 const fatal = std.process.fatal;
661672
662673 var targets: std.ArrayListUnmanaged(Target) = .empty;
674 var modules: std.ArrayListUnmanaged(Module) = .empty;
663675 var updates: std.ArrayListUnmanaged(Update) = .empty;
664676 var changes: std.ArrayListUnmanaged(FullContents) = .empty;
665677 var deletes: std.ArrayListUnmanaged([]const u8) = .empty;
......@@ -698,6 +710,15 @@ const Case = struct {
698710 .resolved = resolved,
699711 .backend = backend,
700712 });
713 } else if (std.mem.eql(u8, key, "module")) {
714 const split_idx = std.mem.indexOfScalar(u8, val, '=') orelse
715 fatal("line {d}: module does not include file", .{line_n});
716 const name = val[0..split_idx];
717 const file = val[split_idx + 1 ..];
718 try modules.append(arena, .{
719 .name = name,
720 .file = file,
721 });
701722 } else if (std.mem.eql(u8, key, "update")) {
702723 if (updates.items.len > 0) {
703724 const last_update = &updates.items[updates.items.len - 1];
......@@ -811,6 +832,7 @@ const Case = struct {
811832 .updates = updates.items,
812833 .root_source_file = root_source_file orelse fatal("missing root source file", .{}),
813834 .targets = targets.items, // arena so no need for toOwnedSlice
835 .modules = modules.items,
814836 };
815837 }
816838};