aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordweiller <4678790+dweiller@users.noreply.github.com>2024-07-30 18:41:22 +1000
committerAlex Rønne Petersen <alex@alexrp.com>2025-03-26 14:48:04 +0100
commitb84db311d90d722c206a7eea5464f46fd1b9e827 (patch)
treea12db400890f30971815fa400f17ac04854c8936 /lib
parent5b4759bd3c860b0648bf847ba9aa52584a9547d9 (diff)
downloadzig-b84db311d90d722c206a7eea5464f46fd1b9e827.tar.gz
zig-b84db311d90d722c206a7eea5464f46fd1b9e827.zip
zig build: add env_map entries to hash for Step.Run
This change fixes false-positive cache hits for run steps that get run with different sets of environment variables due the the environment map being excluded from the cache hash.
Diffstat (limited to 'lib')
-rw-r--r--lib/std/Build/Step/Run.zig29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig
index a9d4808bc0..3d0b0a7068 100644
--- a/lib/std/Build/Step/Run.zig
+++ b/lib/std/Build/Step/Run.zig
@@ -620,6 +620,35 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
var man = b.graph.cache.obtain();
defer man.deinit();
+ if (run.env_map) |env_map| {
+ const KV = struct { []const u8, []const u8 };
+ var kv_pairs = try std.ArrayList(KV).initCapacity(arena, env_map.count());
+ var iter = env_map.iterator();
+ while (iter.next()) |entry| {
+ kv_pairs.appendAssumeCapacity(.{ entry.key_ptr.*, entry.value_ptr.* });
+ }
+
+ std.mem.sortUnstable(KV, kv_pairs.items, {}, struct {
+ fn lessThan(_: void, kv1: KV, kv2: KV) bool {
+ const k1 = kv1[0];
+ const k2 = kv2[0];
+
+ if (k1.len != k2.len) return k1.len < k2.len;
+
+ for (k1, k2) |c1, c2| {
+ if (c1 == c2) continue;
+ return c1 < c2;
+ }
+ unreachable; // two keys cannot be equal
+ }
+ }.lessThan);
+
+ for (kv_pairs.items) |kv| {
+ man.hash.addBytes(kv[0]);
+ man.hash.addBytes(kv[1]);
+ }
+ }
+
for (run.argv.items) |arg| {
switch (arg) {
.bytes => |bytes| {