From fc36c874f21b38b32a63a99399862bf003f42b6b Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 19 Jan 2024 15:23:14 +0100 Subject: [PATCH] Also report cycles involving WORKSPACE from BzlmodRepoCycleReporter --- .../google/devtools/build/lib/skyframe/BUILD | 2 + .../lib/skyframe/BzlmodRepoCycleReporter.java | 54 +++++++++++++++---- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/BUILD index 40907eb646690b..fa4b11ef131a43 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/BUILD +++ b/src/main/java/com/google/devtools/build/lib/skyframe/BUILD @@ -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", diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoCycleReporter.java b/src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoCycleReporter.java index 65a60bd85120cf..6ed9f158038a7f 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoCycleReporter.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/BzlmodRepoCycleReporter.java @@ -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; @@ -53,6 +54,21 @@ public class BzlmodRepoCycleReporter implements CyclesReporter.SingleCycleReport private static final Predicate IS_EXTENSION_IMPL = SkyFunctions.isSkyFunction(SkyFunctions.SINGLE_EXTENSION_EVAL); + private static final Predicate IS_REPO_MAPPING = + SkyFunctions.isSkyFunction(SkyFunctions.REPOSITORY_MAPPING); + + private static final Predicate IS_MODULE_EXTENSION_REPO_MAPPING_ENTRIES = + SkyFunctions.isSkyFunction(SkyFunctions.MODULE_EXTENSION_REPO_MAPPING_ENTRIES); + + private static final Predicate IS_PACKAGE = + SkyFunctions.isSkyFunction(SkyFunctions.PACKAGE); + + private static final Predicate IS_EXTERNAL_PACKAGE = + SkyFunctions.isSkyFunction(SkyFunctions.EXTERNAL_PACKAGE); + + private static final Predicate IS_WORKSPACE_FILE = + SkyFunctions.isSkyFunction(WorkspaceFileValue.WORKSPACE_FILE); + private static void requestRepoDefinitions( ExtendedEventHandler eventHandler, Iterable repos) { for (SkyKey repo : repos) { @@ -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 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 printer = rawInput -> { SkyKey input = (SkyKey) rawInput; @@ -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();