Skip to content

Commit

Permalink
Remove old toolchain registration syntax from Bzlmod
Browse files Browse the repository at this point in the history
Fixes bazelbuild#15829

PiperOrigin-RevId: 473753020
Change-Id: I73b442693fc7452aa8364e594e5cc78b7dae1954
  • Loading branch information
Wyverald authored and aiuto committed Oct 12, 2022
1 parent 20b5c6f commit 6858345
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,39 +167,13 @@ static void validateModuleName(String moduleName) throws EvalException {
named = true,
positional = false,
defaultValue = "''"),
@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=\"${link toolchains}\">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=\"${link toolchains}\">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,
String repoName,
Iterable<?> executionPlatformsToRegister,
Iterable<?> toolchainsToRegister,
StarlarkThread thread)
throws EvalException {
if (moduleCalled) {
Expand All @@ -222,18 +196,11 @@ public void module(
} catch (ParseException e) {
throw new EvalException("Invalid version in module()", e);
}
// TODO(wyv): migrate users of execution_platforms_to_register and toolchains_to_register to
// register_execution_platforms and register_toolchains, and remove the former two attributes.
module
.setName(name)
.setVersion(parsedVersion)
.setCompatibilityLevel(compatibilityLevel.toInt("compatibility_level"))
.setRepoName(repoName)
.addExecutionPlatformsToRegister(
checkAllAbsolutePatterns(
executionPlatformsToRegister, "execution_platforms_to_register"))
.addToolchainsToRegister(
checkAllAbsolutePatterns(toolchainsToRegister, "toolchains_to_register"));
.setRepoName(repoName);
}

private static ImmutableList<String> checkAllAbsolutePatterns(Iterable<?> iterable, String where)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,11 @@ public void testRootModule() throws Exception {
" name='aaa',",
" version='0.1',",
" compatibility_level=4,",
" toolchains_to_register=['//my:toolchain', '//my:toolchain2'],",
" execution_platforms_to_register=['//my:platform', '//my:platform2'],",
")",
"bazel_dep(name='bbb',version='1.0')",
"bazel_dep(name='ccc',version='2.0',repo_name='see')",
"register_toolchains('//my:toolchain3', '//my:toolchain4')",
"register_execution_platforms('//my:platform3', '//my:platform4')",
"register_toolchains('//my:toolchain', '//my:toolchain2')",
"register_execution_platforms('//my:platform', '//my:platform2')",
"single_version_override(module_name='ddd',version='18')",
"local_path_override(module_name='eee',path='somewhere/else')",
"multiple_version_override(module_name='fff',versions=['1.0','2.0'])",
Expand All @@ -209,11 +207,8 @@ public void testRootModule() throws Exception {
ModuleBuilder.create("aaa", "0.1", 4)
.setKey(ModuleKey.ROOT)
.addExecutionPlatformsToRegister(
ImmutableList.of(
"//my:platform", "//my:platform2", "//my:platform3", "//my:platform4"))
.addToolchainsToRegister(
ImmutableList.of(
"//my:toolchain", "//my:toolchain2", "//my:toolchain3", "//my:toolchain4"))
ImmutableList.of("//my:platform", "//my:platform2"))
.addToolchainsToRegister(ImmutableList.of("//my:toolchain", "//my:toolchain2"))
.addDep("bbb", createModuleKey("bbb", "1.0"))
.addDep("see", createModuleKey("ccc", "2.0"))
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public void testRegisteredExecutionPlatforms_bzlmod() throws Exception {
setBuildLanguageOptions("--enable_bzlmod");
scratch.overwriteFile(
"MODULE.bazel",
"module(execution_platforms_to_register=['//:plat'])",
"register_execution_platforms('//:plat')",
"bazel_dep(name='bbb',version='1.0')",
"bazel_dep(name='ccc',version='1.1')");
registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void testRegisteredToolchains_bzlmod() throws Exception {
setBuildLanguageOptions("--enable_bzlmod");
scratch.overwriteFile(
"MODULE.bazel",
"module(toolchains_to_register=['//:tool'])",
"register_toolchains('//:tool')",
"bazel_dep(name='bbb',version='1.0')",
"bazel_dep(name='ccc',version='1.1')",
"bazel_dep(name='toolchain_def',version='1.0')");
Expand Down

0 comments on commit 6858345

Please sign in to comment.