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

Fail early if use_extension has a bad label #17926

Merged
merged 1 commit into from
Mar 30, 2023
Merged
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 @@ -69,11 +69,11 @@ public SkyValue compute(SkyKey skyKey, Environment env)
PackageIdentifier.create(module.getCanonicalRepoName(), PathFragment.EMPTY_FRAGMENT),
module.getRepoMappingWithBazelDepsOnly());
for (ModuleExtensionUsage usage : module.getExtensionUsages()) {
ModuleExtensionId moduleExtensionId;
try {
ModuleExtensionId moduleExtensionId =
moduleExtensionId =
ModuleExtensionId.create(
labelConverter.convert(usage.getExtensionBzlFile()), usage.getExtensionName());
extensionUsagesTableBuilder.put(moduleExtensionId, module.getKey(), usage);
} catch (LabelSyntaxException e) {
throw new BazelModuleResolutionFunctionException(
ExternalDepsException.withCauseAndMessage(
Expand All @@ -83,6 +83,16 @@ public SkyValue compute(SkyKey skyKey, Environment env)
usage.getLocation()),
Transience.PERSISTENT);
}
if (!moduleExtensionId.getBzlFileLabel().getRepository().isVisible()) {
throw new BazelModuleResolutionFunctionException(
ExternalDepsException.withMessage(
Code.BAD_MODULE,
"invalid label for module extension found at %s: no repo visible as '@%s' here",
usage.getLocation(),
moduleExtensionId.getBzlFileLabel().getRepository().getName()),
Transience.PERSISTENT);
}
extensionUsagesTableBuilder.put(moduleExtensionId, module.getKey(), usage);
}
}
ImmutableTable<ModuleExtensionId, ModuleKey, ModuleExtensionUsage> extensionUsagesById =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,23 @@ public void createValue_moduleExtensions() throws Exception {
"dep~2.0~myext2~myext"));
}

@Test
public void useExtensionBadLabelFails() throws Exception {
Module root =
Module.builder()
.addExtensionUsage(createModuleExtensionUsage("@foo//:defs.bzl", "bar"))
.build();
ImmutableMap<ModuleKey, Module> depGraph = ImmutableMap.of(ModuleKey.ROOT, root);

resolutionFunctionMock.setDepGraph(depGraph);
EvaluationResult<BazelDepGraphValue> result =
evaluator.evaluate(ImmutableList.of(BazelDepGraphValue.KEY), evaluationContext);
if (!result.hasError()) {
fail("expected error about @foo not being visible, but succeeded");
}
assertThat(result.getError().toString()).contains("no repo visible as '@foo' here");
}

private static class BazelModuleResolutionFunctionMock implements SkyFunction {

private ImmutableMap<ModuleKey, Module> depGraph = ImmutableMap.of();
Expand Down