authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-27 10:54:17-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:34-07:00
log378b790ee20fa64c549d114204dafc19d1e33362
tree56852733dc08db8a9026afbecd997467acc5b57d
parent5a4b5b549b606bdad026b977fd3fa669b6f7070d

maker: port more of Run step over


2 files changed, 53 insertions(+), 59 deletions(-)

lib/compiler/Maker/Step/Run.zig+49-59
......@@ -48,6 +48,7 @@ pub fn make(
4848 const conf_run = conf_step.extended.get(conf.extra).run;
4949 const argv_list = &run.argv;
5050 const output_placeholders = &run.output_placeholders;
51 const cache_root = graph.local_cache_root;
5152
5253 argv_list.clearRetainingCapacity();
5354 output_placeholders.clearRetainingCapacity();
......@@ -174,51 +175,62 @@ pub fn make(
174175 }
175176 }
176177
177 if (true) @panic("TODO");
178
179178 switch (conf_run.stdin.u) {
180179 .bytes => |bytes| {
181 man.hash.addBytes(bytes);
180 man.hash.addBytes(bytes.slice(conf));
182181 },
183182 .lazy_path => |lazy_path| {
184 const file_path = lazy_path.getPath2(graph, step);
185 _ = try man.addFile(file_path, null);
183 const file_path = try maker.resolveLazyPathIndex(arena, lazy_path, run_index);
184 _ = try man.addFilePath(file_path, null);
186185 },
187186 .none => {},
188187 }
189188
190 if (conf_run.captured_stdout) |captured| {
191 man.hash.addBytes(captured.output.basename);
192 man.hash.add(captured.trim_whitespace);
189 if (conf_run.captured_stdout.value) |captured| {
190 man.hash.addBytes(captured.basename.slice(conf));
191 man.hash.add(conf_run.flags.stdout_trim_whitespace);
193192 }
194193
195 if (conf_run.captured_stderr) |captured| {
196 man.hash.addBytes(captured.output.basename);
197 man.hash.add(captured.trim_whitespace);
194 if (conf_run.captured_stderr.value) |captured| {
195 man.hash.addBytes(captured.basename.slice(conf));
196 man.hash.add(conf_run.flags.stderr_trim_whitespace);
198197 }
199198
200 std.log.err("TODO hashStdIo", .{});
201 //hashStdIo(&man.hash, conf_run.stdio);
199 switch (conf_run.flags.stdio) {
200 .infer_from_args, .inherit, .zig_test => {},
201 .check => {
202 man.hash.addBytes(if (conf_run.expect_stderr_exact.value) |bytes| bytes.slice(conf) else "");
203 man.hash.addBytes(if (conf_run.expect_stdout_exact.value) |bytes| bytes.slice(conf) else "");
204 for (conf_run.expect_stderr_match.slice) |bytes| man.hash.addBytes(bytes.slice(conf));
205 for (conf_run.expect_stdout_match.slice) |bytes| man.hash.addBytes(bytes.slice(conf));
206 man.hash.add(conf_run.flags2.expect_term_status);
207 man.hash.addOptional(conf_run.expect_term_value.value);
208 },
209 }
202210
203 for (conf_run.file_inputs.items) |lazy_path| {
204 _ = try man.addFile(lazy_path.getPath2(graph, step), null);
211 for (conf_run.file_inputs.slice) |lazy_path| {
212 const file_path = try maker.resolveLazyPathIndex(arena, lazy_path, run_index);
213 _ = try man.addFilePath(file_path, null);
205214 }
206215
207 if (conf_run.cwd) |cwd| {
208 const cwd_path = cwd.getPath3(graph, step);
216 if (conf_run.cwd.value) |lazy_path| {
217 const cwd_path = try maker.resolveLazyPathIndex(arena, lazy_path, run_index);
209218 _ = man.hash.addBytes(try cwd_path.toString(arena));
210219 }
211220
212221 const has_side_effects = conf_run.flags.has_side_effects;
213222
214 if (!has_side_effects and try step.cacheHitAndWatch(&man)) {
223 if (true) @panic("TODO");
224
225 if (!has_side_effects and try step.cacheHitAndWatch(maker, &man)) {
215226 // cache hit, skip running command
216227 const digest = man.final();
217228
218229 try populateGeneratedPaths(
219230 arena,
220231 output_placeholders.items,
221 graph.cache_root,
232 &conf_run,
233 cache_root,
222234 &digest,
223235 );
224236
......@@ -236,7 +248,8 @@ pub fn make(
236248 try populateGeneratedPaths(
237249 arena,
238250 output_placeholders.items,
239 graph.cache_root,
251 &conf_run,
252 cache_root,
240253 &digest,
241254 );
242255
......@@ -248,9 +261,9 @@ pub fn make(
248261 .output_directory => output_sub_path,
249262 else => unreachable,
250263 };
251 graph.cache_root.handle.createDirPath(io, output_sub_dir_path) catch |err| {
264 cache_root.handle.createDirPath(io, output_sub_dir_path) catch |err| {
252265 return step.fail(maker, "unable to make path '{f}{s}': {t}", .{
253 graph.cache_root, output_sub_dir_path, err,
266 cache_root, output_sub_dir_path, err,
254267 });
255268 };
256269 const arg_output_path = try convertPathArg(run_index, maker, .{
......@@ -281,13 +294,13 @@ pub fn make(
281294 .output_directory => output_sub_path,
282295 else => unreachable,
283296 };
284 graph.cache_root.handle.createDirPath(io, output_sub_dir_path) catch |err| {
297 cache_root.handle.createDirPath(io, output_sub_dir_path) catch |err| {
285298 return step.fail(maker, "unable to make path '{f}{s}': {t}", .{
286 graph.cache_root, output_sub_dir_path, err,
299 cache_root, output_sub_dir_path, err,
287300 });
288301 };
289302 const raw_output_path: Path = .{
290 .root_dir = graph.cache_root,
303 .root_dir = cache_root,
291304 .sub_path = graph.pathJoin(&output_components),
292305 };
293306 placeholder.output.generated_file.path = raw_output_path.toString(arena) catch @panic("OOM");
......@@ -318,21 +331,21 @@ pub fn make(
318331 if (any_output) {
319332 const o_sub_path = "o" ++ Dir.path.sep_str ++ &digest;
320333
321 graph.cache_root.handle.rename(tmp_dir_path, graph.cache_root.handle, o_sub_path, io) catch |err| switch (err) {
334 cache_root.handle.rename(tmp_dir_path, cache_root.handle, o_sub_path, io) catch |err| switch (err) {
322335 Dir.RenameError.DirNotEmpty => {
323 graph.cache_root.handle.deleteTree(io, o_sub_path) catch |del_err| {
336 cache_root.handle.deleteTree(io, o_sub_path) catch |del_err| {
324337 return step.fail(maker, "unable to remove dir '{f}'{s}: {t}", .{
325 graph.cache_root, tmp_dir_path, del_err,
338 cache_root, tmp_dir_path, del_err,
326339 });
327340 };
328 graph.cache_root.handle.rename(tmp_dir_path, graph.cache_root.handle, o_sub_path, io) catch |retry_err| {
341 cache_root.handle.rename(tmp_dir_path, cache_root.handle, o_sub_path, io) catch |retry_err| {
329342 return step.fail(maker, "unable to rename dir '{f}{s}' to '{f}{s}': {t}", .{
330 graph.cache_root, tmp_dir_path, graph.cache_root, o_sub_path, retry_err,
343 cache_root, tmp_dir_path, cache_root, o_sub_path, retry_err,
331344 });
332345 };
333346 },
334347 else => return step.fail(maker, "unable to rename dir '{f}{s}' to '{f}{s}': {t}", .{
335 graph.cache_root, tmp_dir_path, graph.cache_root, o_sub_path, err,
348 cache_root, tmp_dir_path, cache_root, o_sub_path, err,
336349 }),
337350 };
338351 }
......@@ -342,7 +355,8 @@ pub fn make(
342355 try populateGeneratedPaths(
343356 arena,
344357 output_placeholders.items,
345 graph.cache_root,
358 &conf_run,
359 cache_root,
346360 &digest,
347361 );
348362}
......@@ -1548,8 +1562,7 @@ const CapturedStdIo = void; // TODO get it from Configuration
15481562fn populateGeneratedPaths(
15491563 arena: std.mem.Allocator,
15501564 output_placeholders: []const IndexedOutput,
1551 captured_stdout: ?*CapturedStdIo,
1552 captured_stderr: ?*CapturedStdIo,
1565 conf_run: *const Configuration.Step.Run,
15531566 cache_root: Cache.Directory,
15541567 digest: *const Cache.HexDigest,
15551568) !void {
......@@ -1559,13 +1572,13 @@ fn populateGeneratedPaths(
15591572 });
15601573 }
15611574
1562 if (captured_stdout) |captured| {
1575 if (conf_run.captured_stdout.value) |captured| {
15631576 captured.output.generated_file.path = try cache_root.join(arena, &.{
15641577 "o", digest, captured.output.basename,
15651578 });
15661579 }
15671580
1568 if (captured_stderr) |captured| {
1581 if (conf_run.captured_stderr.value) |captured| {
15691582 captured.output.generated_file.path = try cache_root.join(arena, &.{
15701583 "o", digest, captured.output.basename,
15711584 });
......@@ -1985,29 +1998,6 @@ fn spawnChildAndCollect(
19851998 }
19861999}
19872000
1988fn hashStdIo(hh: *Cache.HashHelper, stdio: void) void {
1989 switch (stdio) {
1990 .infer_from_args, .inherit, .zig_test => {},
1991 .check => |checks| for (checks.items) |check| {
1992 hh.add(@as(std.meta.Tag(@This().StdIo.Check), check));
1993 switch (check) {
1994 .expect_stderr_exact,
1995 .expect_stderr_match,
1996 .expect_stdout_exact,
1997 .expect_stdout_match,
1998 => |s| hh.addBytes(s),
1999
2000 .expect_term => |term| {
2001 hh.add(@as(std.meta.Tag(process.Child.Term), term));
2002 switch (term) {
2003 inline .exited, .signal, .stopped => |x| hh.add(x),
2004 .unknown => |x| hh.add(x),
2005 }
2006 },
2007 }
2008 },
2009 }
2010}
20112001fn termMatches(expected: ?process.Child.Term, actual: process.Child.Term) bool {
20122002 return if (expected) |e| switch (e) {
20132003 .exited => |expected_code| switch (actual) {
lib/std/Build/Configuration.zig+4
......@@ -1572,6 +1572,10 @@ pub const Bytes = extern struct {
15721572 /// Points into `string_bytes`.
15731573 index: u32,
15741574 len: u32,
1575
1576 pub fn slice(bytes: Bytes, c: *const Configuration) []const u8 {
1577 return c.string_bytes[bytes.index..][0..bytes.len];
1578 }
15751579};
15761580
15771581pub const DefaultingBool = enum(u2) {