Skip to content

Commit

Permalink
Also report cycles involving WORKSPACE from BzlmodRepoCycleReporter
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jan 19, 2024
1 parent b8d8c70 commit fc36c87
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
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 @@ -2434,8 +2434,10 @@ java_library(
"//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/lib/skyframe:repository_mapping_value",
"//src/main/java/com/google/devtools/build/skyframe",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
"//third_party:guava",
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

0 comments on commit fc36c87

Please sign in to comment.