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

[6.3.0] Fail on isolated extension usages without imports #18793

Merged
merged 1 commit into from
Jun 27, 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 @@ -162,6 +162,18 @@ private SkyValue computeForRootModule(StarlarkSemantics starlarkSemantics, Envir
starlarkSemantics,
env);
InterimModule module = moduleFileGlobals.buildModule();
for (ModuleExtensionUsage usage : module.getExtensionUsages()) {
if (usage.getIsolationKey().isPresent() && usage.getImports().isEmpty()) {
throw errorf(
Code.BAD_MODULE,
"the isolated usage at %s of extension %s defined in %s has no effect as no "
+ "repositories are imported from it. Either import one or more repositories "
+ "generated by the extension with use_repo or remove the usage.",
usage.getLocation(),
usage.getExtensionName(),
usage.getExtensionBzlFile());
}
}

ImmutableMap<String, ModuleOverride> moduleOverrides = moduleFileGlobals.buildOverrides();
Map<String, ModuleOverride> commandOverrides = MODULE_OVERRIDES.get(env);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,10 @@ private EvaluationResult<SingleExtensionEvalValue> evaluateIsolatedModuleExtensi
workspaceRoot.getRelative("MODULE.bazel").getPathString(),
String.format(
"ext = use_extension('//:defs.bzl', 'ext', dev_dependency = %s, isolate = %s)",
devDependencyStr, isolateStr));
devDependencyStr, isolateStr),
// Isolated module extensions without repo imports result in an error in
// ModuleFileFunction.
"use_repo(ext, 'some_repo')");
scratch.file(
workspaceRoot.getRelative("defs.bzl").getPathString(),
"def _ext_impl(ctx):",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,4 +1032,24 @@ public void module_calledLate() throws Exception {

assertContainsEvent("if module() is called, it must be called before any other functions");
}

@Test
public void isolatedExtensionWithoutImports() throws Exception {
scratch.file(
rootDirectory.getRelative("MODULE.bazel").getPathString(),
"isolated_ext = use_extension('//:extensions.bzl', 'my_ext', isolate = True)");
FakeRegistry registry = registryFactory.newFakeRegistry("/foo");
ModuleFileFunction.REGISTRIES.set(differencer, ImmutableList.of(registry.getUrl()));

EvaluationResult<RootModuleFileValue> result =
evaluator.evaluate(
ImmutableList.of(ModuleFileValue.KEY_FOR_ROOT_MODULE), evaluationContext);
assertThat(result.hasError()).isTrue();
assertThat(result.getError().toString())
.contains(
"the isolated usage at /workspace/MODULE.bazel:1:29 of extension my_ext defined in "
+ "@//:extensions.bzl has no effect as no repositories are imported from it. "
+ "Either import one or more repositories generated by the extension with "
+ "use_repo or remove the usage.");
}
}