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] Also report cycles involving WORKSPACE from BzlmodRepoCycleReporter #21013

Merged
merged 1 commit into from
Jan 24, 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
2 changes: 2 additions & 0 deletions src/main/java/com/google/devtools/build/lib/skyframe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2351,11 +2351,13 @@ java_library(
deps = [
":abstract_label_cycle_reporter",
":bzl_load_value",
":repository_mapping_value",
":sky_functions",
"//src/main/java/com/google/devtools/build/lib/bazel/bzlmod:module_extension",
"//src/main/java/com/google/devtools/build/lib/bazel/bzlmod:repo_rule_value",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/repository:request_repository_information_event",
"//src/main/java/com/google/devtools/build/lib/rules:repository/repository_directory_value",
"//src/main/java/com/google/devtools/build/skyframe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.ExtendedEventHandler;
import com.google.devtools.build.lib.packages.WorkspaceFileValue;
import com.google.devtools.build.lib.repository.RequestRepositoryInformationEvent;
import com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue;
import com.google.devtools.build.skyframe.CycleInfo;
Expand Down Expand Up @@ -53,6 +54,21 @@ public class BzlmodRepoCycleReporter implements CyclesReporter.SingleCycleReport
private static final Predicate<SkyKey> IS_EXTENSION_IMPL =
SkyFunctions.isSkyFunction(SkyFunctions.SINGLE_EXTENSION_EVAL);

private static final Predicate<SkyKey> IS_REPO_MAPPING =
SkyFunctions.isSkyFunction(SkyFunctions.REPOSITORY_MAPPING);

private static final Predicate<SkyKey> IS_MODULE_EXTENSION_REPO_MAPPING_ENTRIES =
SkyFunctions.isSkyFunction(SkyFunctions.MODULE_EXTENSION_REPO_MAPPING_ENTRIES);

private static final Predicate<SkyKey> IS_PACKAGE =
SkyFunctions.isSkyFunction(SkyFunctions.PACKAGE);

private static final Predicate<SkyKey> IS_EXTERNAL_PACKAGE =
SkyFunctions.isSkyFunction(SkyFunctions.EXTERNAL_PACKAGE);

private static final Predicate<SkyKey> IS_WORKSPACE_FILE =
SkyFunctions.isSkyFunction(WorkspaceFileValue.WORKSPACE_FILE);

private static void requestRepoDefinitions(
ExtendedEventHandler eventHandler, Iterable<SkyKey> repos) {
for (SkyKey repo : repos) {
Expand Down Expand Up @@ -85,21 +101,33 @@ public boolean maybeReportCycle(
// |___________________|___|
// TODO(andreisolo): Figure out how to detect and print this kind of cycles more specifically.
if (Iterables.all(
cycle,
Predicates.or(
IS_REPOSITORY_DIRECTORY,
IS_PACKAGE_LOOKUP,
IS_REPO_RULE,
IS_EXTENSION_IMPL,
IS_BZL_LOAD,
IS_CONTAINING_PACKAGE))) {
cycle,
Predicates.or(
IS_REPOSITORY_DIRECTORY,
IS_PACKAGE_LOOKUP,
IS_REPO_RULE,
IS_EXTENSION_IMPL,
IS_BZL_LOAD,
IS_CONTAINING_PACKAGE,
IS_REPO_MAPPING,
IS_MODULE_EXTENSION_REPO_MAPPING_ENTRIES,
IS_PACKAGE,
IS_EXTERNAL_PACKAGE,
IS_WORKSPACE_FILE))
&& Iterables.any(cycle, Predicates.or(IS_REPO_RULE, IS_EXTENSION_IMPL))) {
StringBuilder cycleMessage =
new StringBuilder(
"Circular definition of repositories generated by module extensions and/or .bzl"
+ " files:");
Iterable<SkyKey> repos =
Iterables.filter(
cycle, Predicates.or(IS_REPOSITORY_DIRECTORY, IS_EXTENSION_IMPL, IS_BZL_LOAD));
cycle,
Predicates.or(
IS_REPOSITORY_DIRECTORY,
IS_EXTENSION_IMPL,
IS_BZL_LOAD,
IS_REPO_MAPPING,
IS_WORKSPACE_FILE));
Function<Object, String> printer =
rawInput -> {
SkyKey input = (SkyKey) rawInput;
Expand All @@ -110,6 +138,14 @@ public boolean maybeReportCycle(
return String.format(
"extension '%s' defined in %s",
id.getExtensionName(), id.getBzlFileLabel().getCanonicalForm());
} else if (input.argument() instanceof RepositoryMappingValue.Key) {
var key = (RepositoryMappingValue.Key) input.argument();
if (key == RepositoryMappingValue.KEY_FOR_ROOT_MODULE_WITHOUT_WORKSPACE_REPOS) {
return "repository mapping of @@ without WORKSPACE repos";
}
return String.format("repository mapping of %s", key.repoName());
} else if (input.argument() instanceof WorkspaceFileValue.WorkspaceFileKey) {
return "WORKSPACE file";
} else {
Preconditions.checkArgument(input.argument() instanceof BzlLoadValue.Key);
return ((BzlLoadValue.Key) input.argument()).getLabel().toString();
Expand Down
Loading