Start the process of getting Target out of ConfiguredTarget: add a new container, ConfiguredTargetAndTarget, that can be used to access Targets, and deprecate ConfiguredTarget#getTarget. ConfiguredAndTargetObjects are intended to be limited in scope, not being persisted to Skyframe.

The eventual plan is to remove the target field from ConfiguredTarget.

This CL is mostly straightforward, except for dealing with AliasConfiguredTargets, which cause some complications.

A significant cleanup is still needed before #getTarget can be removed, but I don't see any impossible blockers. We will may still need to store a Target-like object in ConfiguredTarget (that has the RuleClass, or at least a string representation of it, for instance), but that will let us avoid storing a full Target together with its associated Package.

PiperOrigin-RevId: 182371566
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
index 4b58054..95ea703 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
@@ -21,6 +21,7 @@
 import com.google.common.base.Preconditions;
 import com.google.common.base.Predicate;
 import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMultimap;
@@ -80,6 +81,7 @@
 import com.google.devtools.build.lib.skyframe.AspectValue;
 import com.google.devtools.build.lib.skyframe.AspectValue.AspectKey;
 import com.google.devtools.build.lib.skyframe.AspectValue.AspectValueKey;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndTarget;
 import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
 import com.google.devtools.build.lib.skyframe.CoverageReportValue;
 import com.google.devtools.build.lib.skyframe.SkyframeAnalysisResult;
@@ -894,13 +896,15 @@
       BuildConfigurationCollection configurations)
       throws EvalException, InvalidConfigurationException,
       InterruptedException, InconsistentAspectOrderException {
-    return skyframeExecutor.getConfiguredTargets(
-        eventHandler,
-        ct.getConfiguration(),
-        ImmutableSet.copyOf(
-            getDirectPrerequisiteDependenciesForTesting(
-                    eventHandler, ct, configurations, /*toolchainContext=*/ null)
-                .values()));
+    return Collections2.transform(
+        skyframeExecutor.getConfiguredTargets(
+            eventHandler,
+            ct.getConfiguration(),
+            ImmutableSet.copyOf(
+                getDirectPrerequisiteDependenciesForTesting(
+                        eventHandler, ct, configurations, /*toolchainContext=*/ null)
+                    .values())),
+        ConfiguredTargetAndTarget::getConfiguredTarget);
   }
 
   @VisibleForTesting
@@ -1002,7 +1006,7 @@
     return ImmutableMap.copyOf(keys);
   }
 
-  private OrderedSetMultimap<Attribute, ConfiguredTarget> getPrerequisiteMapForTesting(
+  private OrderedSetMultimap<Attribute, ConfiguredTargetAndTarget> getPrerequisiteMapForTesting(
       final ExtendedEventHandler eventHandler,
       ConfiguredTarget target,
       BuildConfigurationCollection configurations,
@@ -1013,11 +1017,11 @@
         getDirectPrerequisiteDependenciesForTesting(
             eventHandler, target, configurations, toolchainContext);
 
-    ImmutableMultimap<Dependency, ConfiguredTarget> cts = skyframeExecutor.getConfiguredTargetMap(
-        eventHandler,
-        target.getConfiguration(), ImmutableSet.copyOf(depNodeNames.values()));
+    ImmutableMultimap<Dependency, ConfiguredTargetAndTarget> cts =
+        skyframeExecutor.getConfiguredTargetMap(
+            eventHandler, target.getConfiguration(), ImmutableSet.copyOf(depNodeNames.values()));
 
-    OrderedSetMultimap<Attribute, ConfiguredTarget> result = OrderedSetMultimap.create();
+    OrderedSetMultimap<Attribute, ConfiguredTargetAndTarget> result = OrderedSetMultimap.create();
     for (Map.Entry<Attribute, Dependency> entry : depNodeNames.entries()) {
       result.putAll(entry.getKey(), cts.get(entry.getValue()));
     }
@@ -1111,7 +1115,7 @@
     ToolchainContext toolchainContext =
         skyframeExecutor.getToolchainContextForTesting(
             requiredToolchains, targetConfig, eventHandler);
-    OrderedSetMultimap<Attribute, ConfiguredTarget> prerequisiteMap =
+    OrderedSetMultimap<Attribute, ConfiguredTargetAndTarget> prerequisiteMap =
         getPrerequisiteMapForTesting(eventHandler, target, configurations, toolchainContext);
     toolchainContext.resolveToolchains(prerequisiteMap);
 
@@ -1147,13 +1151,13 @@
       BuildConfigurationCollection configurations)
       throws EvalException, InvalidConfigurationException, InterruptedException,
              InconsistentAspectOrderException {
-    Collection<ConfiguredTarget> configuredTargets =
+    Collection<ConfiguredTargetAndTarget> configuredTargets =
         getPrerequisiteMapForTesting(
                 eventHandler, dependentTarget, configurations, /*toolchainContext=*/ null)
             .values();
-    for (ConfiguredTarget ct : configuredTargets) {
-      if (ct.getLabel().equals(desiredTarget)) {
-        return ct;
+    for (ConfiguredTargetAndTarget ct : configuredTargets) {
+      if (ct.getTarget().getLabel().equals(desiredTarget)) {
+        return ct.getConfiguredTarget();
       }
     }
     return null;