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 4e8054c347e1a9..c711c83f0fabf4 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
@@ -350,13 +350,27 @@ public void bazelDep(
+ " selected. Should be absolute target patterns (ie. beginning with either"
+ " @
or //
). See toolchain"
+ " resolution for more information.",
+ parameters = {
+ @Param(
+ name = "dev_dependency",
+ doc =
+ "If true, the execution platforms will not be registered if the current module is"
+ + " not the root module or `--ignore_dev_dependency` is enabled.",
+ named = true,
+ positional = false,
+ defaultValue = "False"),
+ },
extraPositionals =
@Param(
name = "platform_labels",
allowedTypes = {@ParamType(type = Sequence.class, generic1 = String.class)},
doc = "The labels of the platforms to register."))
- public void registerExecutionPlatforms(Sequence> platformLabels) throws EvalException {
+ public void registerExecutionPlatforms(boolean devDependency, Sequence> platformLabels)
+ throws EvalException {
hadNonModuleCall = true;
+ if (ignoreDevDeps && devDependency) {
+ return;
+ }
module.addExecutionPlatformsToRegister(
checkAllAbsolutePatterns(platformLabels, "register_execution_platforms"));
}
@@ -368,13 +382,27 @@ public void registerExecutionPlatforms(Sequence> platformLabels) throws EvalEx
+ " Should be absolute target patterns (ie. beginning with either @
or"
+ " //
). See toolchain resolution for"
+ " more information.",
+ parameters = {
+ @Param(
+ name = "dev_dependency",
+ doc =
+ "If true, the toolchains will not be registered if the current module is not the"
+ + " root module or `--ignore_dev_dependency` is enabled.",
+ named = true,
+ positional = false,
+ defaultValue = "False"),
+ },
extraPositionals =
@Param(
name = "toolchain_labels",
allowedTypes = {@ParamType(type = Sequence.class, generic1 = String.class)},
doc = "The labels of the toolchains to register."))
- public void registerToolchains(Sequence> toolchainLabels) throws EvalException {
+ public void registerToolchains(boolean devDependency, Sequence> toolchainLabels)
+ throws EvalException {
hadNonModuleCall = true;
+ if (ignoreDevDeps && devDependency) {
+ return;
+ }
module.addToolchainsToRegister(
checkAllAbsolutePatterns(toolchainLabels, "register_toolchains"));
}
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 622eafea37b648..f40c8d01ade7a4 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
@@ -341,6 +341,7 @@ public void testRegisteredExecutionPlatforms_bzlmod() throws Exception {
scratch.overwriteFile(
"MODULE.bazel",
"register_execution_platforms('//:plat')",
+ "register_execution_platforms('//:dev_plat',dev_dependency=True)",
"bazel_dep(name='bbb',version='1.0')",
"bazel_dep(name='ccc',version='1.1')");
registry
@@ -348,11 +349,13 @@ public void testRegisteredExecutionPlatforms_bzlmod() throws Exception {
createModuleKey("bbb", "1.0"),
"module(name='bbb',version='1.0')",
"register_execution_platforms('//:plat')",
+ "register_execution_platforms('//:dev_plat',dev_dependency=True)",
"bazel_dep(name='ddd',version='1.0')")
.addModule(
createModuleKey("ccc", "1.1"),
"module(name='ccc',version='1.1')",
"register_execution_platforms('//:plat')",
+ "register_execution_platforms('//:dev_plat',dev_dependency=True)",
"bazel_dep(name='ddd',version='1.1')")
// ddd@1.0 is not selected
.addModule(
@@ -371,7 +374,8 @@ public void testRegisteredExecutionPlatforms_bzlmod() throws Exception {
moduleRoot.getRelative(repo).getRelative("BUILD").getPathString(),
"platform(name='plat')");
}
- scratch.overwriteFile("BUILD", "platform(name='plat');platform(name='wsplat')");
+ scratch.overwriteFile(
+ "BUILD", "platform(name='plat')", "platform(name='dev_plat')", "platform(name='wsplat')");
rewriteWorkspace("register_execution_platforms('//:wsplat')");
SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey);
@@ -387,6 +391,7 @@ public void testRegisteredExecutionPlatforms_bzlmod() throws Exception {
assertExecutionPlatformLabels(result.get(executionPlatformsKey))
.containsExactly(
Label.parseCanonical("//:plat"),
+ Label.parseCanonical("//:dev_plat"),
Label.parseCanonical("@@bbb~1.0//:plat"),
Label.parseCanonical("@@ccc~1.1//:plat"),
Label.parseCanonical("@@eee~1.0//:plat"),
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 4495ddd0233704..d9bce3c2f5e80d 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
@@ -307,6 +307,7 @@ public void testRegisteredToolchains_bzlmod() throws Exception {
scratch.overwriteFile(
"MODULE.bazel",
"register_toolchains('//:tool')",
+ "register_toolchains('//:dev_tool',dev_dependency=True)",
"bazel_dep(name='bbb',version='1.0')",
"bazel_dep(name='ccc',version='1.1')",
"bazel_dep(name='toolchain_def',version='1.0')");
@@ -315,12 +316,14 @@ public void testRegisteredToolchains_bzlmod() throws Exception {
createModuleKey("bbb", "1.0"),
"module(name='bbb',version='1.0')",
"register_toolchains('//:tool')",
+ "register_toolchains('//:dev_tool',dev_dependency=True)",
"bazel_dep(name='ddd',version='1.0')",
"bazel_dep(name='toolchain_def',version='1.0')")
.addModule(
createModuleKey("ccc", "1.1"),
"module(name='ccc',version='1.1')",
"register_toolchains('//:tool')",
+ "register_toolchains('//:dev_tool',dev_dependency=True)",
"bazel_dep(name='ddd',version='1.1')",
"bazel_dep(name='toolchain_def',version='1.0')")
// ddd@1.0 is not selected
@@ -328,11 +331,13 @@ public void testRegisteredToolchains_bzlmod() throws Exception {
createModuleKey("ddd", "1.0"),
"module(name='ddd',version='1.0')",
"register_toolchains('//:tool')",
+ "register_toolchains('//:dev_tool',dev_dependency=True)",
"bazel_dep(name='toolchain_def',version='1.0')")
.addModule(
createModuleKey("ddd", "1.1"),
"module(name='ddd',version='1.1')",
"register_toolchains('@eee//:tool', '//:tool')",
+ "register_toolchains('@eee//:dev_tool',dev_dependency=True)",
"bazel_dep(name='eee',version='1.0')",
"bazel_dep(name='toolchain_def',version='1.0')")
.addModule(
@@ -369,11 +374,13 @@ public void testRegisteredToolchains_bzlmod() throws Exception {
scratch.file(
moduleRoot.getRelative(repo).getRelative("BUILD").getPathString(),
"load('@toolchain_def//:toolchain_def.bzl', 'declare_toolchain')",
- "declare_toolchain(name='tool')");
+ "declare_toolchain(name='tool')",
+ "declare_toolchain(name='dev_tool')");
}
scratch.overwriteFile(
"BUILD",
"load('@toolchain_def//:toolchain_def.bzl', 'declare_toolchain')",
+ "declare_toolchain(name='dev_tool')",
"declare_toolchain(name='tool')",
"declare_toolchain(name='wstool')");
rewriteWorkspace("register_toolchains('//:wstool')");
@@ -391,6 +398,7 @@ public void testRegisteredToolchains_bzlmod() throws Exception {
assertToolchainLabels(result.get(toolchainsKey))
.containsAtLeast(
Label.parseCanonical("//:tool_impl"),
+ Label.parseCanonical("//:dev_tool_impl"),
Label.parseCanonical("@@bbb~1.0//:tool_impl"),
Label.parseCanonical("@@ccc~1.1//:tool_impl"),
Label.parseCanonical("@@eee~1.0//:tool_impl"),