From a3443dd9a132c3f2a5f897dbdee8ed61e605fbbf Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Tue, 30 May 2023 06:57:19 -0700 Subject: [PATCH] Use extension rather than local names in ModuleExtensionMetadata ModuleExtensionMetadata incorrectly identified repos by their local names rather than the names used by the generating extension, which resulted in incorrect fixup warnings when supplying keyword arguments to `use_repo`. Closes #18528. PiperOrigin-RevId: 536386347 Change-Id: I4368b0dcdc28d6b2827b74b3b0b73c31a0215c0f --- .../bazel/bzlmod/ModuleExtensionMetadata.java | 2 +- .../bzlmod/ModuleExtensionResolutionTest.java | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionMetadata.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionMetadata.java index fde1c8fcd6887c..d680b3100402c3 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionMetadata.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionMetadata.java @@ -188,7 +188,7 @@ private static Optional generateFixupMessage( .collect(toImmutableSet()); var actualImports = rootUsages.stream() - .flatMap(usage -> usage.getImports().keySet().stream()) + .flatMap(usage -> usage.getImports().values().stream()) .filter(repo -> !actualDevImports.contains(repo)) .collect(toImmutableSet()); diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java index 06033115a3f683..9e115fe0596632 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java @@ -1599,13 +1599,23 @@ public void extensionMetadata() throws Exception { "bazel_dep(name='ext', version='1.0')", "bazel_dep(name='data_repo',version='1.0')", "ext = use_extension('@ext//:defs.bzl', 'ext')", - "use_repo(ext, 'direct_dep', 'indirect_dep', 'invalid_dep')", + "use_repo(", + " ext,", + " 'indirect_dep',", + " 'invalid_dep',", + " my_direct_dep = 'direct_dep',", + ")", "ext_dev = use_extension('@ext//:defs.bzl', 'ext', dev_dependency = True)", - "use_repo(ext_dev, 'direct_dev_dep', 'indirect_dev_dep', 'invalid_dev_dep')"); + "use_repo(", + " ext_dev,", + " 'indirect_dev_dep',", + " 'invalid_dev_dep',", + " my_direct_dev_dep = 'direct_dev_dep',", + ")"); scratch.file(workspaceRoot.getRelative("BUILD").getPathString()); scratch.file( workspaceRoot.getRelative("data.bzl").getPathString(), - "load('@direct_dep//:data.bzl', direct_dep_data='data')", + "load('@my_direct_dep//:data.bzl', direct_dep_data='data')", "data = direct_dep_data"); registry.addModule(