Skip to content

Commit

Permalink
Bzlmod: Better canonical repo names for modules with overrides (bazel…
Browse files Browse the repository at this point in the history
…build#15793)

(bazelbuild#13316)

Use "foo.override" instead of just "foo" as the canonical repo name for the module "foo" when it has a non-registry override. Context: https://groups.google.com/a/bazel.build/g/external-deps/c/GcV1cpRd-Ls/m/o446O3vGAAAJ

PiperOrigin-RevId: 423049588

Co-authored-by: wyv <[email protected]>
  • Loading branch information
fmeum and Wyverald authored Jul 5, 2022
1 parent e7efa1f commit 62be9ea
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ public String getCanonicalRepoName() {
if (WELL_KNOWN_MODULES.containsKey(getName())) {
return WELL_KNOWN_MODULES.get(getName());
}
if (ROOT.equals(this)) {
return "";
}
if (getVersion().isEmpty()) {
return getName();
return getName() + ".override";
}
return getName() + "." + getVersion();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void createValue_basic() throws Exception {
"dep.1.0", createModuleKey("dep", "1.0"),
"dep.2.0", createModuleKey("dep", "2.0"),
"rules_cc.1.0", createModuleKey("rules_cc", "1.0"),
"rules_java", createModuleKey("rules_java", ""));
"rules_java.override", createModuleKey("rules_java", ""));
assertThat(value.getModuleNameLookup())
.containsExactly(
"rules_cc", createModuleKey("rules_cc", "1.0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,19 @@ public void getRepoSpec_nonRegistryOverride() throws Exception {
ModuleFileFunction.REGISTRIES.set(differencer, ImmutableList.of(registry.getUrl()));

EvaluationResult<GetRepoSpecByNameValue> result =
driver.evaluate(ImmutableList.of(getRepoSpecByNameKey("C")), evaluationContext);
driver.evaluate(ImmutableList.of(getRepoSpecByNameKey("C.override")), evaluationContext);
if (result.hasError()) {
fail(result.getError().toString());
}

Optional<RepoSpec> repoSpec = result.get(getRepoSpecByNameKey("C")).rule();
Optional<RepoSpec> repoSpec = result.get(getRepoSpecByNameKey("C.override")).rule();
assertThat(repoSpec)
.hasValue(
RepoSpec.builder()
.setRuleClassName("local_repository")
.setAttributes(
ImmutableMap.of(
"name", "C",
"name", "C.override",
"path", "/foo/bar/C"))
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void testRootModule() throws Exception {
"",
0));
assertThat(rootModuleFileValue.getNonRegistryOverrideCanonicalRepoNameLookup())
.containsExactly("E", "E", "G", "G");
.containsExactly("E.override", "E", "G.override", "G");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void basic() throws Exception {
assertThat(pomTags.get(0).getValue("pom_xmls"))
.isEqualTo(
StarlarkList.immutableOf(
Label.parseAbsoluteUnchecked("@foo//:pom.xml"),
Label.parseAbsoluteUnchecked("@foo.override//:pom.xml"),
Label.parseAbsoluteUnchecked("@bar.2.0//:pom.xml")));
}

Expand Down

0 comments on commit 62be9ea

Please sign in to comment.