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

[7.1.0] Improve use_repo_rule error when not referencing a repository_rule #20732

Merged
merged 2 commits into from
Jan 4, 2024
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 @@ -620,7 +620,7 @@ public RunModuleExtensionResult run(
// Instiantiate the repos one by one.
for (InnateExtensionRepo repo : repos) {
Object exported = repo.loadedBzl().getModule().getGlobal(repo.ruleName());
if (!(exported instanceof RepositoryRuleFunction)) {
if (exported == null) {
ImmutableSet<String> exportedRepoRules =
repo.loadedBzl().getModule().getGlobals().entrySet().stream()
.filter(e -> e.getValue() instanceof RepositoryRuleFunction)
Expand All @@ -636,6 +636,17 @@ public RunModuleExtensionResult run(
repo.tag().getLocation(),
SpellChecker.didYouMean(repo.ruleName(), exportedRepoRules)),
Transience.PERSISTENT);
} else if (!(exported instanceof RepositoryRuleFunction)) {
throw new SingleExtensionEvalFunctionException(
ExternalDepsException.withMessage(
Code.BAD_MODULE,
"%s exports a value called %s of type %s, yet a repository_rule is requested"
+ " at %s",
repo.bzlLabel(),
repo.ruleName(),
Starlark.type(exported),
repo.tag().getLocation()),
Transience.PERSISTENT);
}
RepositoryRuleFunction repoRule = (RepositoryRuleFunction) exported;
Dict<String, Object> kwargs = repo.tag().getAttributeValues().attributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2448,7 +2448,35 @@ public void innate_noSuchRepoRule() throws Exception {
"load('@data//:data.bzl', self_data='data')",
"data=self_data");
scratch.file(
workspaceRoot.getRelative("repo.bzl").getPathString(), "data_repo = 3 # not a repo rule");
workspaceRoot.getRelative("repo.bzl").getPathString(),
"# not a repo rule",
"def data_repo(name):",
" pass");

SkyKey skyKey = BzlLoadValue.keyForBuild(Label.parseCanonical("//:data.bzl"));
reporter.removeHandler(failFastHandler);
EvaluationResult<BzlLoadValue> result =
evaluator.evaluate(ImmutableList.of(skyKey), evaluationContext);
assertThat(result.hasError()).isTrue();
assertThat(result.getError().getException())
.hasMessageThat()
.contains(
"//:repo.bzl exports a value called data_repo of type function, yet a repository_rule"
+ " is requested at /ws/MODULE.bazel");
}

@Test
public void innate_noSuchValue() throws Exception {
scratch.file(
workspaceRoot.getRelative("MODULE.bazel").getPathString(),
"data_repo = use_repo_rule('//:repo.bzl', 'data_repo')",
"data_repo(name='data', data='get up at 6am.')");
scratch.file(workspaceRoot.getRelative("BUILD").getPathString());
scratch.file(
workspaceRoot.getRelative("data.bzl").getPathString(),
"load('@data//:data.bzl', self_data='data')",
"data=self_data");
scratch.file(workspaceRoot.getRelative("repo.bzl").getPathString(), "");

SkyKey skyKey = BzlLoadValue.keyForBuild(Label.parseCanonical("//:data.bzl"));
reporter.removeHandler(failFastHandler);
Expand Down
Loading