[7.3.1] Use target.getLookupKey() for contstructing lookup keys for vendor mode (#23309)
Fixes https://github.com/bazelbuild/bazel/issues/23300
Closes #23301.
PiperOrigin-RevId: 663007815
Change-Id: I304a9ffd344bc5cc3dbf5542bdee401109247a35
Commit
https://github.com/bazelbuild/bazel/commit/af2d688f3f6654b2931eff70cd63816e4fc45196
Co-authored-by: Yun Peng <pcloudy@google.com>
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/commands/BUILD
index 8d7a8e6..b98dd56 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/commands/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/BUILD
@@ -27,6 +27,7 @@
"//src/main/java/com/google/devtools/build/lib:loading-phase-threads-option",
"//src/main/java/com/google/devtools/build/lib:runtime",
"//src/main/java/com/google/devtools/build/lib:runtime/blaze_command_result",
+ "//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
"//src/main/java/com/google/devtools/build/lib/analysis:no_build_event",
"//src/main/java/com/google/devtools/build/lib/analysis:no_build_request_finished_event",
"//src/main/java/com/google/devtools/build/lib/bazel:resolved_event",
@@ -53,7 +54,6 @@
"//src/main/java/com/google/devtools/build/lib/rules:repository/resolved_file_value",
"//src/main/java/com/google/devtools/build/lib/runtime/commands",
"//src/main/java/com/google/devtools/build/lib/shell",
- "//src/main/java/com/google/devtools/build/lib/skyframe:configured_target_key",
"//src/main/java/com/google/devtools/build/lib/skyframe:package_lookup_value",
"//src/main/java/com/google/devtools/build/lib/skyframe:precomputed_value",
"//src/main/java/com/google/devtools/build/lib/skyframe:repository_mapping_value",
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/VendorCommand.java b/src/main/java/com/google/devtools/build/lib/bazel/commands/VendorCommand.java
index bb9fc19..cde398c 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/commands/VendorCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/VendorCommand.java
@@ -18,6 +18,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.NoBuildEvent;
import com.google.devtools.build.lib.analysis.NoBuildRequestFinishedEvent;
import com.google.devtools.build.lib.bazel.bzlmod.BazelFetchAllValue;
@@ -47,7 +48,6 @@
import com.google.devtools.build.lib.server.FailureDetails;
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
import com.google.devtools.build.lib.server.FailureDetails.FetchCommand.Code;
-import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
import com.google.devtools.build.lib.skyframe.PrecomputedValue;
import com.google.devtools.build.lib.skyframe.RepositoryMappingValue.RepositoryMappingResolutionException;
import com.google.devtools.build.lib.skyframe.SkyFunctions;
@@ -279,12 +279,7 @@
// Traverse the graph created from build to collect repos and vendor them
ImmutableList<SkyKey> targetKeys =
buildResult.getActualTargets().stream()
- .map(
- target ->
- ConfiguredTargetKey.builder()
- .setConfigurationKey(target.getConfigurationKey())
- .setLabel(target.getLabel())
- .build())
+ .map(ConfiguredTarget::getLookupKey)
.collect(toImmutableList());
InMemoryGraph inMemoryGraph = env.getSkyframeExecutor().getEvaluator().getInMemoryGraph();
ImmutableSet<RepositoryName> reposToVendor = collectReposFromTargets(inMemoryGraph, targetKeys);
diff --git a/src/test/py/bazel/bzlmod/bazel_vendor_test.py b/src/test/py/bazel/bzlmod/bazel_vendor_test.py
index f69a97a..4dc87a2 100644
--- a/src/test/py/bazel/bzlmod/bazel_vendor_test.py
+++ b/src/test/py/bazel/bzlmod/bazel_vendor_test.py
@@ -810,6 +810,14 @@
' bar!\n',
)
+ def testVendorAliasTarget(self):
+ self.ScratchFile('foo/file.txt')
+ self.ScratchFile('foo/BUILD', ['alias(name="foo", actual="file.txt")'])
+
+ # This should not fail
+ # Regression test for https://github.com/bazelbuild/bazel/issues/23300
+ self.RunBazel(['vendor', '//foo/...', '--vendor_dir=vendor'])
+
if __name__ == '__main__':
absltest.main()