Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dev_dependency to register_{execution_platforms,toolchains} #18253

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.",
extraPositionals =
parameters = {
@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 {
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(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.",
extraPositionals =
parameters = {
@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 {
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(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,10 @@ 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 +393,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