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(...@@ -48,6 +48,7 @@ pub fn make(
48 const conf_run = conf_step.extended.get(conf.extra).run;48 const conf_run = conf_step.extended.get(conf.extra).run;
49 const argv_list = &run.argv;49 const argv_list = &run.argv;
50 const output_placeholders = &run.output_placeholders;50 const output_placeholders = &run.output_placeholders;
51 const cache_root = graph.local_cache_root;
5152
52 argv_list.clearRetainingCapacity();53 argv_list.clearRetainingCapacity();
53 output_placeholders.clearRetainingCapacity();54 output_placeholders.clearRetainingCapacity();
...@@ -174,51 +175,62 @@ pub fn make(...@@ -174,51 +175,62 @@ pub fn make(
174 }175 }
175 }176 }
176177
177 if (true) @panic("TODO");
178
179 switch (conf_run.stdin.u) {178 switch (conf_run.stdin.u) {
180 .bytes => |bytes| {179 .bytes => |bytes| {
181 man.hash.addBytes(bytes);180 man.hash.addBytes(bytes.slice(conf));
182 },181 },
183 .lazy_path => |lazy_path| {182 .lazy_path => |lazy_path| {
184 const file_path = lazy_path.getPath2(graph, step);183 const file_path = try maker.resolveLazyPathIndex(arena, lazy_path, run_index);
185 _ = try man.addFile(file_path, null);184 _ = try man.addFilePath(file_path, null);
186 },185 },
187 .none => {},186 .none => {},
188 }187 }
189188
190 if (conf_run.captured_stdout) |captured| {189 if (conf_run.captured_stdout.value) |captured| {
191 man.hash.addBytes(captured.output.basename);190 man.hash.addBytes(captured.basename.slice(conf));
192 man.hash.add(captured.trim_whitespace);191 man.hash.add(conf_run.flags.stdout_trim_whitespace);
193 }192 }
194193
195 if (conf_run.captured_stderr) |captured| {194 if (conf_run.captured_stderr.value) |captured| {
196 man.hash.addBytes(captured.output.basename);195 man.hash.addBytes(captured.basename.slice(conf));
197 man.hash.add(captured.trim_whitespace);196 man.hash.add(conf_run.flags.stderr_trim_whitespace);
198 }197 }
199198
200 std.log.err("TODO hashStdIo", .{});199 switch (conf_run.flags.stdio) {
201 //hashStdIo(&man.hash, conf_run.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| {211 for (conf_run.file_inputs.slice) |lazy_path| {
204 _ = try man.addFile(lazy_path.getPath2(graph, step), null);212 const file_path = try maker.resolveLazyPathIndex(arena, lazy_path, run_index);
213 _ = try man.addFilePath(file_path, null);
205 }214 }
206215
207 if (conf_run.cwd) |cwd| {216 if (conf_run.cwd.value) |lazy_path| {
208 const cwd_path = cwd.getPath3(graph, step);217 const cwd_path = try maker.resolveLazyPathIndex(arena, lazy_path, run_index);
209 _ = man.hash.addBytes(try cwd_path.toString(arena));218 _ = man.hash.addBytes(try cwd_path.toString(arena));
210 }219 }
211220
212 const has_side_effects = conf_run.flags.has_side_effects;221 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)) {
215 // cache hit, skip running command226 // cache hit, skip running command
216 const digest = man.final();227 const digest = man.final();
217228
218 try populateGeneratedPaths(229 try populateGeneratedPaths(
219 arena,230 arena,
220 output_placeholders.items,231 output_placeholders.items,
221 graph.cache_root,232 &conf_run,
233 cache_root,
222 &digest,234 &digest,
223 );235 );
224236
...@@ -236,7 +248,8 @@ pub fn make(...@@ -236,7 +248,8 @@ pub fn make(
236 try populateGeneratedPaths(248 try populateGeneratedPaths(
237 arena,249 arena,
238 output_placeholders.items,250 output_placeholders.items,
239 graph.cache_root,251 &conf_run,
252 cache_root,
240 &digest,253 &digest,
241 );254 );
242255
...@@ -248,9 +261,9 @@ pub fn make(...@@ -248,9 +261,9 @@ pub fn make(
248 .output_directory => output_sub_path,261 .output_directory => output_sub_path,
249 else => unreachable,262 else => unreachable,
250 };263 };
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| {
252 return step.fail(maker, "unable to make path '{f}{s}': {t}", .{265 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,
254 });267 });
255 };268 };
256 const arg_output_path = try convertPathArg(run_index, maker, .{269 const arg_output_path = try convertPathArg(run_index, maker, .{
...@@ -281,13 +294,13 @@ pub fn make(...@@ -281,13 +294,13 @@ pub fn make(
281 .output_directory => output_sub_path,294 .output_directory => output_sub_path,
282 else => unreachable,295 else => unreachable,
283 };296 };
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| {
285 return step.fail(maker, "unable to make path '{f}{s}': {t}", .{298 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,
287 });300 });
288 };301 };
289 const raw_output_path: Path = .{302 const raw_output_path: Path = .{
290 .root_dir = graph.cache_root,303 .root_dir = cache_root,
291 .sub_path = graph.pathJoin(&output_components),304 .sub_path = graph.pathJoin(&output_components),
292 };305 };
293 placeholder.output.generated_file.path = raw_output_path.toString(arena) catch @panic("OOM");306 placeholder.output.generated_file.path = raw_output_path.toString(arena) catch @panic("OOM");
...@@ -318,21 +331,21 @@ pub fn make(...@@ -318,21 +331,21 @@ pub fn make(
318 if (any_output) {331 if (any_output) {
319 const o_sub_path = "o" ++ Dir.path.sep_str ++ &digest;332 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) {
322 Dir.RenameError.DirNotEmpty => {335 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| {
324 return step.fail(maker, "unable to remove dir '{f}'{s}: {t}", .{337 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,
326 });339 });
327 };340 };
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| {
329 return step.fail(maker, "unable to rename dir '{f}{s}' to '{f}{s}': {t}", .{342 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,
331 });344 });
332 };345 };
333 },346 },
334 else => return step.fail(maker, "unable to rename dir '{f}{s}' to '{f}{s}': {t}", .{347 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,
336 }),349 }),
337 };350 };
338 }351 }
...@@ -342,7 +355,8 @@ pub fn make(...@@ -342,7 +355,8 @@ pub fn make(
342 try populateGeneratedPaths(355 try populateGeneratedPaths(
343 arena,356 arena,
344 output_placeholders.items,357 output_placeholders.items,
345 graph.cache_root,358 &conf_run,
359 cache_root,
346 &digest,360 &digest,
347 );361 );
348}362}
...@@ -1548,8 +1562,7 @@ const CapturedStdIo = void; // TODO get it from Configuration...@@ -1548,8 +1562,7 @@ const CapturedStdIo = void; // TODO get it from Configuration
1548fn populateGeneratedPaths(1562fn populateGeneratedPaths(
1549 arena: std.mem.Allocator,1563 arena: std.mem.Allocator,
1550 output_placeholders: []const IndexedOutput,1564 output_placeholders: []const IndexedOutput,
1551 captured_stdout: ?*CapturedStdIo,1565 conf_run: *const Configuration.Step.Run,
1552 captured_stderr: ?*CapturedStdIo,
1553 cache_root: Cache.Directory,1566 cache_root: Cache.Directory,
1554 digest: *const Cache.HexDigest,1567 digest: *const Cache.HexDigest,
1555) !void {1568) !void {
...@@ -1559,13 +1572,13 @@ fn populateGeneratedPaths(...@@ -1559,13 +1572,13 @@ fn populateGeneratedPaths(
1559 });1572 });
1560 }1573 }
15611574
1562 if (captured_stdout) |captured| {1575 if (conf_run.captured_stdout.value) |captured| {
1563 captured.output.generated_file.path = try cache_root.join(arena, &.{1576 captured.output.generated_file.path = try cache_root.join(arena, &.{
1564 "o", digest, captured.output.basename,1577 "o", digest, captured.output.basename,
1565 });1578 });
1566 }1579 }
15671580
1568 if (captured_stderr) |captured| {1581 if (conf_run.captured_stderr.value) |captured| {
1569 captured.output.generated_file.path = try cache_root.join(arena, &.{1582 captured.output.generated_file.path = try cache_root.join(arena, &.{
1570 "o", digest, captured.output.basename,1583 "o", digest, captured.output.basename,
1571 });1584 });
...@@ -1985,29 +1998,6 @@ fn spawnChildAndCollect(...@@ -1985,29 +1998,6 @@ fn spawnChildAndCollect(
1985 }1998 }
1986}1999}
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}
2011fn termMatches(expected: ?process.Child.Term, actual: process.Child.Term) bool {2001fn termMatches(expected: ?process.Child.Term, actual: process.Child.Term) bool {
2012 return if (expected) |e| switch (e) {2002 return if (expected) |e| switch (e) {
2013 .exited => |expected_code| switch (actual) {2003 .exited => |expected_code| switch (actual) {
lib/std/Build/Configuration.zig+4
...@@ -1572,6 +1572,10 @@ pub const Bytes = extern struct {...@@ -1572,6 +1572,10 @@ pub const Bytes = extern struct {
1572 /// Points into `string_bytes`.1572 /// Points into `string_bytes`.
1573 index: u32,1573 index: u32,
1574 len: u32,1574 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 }
1575};1579};
15761580
1577pub const DefaultingBool = enum(u2) {1581pub const DefaultingBool = enum(u2) {