bzlmod: Revert platform/toolchain support from the module() directive
(https://github.com/bazelbuild/bazel/issues/13316)
We'll go with a different approach where platforms/toolchains can be registered with a built-in module extension instead.
PiperOrigin-RevId: 395905591
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD
index 9d3c56c..fe9853f 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BUILD
@@ -95,7 +95,6 @@
],
deps = [
":common",
- ":exception",
":module_extension",
":registry",
"//src/main/java/com/google/devtools/build/lib/cmdline",
@@ -103,7 +102,6 @@
"//src/main/java/com/google/devtools/build/lib/skyframe:sky_functions",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
- "//src/main/protobuf:failure_details_java_proto",
"//third_party:auto_value",
"//third_party:guava",
"//third_party:jsr305",
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/Module.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/Module.java
index 8815103..d05f348 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/Module.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/Module.java
@@ -21,7 +21,6 @@
import com.google.common.collect.Maps;
import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.cmdline.RepositoryName;
-import com.google.devtools.build.lib.server.FailureDetails.ExternalDeps.Code;
import java.util.Map;
import java.util.function.UnaryOperator;
import javax.annotation.Nullable;
@@ -71,70 +70,6 @@
public abstract int getCompatibilityLevel();
/**
- * Target patterns identifying execution platforms to register when this module is selected. Note
- * that these are what was written in module files verbatim, and don't contain canonical repo
- * names.
- */
- public abstract ImmutableList<String> getExecutionPlatformsToRegister();
-
- /**
- * Target patterns identifying toolchains to register when this module is selected. Note that
- * these are what was written in module files verbatim, and don't contain canonical repo names.
- */
- public abstract ImmutableList<String> getToolchainsToRegister();
-
- /**
- * Target patterns (with canonical repo names) identifying execution platforms to register when
- * this module is selected.
- */
- public final ImmutableList<String> getCanonicalizedExecutionPlatformsToRegister()
- throws ExternalDepsException {
- return canonicalizeTargetPatterns(getExecutionPlatformsToRegister());
- }
-
- /**
- * Target patterns (with canonical repo names) identifying toolchains to register when this module
- * is selected.
- */
- public final ImmutableList<String> getCanonicalizedToolchainsToRegister()
- throws ExternalDepsException {
- return canonicalizeTargetPatterns(getToolchainsToRegister());
- }
-
- /**
- * Rewrites the given target patterns to have canonical repo names, assuming that they're
- * originally written in the context of the module identified by {@code key} and {@code module}.
- */
- private ImmutableList<String> canonicalizeTargetPatterns(ImmutableList<String> targetPatterns)
- throws ExternalDepsException {
- ImmutableList.Builder<String> renamedPatterns = ImmutableList.builder();
- for (String pattern : targetPatterns) {
- if (!pattern.startsWith("@")) {
- renamedPatterns.add("@" + getKey().getCanonicalRepoName() + pattern);
- continue;
- }
- int doubleSlashIndex = pattern.indexOf("//");
- if (doubleSlashIndex == -1) {
- throw ExternalDepsException.withMessage(
- Code.BAD_MODULE, "%s refers to malformed target pattern: %s", getKey(), pattern);
- }
- String repoName = pattern.substring(1, doubleSlashIndex);
- ModuleKey depKey = getDeps().get(repoName);
- if (depKey == null) {
- throw ExternalDepsException.withMessage(
- Code.BAD_MODULE,
- "%s refers to target pattern %s with unknown repo %s",
- getKey(),
- pattern,
- repoName);
- }
- renamedPatterns.add(
- "@" + depKey.getCanonicalRepoName() + pattern.substring(doubleSlashIndex));
- }
- return renamedPatterns.build();
- }
-
- /**
* The direct dependencies of this module. The key type is the repo name of the dep, and the value
* type is the ModuleKey (name+version) of the dep.
*/
@@ -204,9 +139,7 @@
.setName("")
.setVersion(Version.EMPTY)
.setKey(ModuleKey.ROOT)
- .setCompatibilityLevel(0)
- .setExecutionPlatformsToRegister(ImmutableList.of())
- .setToolchainsToRegister(ImmutableList.of());
+ .setCompatibilityLevel(0);
}
/**
@@ -234,12 +167,6 @@
/** Optional; defaults to {@code 0}. */
public abstract Builder setCompatibilityLevel(int value);
- /** Optional; defaults to an empty list. */
- public abstract Builder setExecutionPlatformsToRegister(ImmutableList<String> value);
-
- /** Optional; defaults to an empty list. */
- public abstract Builder setToolchainsToRegister(ImmutableList<String> value);
-
public abstract Builder setDeps(ImmutableMap<String, ModuleKey> value);
abstract ImmutableMap.Builder<String, ModuleKey> depsBuilder();
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileGlobals.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileGlobals.java
index 266e9db..cdbb64a 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileGlobals.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileGlobals.java
@@ -120,38 +120,12 @@
named = true,
positional = false,
defaultValue = "0"),
- @Param(
- name = "execution_platforms_to_register",
- doc =
- "A list of already-defined execution platforms to be registered when this module is"
- + " selected. Should be a list of absolute target patterns (ie. beginning with"
- + " either <code>@</code> or <code>//</code>). See <a"
- + " href=\"../../toolchains.html\">toolchain resolution</a> for more"
- + " information.",
- named = true,
- positional = false,
- allowedTypes = {@ParamType(type = Iterable.class, generic1 = String.class)},
- defaultValue = "[]"),
- @Param(
- name = "toolchains_to_register",
- doc =
- "A list of already-defined toolchains to be registered when this module is"
- + " selected. Should be a list of absolute target patterns (ie. beginning with"
- + " either <code>@</code> or <code>//</code>). See <a"
- + " href=\"../../toolchains.html\">toolchain resolution</a> for more"
- + " information.",
- named = true,
- positional = false,
- allowedTypes = {@ParamType(type = Iterable.class, generic1 = String.class)},
- defaultValue = "[]"),
},
useStarlarkThread = true)
public void module(
String name,
String version,
StarlarkInt compatibilityLevel,
- Iterable<?> executionPlatformsToRegister,
- Iterable<?> toolchainsToRegister,
StarlarkThread thread)
throws EvalException {
if (moduleCalled) {
@@ -168,12 +142,7 @@
module
.setName(name)
.setVersion(parsedVersion)
- .setCompatibilityLevel(compatibilityLevel.toInt("compatibility_level"))
- .setExecutionPlatformsToRegister(
- checkAllAbsolutePatterns(
- executionPlatformsToRegister, "execution_platforms_to_register"))
- .setToolchainsToRegister(
- checkAllAbsolutePatterns(toolchainsToRegister, "toolchains_to_register"));
+ .setCompatibilityLevel(compatibilityLevel.toInt("compatibility_level"));
addRepoNameUsage(name, "as the current module name", thread.getCallerLocation());
}
@@ -380,20 +349,6 @@
return result.build();
}
- private static ImmutableList<String> checkAllAbsolutePatterns(Iterable<?> iterable, String where)
- throws EvalException {
- ImmutableList<String> list = checkAllStrings(iterable, where);
- for (String item : list) {
- if (!item.startsWith("//") && !item.startsWith("@")) {
- throw Starlark.errorf(
- "Expected absolute target patterns (must begin with '//' or '@') for '%s' argument, but"
- + " got '%s' in the sequence",
- where, item);
- }
- }
- return list;
- }
-
@StarlarkMethod(
name = "single_version_override",
doc =
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
index 7281ce8..fb5cca9 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
@@ -25,16 +25,13 @@
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
import com.google.devtools.build.lib.analysis.platform.PlatformProviderUtils;
-import com.google.devtools.build.lib.bazel.bzlmod.BazelModuleResolutionValue;
import com.google.devtools.build.lib.bazel.bzlmod.ExternalDepsException;
-import com.google.devtools.build.lib.bazel.bzlmod.Module;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelConstants;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.packages.Package;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.pkgcache.FilteringPolicy;
-import com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction;
import com.google.devtools.build.lib.server.FailureDetails.Analysis;
import com.google.devtools.build.lib.server.FailureDetails.Analysis.Code;
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
@@ -77,13 +74,6 @@
targetPatternBuilder.addAll(platformConfiguration.getExtraExecutionPlatforms());
}
- // Get registered execution platforms from bzlmod.
- List<String> bzlmodExecutionPlatforms = getBzlmodExecutionPlatforms(env);
- if (bzlmodExecutionPlatforms == null) {
- return null;
- }
- targetPatternBuilder.addAll(bzlmodExecutionPlatforms);
-
// Get the registered execution platforms from the WORKSPACE.
List<String> workspaceExecutionPlatforms = getWorkspaceExecutionPlatforms(env);
if (workspaceExecutionPlatforms == null) {
@@ -135,28 +125,6 @@
return externalPackage.getRegisteredExecutionPlatforms();
}
- @Nullable
- private static ImmutableList<String> getBzlmodExecutionPlatforms(Environment env)
- throws InterruptedException, RegisteredExecutionPlatformsFunctionException {
- if (!RepositoryDelegatorFunction.ENABLE_BZLMOD.get(env)) {
- return ImmutableList.of();
- }
- BazelModuleResolutionValue bazelModuleResolutionValue =
- (BazelModuleResolutionValue) env.getValue(BazelModuleResolutionValue.KEY);
- if (bazelModuleResolutionValue == null) {
- return null;
- }
- ImmutableList.Builder<String> executionPlatforms = ImmutableList.builder();
- try {
- for (Module module : bazelModuleResolutionValue.getDepGraph().values()) {
- executionPlatforms.addAll(module.getCanonicalizedExecutionPlatformsToRegister());
- }
- } catch (ExternalDepsException e) {
- throw new RegisteredExecutionPlatformsFunctionException(e, Transience.PERSISTENT);
- }
- return executionPlatforms.build();
- }
-
private static ImmutableList<ConfiguredTargetKey> configureRegisteredExecutionPlatforms(
Environment env, BuildConfiguration configuration, List<Label> labels)
throws InterruptedException, RegisteredExecutionPlatformsFunctionException {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java
index bb53bc9..0b7400c 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java
@@ -24,15 +24,12 @@
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.platform.DeclaredToolchainInfo;
import com.google.devtools.build.lib.analysis.platform.PlatformProviderUtils;
-import com.google.devtools.build.lib.bazel.bzlmod.BazelModuleResolutionValue;
import com.google.devtools.build.lib.bazel.bzlmod.ExternalDepsException;
-import com.google.devtools.build.lib.bazel.bzlmod.Module;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelConstants;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.packages.Package;
import com.google.devtools.build.lib.pkgcache.FilteringPolicies;
-import com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction;
import com.google.devtools.build.lib.server.FailureDetails.Toolchain.Code;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunctionException;
@@ -69,13 +66,6 @@
configuration.getFragment(PlatformConfiguration.class);
targetPatternBuilder.addAll(platformConfiguration.getExtraToolchains());
- // Get registered toolchains from bzlmod.
- ImmutableList<String> bzlmodToolchains = getBzlmodToolchains(env);
- if (bzlmodToolchains == null) {
- return null;
- }
- targetPatternBuilder.addAll(bzlmodToolchains);
-
// Get the registered toolchains from the WORKSPACE.
ImmutableList<String> workspaceToolchains = getWorkspaceToolchains(env);
if (workspaceToolchains == null) {
@@ -128,28 +118,6 @@
return externalPackage.getRegisteredToolchains();
}
- @Nullable
- private static ImmutableList<String> getBzlmodToolchains(Environment env)
- throws InterruptedException, RegisteredToolchainsFunctionException {
- if (!RepositoryDelegatorFunction.ENABLE_BZLMOD.get(env)) {
- return ImmutableList.of();
- }
- BazelModuleResolutionValue bazelModuleResolutionValue =
- (BazelModuleResolutionValue) env.getValue(BazelModuleResolutionValue.KEY);
- if (bazelModuleResolutionValue == null) {
- return null;
- }
- ImmutableList.Builder<String> toolchains = ImmutableList.builder();
- try {
- for (Module module : bazelModuleResolutionValue.getDepGraph().values()) {
- toolchains.addAll(module.getCanonicalizedToolchainsToRegister());
- }
- } catch (ExternalDepsException e) {
- throw new RegisteredToolchainsFunctionException(e, Transience.PERSISTENT);
- }
- return toolchains.build();
- }
-
private static ImmutableList<DeclaredToolchainInfo> configureRegisteredToolchains(
Environment env, BuildConfiguration configuration, List<Label> labels)
throws InterruptedException, RegisteredToolchainsFunctionException {
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java
index e66e9db..06a6b46 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java
@@ -173,13 +173,7 @@
public void testRootModule() throws Exception {
scratch.file(
rootDirectory.getRelative("MODULE.bazel").getPathString(),
- "module(",
- " name='A',",
- " version='0.1',",
- " compatibility_level=4,",
- " toolchains_to_register=['//my:toolchain', '//my:toolchain2'],",
- " execution_platforms_to_register=['//my:platform', '//my:platform2'],",
- ")",
+ "module(name='A',version='0.1',compatibility_level=4)",
"bazel_dep(name='B',version='1.0')",
"bazel_dep(name='C',version='2.0',repo_name='see')",
"single_version_override(module_name='D',version='18')",
@@ -202,9 +196,6 @@
.setVersion(Version.parse("0.1"))
.setKey(ModuleKey.ROOT)
.setCompatibilityLevel(4)
- .setExecutionPlatformsToRegister(
- ImmutableList.of("//my:platform", "//my:platform2"))
- .setToolchainsToRegister(ImmutableList.of("//my:toolchain", "//my:toolchain2"))
.addDep("B", createModuleKey("B", "1.0"))
.addDep("see", createModuleKey("C", "2.0"))
.build());
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleTest.java
index 9f68ba9..3ef4e6b 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleTest.java
@@ -17,10 +17,8 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.bazel.bzlmod.BzlmodTestUtil.createModuleKey;
import static com.google.devtools.build.lib.bazel.bzlmod.BzlmodTestUtil.createRepositoryMapping;
-import static org.junit.Assert.assertThrows;
import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.bazel.bzlmod.Module.WhichRepoMappings;
import net.starlark.java.syntax.Location;
import org.junit.Test;
@@ -32,38 +30,6 @@
public class ModuleTest {
@Test
- public void canonicalizedTargetPatterns_good() throws Exception {
- Module module =
- Module.builder()
- .setKey(createModuleKey("self", "1.0"))
- .setExecutionPlatformsToRegister(ImmutableList.of("//:self_target"))
- .setToolchainsToRegister(ImmutableList.of("@root//:root_target", "@hi//:hi_target"))
- .addDep("hi", createModuleKey("hello", "2.0"))
- .addDep("root", ModuleKey.ROOT)
- .build();
- assertThat(module.getCanonicalizedExecutionPlatformsToRegister())
- .containsExactly("@self.1.0//:self_target")
- .inOrder();
- assertThat(module.getCanonicalizedToolchainsToRegister())
- .containsExactly("@//:root_target", "@hello.2.0//:hi_target")
- .inOrder();
- }
-
- @Test
- public void canonicalizedTargetPatterns_bad() throws Exception {
- Module module =
- Module.builder()
- .setKey(createModuleKey("self", "1.0"))
- .setExecutionPlatformsToRegister(ImmutableList.of("@what//:target"))
- .setToolchainsToRegister(ImmutableList.of("@hi:target"))
- .addDep("hi", createModuleKey("hello", "2.0"))
- .addDep("root", ModuleKey.ROOT)
- .build();
- assertThrows(ExternalDepsException.class, module::getCanonicalizedExecutionPlatformsToRegister);
- assertThrows(ExternalDepsException.class, module::getCanonicalizedToolchainsToRegister);
- }
-
- @Test
public void withDepKeysTransformed() throws Exception {
assertThat(
Module.builder()
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunctionTest.java
index aeb272b..e83d783 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunctionTest.java
@@ -15,7 +15,6 @@
package com.google.devtools.build.lib.skyframe;
import static com.google.common.truth.Truth.assertThat;
-import static com.google.devtools.build.lib.bazel.bzlmod.BzlmodTestUtil.createModuleKey;
import static com.google.devtools.build.skyframe.EvaluationResultSubjectFactory.assertThatEvaluationResult;
import static org.junit.Assert.assertThrows;
@@ -24,22 +23,16 @@
import com.google.common.truth.IterableSubject;
import com.google.devtools.build.lib.analysis.ViewCreationFailedException;
import com.google.devtools.build.lib.analysis.platform.ConstraintCollection;
-import com.google.devtools.build.lib.bazel.bzlmod.FakeRegistry;
-import com.google.devtools.build.lib.bazel.bzlmod.ModuleFileFunction;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.rules.platform.ToolchainTestCase;
import com.google.devtools.build.lib.skyframe.PlatformLookupUtil.InvalidPlatformException;
-import com.google.devtools.build.lib.skyframe.PrecomputedValue.Injected;
import com.google.devtools.build.lib.skyframe.util.SkyframeExecutorTestUtils;
-import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.skyframe.EvaluationResult;
import com.google.devtools.build.skyframe.SkyKey;
-import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -51,9 +44,6 @@
@RunWith(JUnit4.class)
public class RegisteredExecutionPlatformsFunctionTest extends ToolchainTestCase {
- private Path moduleRoot;
- private FakeRegistry registry;
-
protected EvaluationResult<RegisteredExecutionPlatformsValue>
requestExecutionPlatformsFromSkyframe(SkyKey executionPlatformsKey)
throws InterruptedException {
@@ -89,29 +79,6 @@
.collect(Collectors.toList());
}
- @Override
- protected boolean enableBzlmod() {
- return true;
- }
-
- @Override
- protected ImmutableList<Injected> extraPrecomputedValues() {
- try {
- moduleRoot = scratch.dir("modules");
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- registry = FakeRegistry.DEFAULT_FACTORY.newFakeRegistry(moduleRoot.getPathString());
- return ImmutableList.of(
- PrecomputedValue.injected(
- ModuleFileFunction.REGISTRIES, ImmutableList.of(registry.getUrl())));
- }
-
- @Before
- public void setUpForBzlmod() throws Exception {
- scratch.file("MODULE.bazel");
- }
-
@Test
public void testRegisteredExecutionPlatforms() throws Exception {
// Request the executionPlatforms.
@@ -337,77 +304,6 @@
}
@Test
- public void testRegisteredExecutionPlatforms_bzlmod() throws Exception {
- scratch.overwriteFile(
- "MODULE.bazel",
- "module(execution_platforms_to_register=['//:plat'])",
- "bazel_dep(name='B',version='1.0')",
- "bazel_dep(name='C',version='1.1')");
- registry
- .addModule(
- createModuleKey("B", "1.0"),
- "module(",
- " name='B',",
- " version='1.0',",
- " execution_platforms_to_register=['//:plat'],",
- ")",
- "bazel_dep(name='D',version='1.0')")
- .addModule(
- createModuleKey("C", "1.1"),
- "module(",
- " name='C',",
- " version='1.1',",
- " execution_platforms_to_register=['//:plat'],",
- ")",
- "bazel_dep(name='D',version='1.1')")
- // D@1.0 is not selected
- .addModule(
- createModuleKey("D", "1.0"),
- "module(",
- " name='D',",
- " version='1.0',",
- " execution_platforms_to_register=['//:plat'],",
- ")")
- .addModule(
- createModuleKey("D", "1.1"),
- "module(",
- " name='D',",
- " version='1.1',",
- " execution_platforms_to_register=['@E//:plat', '//:plat'],",
- ")",
- "bazel_dep(name='E',version='1.0')")
- .addModule(createModuleKey("E", "1.0"), "module(name='E', version='1.0')");
- for (String repo : ImmutableList.of("B.1.0", "C.1.1", "D.1.0", "D.1.1", "E.1.0")) {
- scratch.file(moduleRoot.getRelative(repo).getRelative("WORKSPACE").getPathString());
- scratch.file(
- moduleRoot.getRelative(repo).getRelative("BUILD").getPathString(),
- "platform(name='plat')");
- }
- scratch.overwriteFile("BUILD", "platform(name='plat');platform(name='wsplat')");
- rewriteWorkspace("register_execution_platforms('//:wsplat')");
-
- SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey);
- EvaluationResult<RegisteredExecutionPlatformsValue> result =
- requestExecutionPlatformsFromSkyframe(executionPlatformsKey);
- if (result.hasError()) {
- throw result.getError().getException();
- }
- assertThatEvaluationResult(result).hasNoError();
-
- // Verify that the execution platforms registered with bzlmod come in the BFS order and before
- // WORKSPACE registrations.
- assertExecutionPlatformLabels(result.get(executionPlatformsKey))
- .containsExactly(
- Label.parseAbsoluteUnchecked("//:plat"),
- Label.parseAbsoluteUnchecked("@B.1.0//:plat"),
- Label.parseAbsoluteUnchecked("@C.1.1//:plat"),
- Label.parseAbsoluteUnchecked("@E.1.0//:plat"),
- Label.parseAbsoluteUnchecked("@D.1.1//:plat"),
- Label.parseAbsoluteUnchecked("//:wsplat"))
- .inOrder();
- }
-
- @Test
public void testRegisteredExecutionPlatformsValue_equalsAndHashCode()
throws ConstraintCollection.DuplicateConstraintException {
ConfiguredTargetKey executionPlatformKey1 =
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java
index bdbed77..b2adebe 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java
@@ -15,25 +15,18 @@
package com.google.devtools.build.lib.skyframe;
import static com.google.common.truth.Truth.assertThat;
-import static com.google.devtools.build.lib.bazel.bzlmod.BzlmodTestUtil.createModuleKey;
import static com.google.devtools.build.skyframe.EvaluationResultSubjectFactory.assertThatEvaluationResult;
import com.google.common.collect.ImmutableList;
import com.google.common.testing.EqualsTester;
import com.google.devtools.build.lib.analysis.platform.DeclaredToolchainInfo;
import com.google.devtools.build.lib.analysis.platform.ToolchainTypeInfo;
-import com.google.devtools.build.lib.bazel.bzlmod.FakeRegistry;
-import com.google.devtools.build.lib.bazel.bzlmod.ModuleFileFunction;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.rules.platform.ToolchainTestCase;
-import com.google.devtools.build.lib.skyframe.PrecomputedValue.Injected;
-import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.skyframe.EvaluationResult;
import com.google.devtools.build.skyframe.SkyKey;
-import java.io.IOException;
import java.util.stream.Collectors;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -42,32 +35,6 @@
@RunWith(JUnit4.class)
public class RegisteredToolchainsFunctionTest extends ToolchainTestCase {
- private Path moduleRoot;
- private FakeRegistry registry;
-
- @Override
- protected boolean enableBzlmod() {
- return true;
- }
-
- @Override
- protected ImmutableList<Injected> extraPrecomputedValues() {
- try {
- moduleRoot = scratch.dir("modules");
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- registry = FakeRegistry.DEFAULT_FACTORY.newFakeRegistry(moduleRoot.getPathString());
- return ImmutableList.of(
- PrecomputedValue.injected(
- ModuleFileFunction.REGISTRIES, ImmutableList.of(registry.getUrl())));
- }
-
- @Before
- public void setUpForBzlmod() throws Exception {
- scratch.file("MODULE.bazel");
- }
-
@Test
public void testRegisteredToolchains() throws Exception {
// Request the toolchains.
@@ -315,115 +282,6 @@
}
@Test
- public void testRegisteredToolchains_bzlmod() throws Exception {
- scratch.overwriteFile(
- "MODULE.bazel",
- "module(toolchains_to_register=['//:tool'])",
- "bazel_dep(name='B',version='1.0')",
- "bazel_dep(name='C',version='1.1')",
- "bazel_dep(name='toolchain_def',version='1.0')");
- registry
- .addModule(
- createModuleKey("B", "1.0"),
- "module(",
- " name='B',",
- " version='1.0',",
- " toolchains_to_register=['//:tool'],",
- ")",
- "bazel_dep(name='D',version='1.0')",
- "bazel_dep(name='toolchain_def',version='1.0')")
- .addModule(
- createModuleKey("C", "1.1"),
- "module(",
- " name='C',",
- " version='1.1',",
- " toolchains_to_register=['//:tool'],",
- ")",
- "bazel_dep(name='D',version='1.1')",
- "bazel_dep(name='toolchain_def',version='1.0')")
- // D@1.0 is not selected
- .addModule(
- createModuleKey("D", "1.0"),
- "module(",
- " name='D',",
- " version='1.0',",
- " toolchains_to_register=['//:tool'],",
- ")",
- "bazel_dep(name='toolchain_def',version='1.0')")
- .addModule(
- createModuleKey("D", "1.1"),
- "module(",
- " name='D',",
- " version='1.1',",
- " toolchains_to_register=['@E//:tool', '//:tool'],",
- ")",
- "bazel_dep(name='E',version='1.0')",
- "bazel_dep(name='toolchain_def',version='1.0')")
- .addModule(
- createModuleKey("E", "1.0"),
- "module(name='E',version='1.0')",
- "bazel_dep(name='toolchain_def',version='1.0')")
- .addModule(
- createModuleKey("toolchain_def", "1.0"), "module(name='toolchain_def',version='1.0')");
-
- // Everyone depends on toolchain_def@1.0 for the declare_toolchain macro.
- Path toolchainDefDir = moduleRoot.getRelative("toolchain_def.1.0");
- scratch.file(toolchainDefDir.getRelative("WORKSPACE").getPathString());
- scratch.file(
- toolchainDefDir.getRelative("BUILD").getPathString(),
- "toolchain_type(name = 'test_toolchain')");
- scratch.file(
- toolchainDefDir.getRelative("toolchain_def.bzl").getPathString(),
- "def _impl(ctx):",
- " toolchain = platform_common.ToolchainInfo(data = ctx.attr.data)",
- " return [toolchain]",
- "test_toolchain = rule(implementation = _impl, attrs = {'data': attr.string()})",
- "def declare_toolchain(name):",
- " native.toolchain(",
- " name = name,",
- " toolchain_type = Label('//:test_toolchain'),",
- " toolchain = ':' + name + '_impl')",
- " test_toolchain(",
- " name = name + '_impl',",
- " data = 'stuff')");
-
- // Now create the toolchains for each module.
- for (String repo : ImmutableList.of("B.1.0", "C.1.1", "D.1.0", "D.1.1", "E.1.0")) {
- scratch.file(moduleRoot.getRelative(repo).getRelative("WORKSPACE").getPathString());
- scratch.file(
- moduleRoot.getRelative(repo).getRelative("BUILD").getPathString(),
- "load('@toolchain_def//:toolchain_def.bzl', 'declare_toolchain')",
- "declare_toolchain(name='tool')");
- }
- scratch.overwriteFile(
- "BUILD",
- "load('@toolchain_def//:toolchain_def.bzl', 'declare_toolchain')",
- "declare_toolchain(name='tool')",
- "declare_toolchain(name='wstool')");
- rewriteWorkspace("register_toolchains('//:wstool')");
-
- SkyKey toolchainsKey = RegisteredToolchainsValue.key(targetConfigKey);
- EvaluationResult<RegisteredToolchainsValue> result =
- requestToolchainsFromSkyframe(toolchainsKey);
- if (result.hasError()) {
- throw result.getError().getException();
- }
- assertThatEvaluationResult(result).hasNoError();
-
- // Verify that the toolchains registered with bzlmod come in the BFS order and before WORKSPACE
- // registrations.
- assertToolchainLabels(result.get(toolchainsKey))
- .containsAtLeast(
- Label.parseAbsoluteUnchecked("//:tool_impl"),
- Label.parseAbsoluteUnchecked("@B.1.0//:tool_impl"),
- Label.parseAbsoluteUnchecked("@C.1.1//:tool_impl"),
- Label.parseAbsoluteUnchecked("@E.1.0//:tool_impl"),
- Label.parseAbsoluteUnchecked("@D.1.1//:tool_impl"),
- Label.parseAbsoluteUnchecked("//:wstool_impl"))
- .inOrder();
- }
-
- @Test
public void testRegisteredToolchainsValue_equalsAndHashCode() throws Exception {
DeclaredToolchainInfo toolchain1 =
DeclaredToolchainInfo.builder()