Commit a909f97e authored by Samuel Ainsworth's avatar Samuel Ainsworth
Browse files

bazel_7: fix enableNixHacks build on darwin

The enableNixHacks patch unconditionally treated any existing repository
directory as valid, bypassing marker file validation. When bazel's module
extension framework created empty directories for extension-generated
repos (like local_config_xcode), the hack returned these before the
repository rule could populate them with BUILD files.

Fix by checking for BUILD/BUILD.bazel file existence before considering
a cached repo valid. Empty repos now fall through to execute the
repository rule, which generates proper stubs.

Fixes: https://github.com/NixOS/nixpkgs/issues/390395
parent c5af9c2d
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ index 53e6494656..22261cd268 100644
 import java.util.Map;
 import java.util.Optional;
 import java.util.TreeMap;
@@ -193,16 +194,11 @@ public final class RepositoryDelegatorFunction implements SkyFunction {
@@ -193,16 +194,15 @@ public final class RepositoryDelegatorFunction implements SkyFunction {
       }

       if (shouldUseCachedRepos(env, handler, repoRoot, rule)) {
@@ -20,8 +20,12 @@ index 53e6494656..22261cd268 100644
-          return null;
-        }
-        if (markerHash != null) { // repo exist & up-to-date
+        {
+          // Nix hack: Always consider cached dirs as up-to-date
+        // Nix hack: Skip marker file validation but only for repos that have
+        // been fully initialized. Check for common root files that indicate a
+        // real repo, not an empty dir created by module extensions before the
+        // repository rule has had a chance to run.
+        if (repoRoot.getChild("BUILD").exists() || repoRoot.getChild("BUILD.bazel").exists()
+            || repoRoot.getChild("WORKSPACE").exists() || repoRoot.getChild("WORKSPACE.bazel").exists()) {
           return RepositoryDirectoryValue.builder()
               .setPath(repoRoot)
-              .setDigest(markerHash)
@@ -30,8 +34,6 @@ index 53e6494656..22261cd268 100644
               .build();
         }
       }


diff --git a/src/main/java/com/google/devtools/build/lib/shell/JavaSubprocessFactory.java b/src/main/java/com/google/devtools/build/lib/shell/JavaSubprocessFactory.java
index 649647c5f2..64d05b530c 100644
--- a/src/main/java/com/google/devtools/build/lib/shell/JavaSubprocessFactory.java