Skip to content

Commit

Permalink
Add dev_dependency to register_{execution_platforms,toolchains}
Browse files Browse the repository at this point in the history
Fixes bazelbuild#18248

Closes bazelbuild#18253.

PiperOrigin-RevId: 527858646
Change-Id: I544694bb55f466bd6e14660ae62f2d535c283563
  • Loading branch information
fmeum authored and copybara-github committed Apr 28, 2023
1 parent 40cf855 commit f39454f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,27 @@ public void bazelDep(
+ " selected. Should be absolute target patterns (ie. beginning with either"
+ " <code>@</code> or <code>//</code>). See <a href=\"${link toolchains}\">toolchain"
+ " resolution</a> 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"));
}
Expand All @@ -368,13 +382,27 @@ public void registerExecutionPlatforms(Sequence<?> platformLabels) throws EvalEx
+ " Should be absolute target patterns (ie. beginning with either <code>@</code> or"
+ " <code>//</code>). See <a href=\"${link toolchains}\">toolchain resolution</a> 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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,21 @@ 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
.addModule(
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(
Expand All @@ -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);
Expand All @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')");
Expand All @@ -315,24 +316,28 @@ 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
.addModule(
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(
Expand Down Expand Up @@ -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')");
Expand All @@ -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"),
Expand Down

0 comments on commit f39454f

Please sign in to comment.