authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-29 18:18:22-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:35-07:00
logfa235757671490746d31a61a9b836ddc6320d3dc
tree1452b78ee0e2dbbfc2e06b003e71cee722071a8f
parent5f626d28c14bfded775ae779dcde5b2435d4ac13

maker: fix the has side effects logic in run step


2 files changed, 17 insertions(+), 6 deletions(-)

lib/compiler/Maker.zig+3-1
......@@ -1669,8 +1669,10 @@ fn fatalWithHint(comptime f: []const u8, args: anytype) noreturn {
16691669}
16701670
16711671fn cleanTmpFiles(io: Io, steps: []const Configuration.Step.Index) void {
1672 std.log.err("TODO implement cleanTmpFiles", .{});
1673 if (true) return;
1674
16721675 for (steps) |step_index| {
1673 if (true) @panic("TODO");
16741676 const wf = step_index.cast(std.Build.Step.WriteFile) orelse continue;
16751677 if (wf.mode != .tmp) continue;
16761678 const path = wf.generated_directory.path orelse continue;
lib/compiler/Maker/Step/Run.zig+14-5
......@@ -70,7 +70,8 @@ pub fn make(
7070 man.hash.add(conf_run.flags.color);
7171 man.hash.add(conf_run.flags.disable_zig_progress);
7272
73 var dep_file_count: usize = 0;
73 var any_dep_files = false;
74 var any_output_args = false;
7475
7576 for (conf_run.args.slice) |arg_index| {
7677 const arg = arg_index.get(conf);
......@@ -161,9 +162,10 @@ pub fn make(
161162 man.hash.addBytesZ(prefix);
162163 man.hash.addBytesZ(basename);
163164 man.hash.addBytesZ(suffix);
164
165165 man.hash.add(arg.flags.dep_file);
166 dep_file_count += @intFromBool(arg.flags.dep_file);
166
167 any_dep_files = any_dep_files or arg.flags.dep_file;
168 any_output_args = true;
167169
168170 // Add a placeholder into the argument list because we need the
169171 // manifest hash to be updated with all arguments before the
......@@ -233,7 +235,14 @@ pub fn make(
233235 _ = man.hash.addBytes(try cwd_path.toString(arena));
234236 }
235237
236 const has_side_effects = conf_run.flags.has_side_effects;
238 // Whether the Run step has side effects *other than* updating the output arguments.
239 const has_side_effects = conf_run.flags.has_side_effects or switch (conf_run.flags.stdio) {
240 .infer_from_args => !any_output_args and
241 conf_run.captured_stdout.value == null and
242 conf_run.captured_stderr.value == null,
243 .inherit => true,
244 .check, .zig_test => false,
245 };
237246
238247 if (!has_side_effects and try step.cacheHitAndWatch(maker, &man)) {
239248 // Cache hit; skip running command.
......@@ -244,7 +253,7 @@ pub fn make(
244253 return;
245254 }
246255
247 if (dep_file_count == 0) {
256 if (!any_dep_files) {
248257 // We already know the final output paths; use them directly.
249258 const digest = if (has_side_effects) man.hash.final() else man.final();
250259 const output_dir_path = "o" ++ Dir.path.sep_str ++ &digest;