Skip to content

Commit

Permalink
Do not eval WORKSPACE in LocalRepositoryLookupFunction when `--noenab…
Browse files Browse the repository at this point in the history
…le_workspace`

This still leaves the question of "what do we do instead?". See issues bazelbuild#22208 and bazelbuild#21515.

Fixes bazelbuild#22754.

Closes bazelbuild#22774.

PiperOrigin-RevId: 645148811
Change-Id: Ib9d07d2ecbc3a79e3341de6739de1c3349124d6b
  • Loading branch information
Wyverald authored and bazel-io committed Jun 20, 2024
1 parent 3278ffd commit 3f3261d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.packages.WorkspaceFileValue;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.repository.ExternalPackageHelper;
import com.google.devtools.build.lib.rules.repository.LocalRepositoryRule;
import com.google.devtools.build.lib.rules.repository.WorkspaceFileHelper;
Expand All @@ -42,6 +43,7 @@
import com.google.devtools.build.skyframe.SkyValue;
import java.io.IOException;
import javax.annotation.Nullable;
import net.starlark.java.eval.StarlarkSemantics;

/** SkyFunction for {@link LocalRepositoryLookupValue}s. */
public class LocalRepositoryLookupFunction implements SkyFunction {
Expand All @@ -58,6 +60,14 @@ public LocalRepositoryLookupFunction(ExternalPackageHelper externalPackageHelper
@Override
public SkyValue compute(SkyKey skyKey, Environment env)
throws SkyFunctionException, InterruptedException {
StarlarkSemantics semantics = PrecomputedValue.STARLARK_SEMANTICS.get(env);
if (semantics == null) {
return null;
}
if (!semantics.getBool(BuildLanguageOptions.ENABLE_WORKSPACE)) {
// TODO: #22208, #21515 - Figure out what to do here.
return LocalRepositoryLookupValue.mainRepository();
}
RootedPath directory = (RootedPath) skyKey.argument();

// Is this the root directory? If so, we're in the MAIN repository. This assumes that the main
Expand Down
6 changes: 6 additions & 0 deletions src/test/py/bazel/bzlmod/bazel_module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,12 @@ def testPendingDownloadDetected(self):
stderr,
)

def testRegression22754(self):
"""Regression test for issue #22754."""
self.ScratchFile('BUILD.bazel', ['print(glob(["testdata/**"]))'])
self.ScratchFile('testdata/WORKSPACE')
self.RunBazel(['build', ':all'])


if __name__ == '__main__':
absltest.main()

0 comments on commit 3f3261d

Please sign in to comment.