Refactor to get rid of some getConfiguredTarget() calls in tests and replace
them with getConfiguredTargetAndTarget() so we can get rid of
ConfiguredTarget.getTarget() callers. This should be a test only change.

PiperOrigin-RevId: 184877255
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 a3835d8..a4cf6e4 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
@@ -1133,6 +1133,12 @@
         getTopLevelTransitionForTarget(label, eventHandler));
   }
 
+  @VisibleForTesting
+  public ConfiguredTargetAndTarget getConfiguredTargetAndTargetForTesting(
+      ExtendedEventHandler eventHandler, Label label, BuildConfiguration config) {
+    return skyframeExecutor.getConfiguredTargetAndTargetForTesting(eventHandler, label, config);
+  }
+
   /**
    * Returns a RuleContext which is the same as the original RuleContext of the target parameter.
    */
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index 9377524..4cc6602 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -1641,9 +1641,7 @@
     return getConfiguredTargetForTesting(eventHandler, label, configuration, NoTransition.INSTANCE);
   }
 
-  /**
-   * Returns a particular configured target after applying the given transition.
-   */
+  /** Returns a particular configured target after applying the given transition. */
   @VisibleForTesting
   @Nullable
   public ConfiguredTarget getConfiguredTargetForTesting(
@@ -1652,6 +1650,20 @@
       BuildConfiguration configuration,
       ConfigurationTransition transition) {
     ConfiguredTargetAndTarget configuredTargetAndTarget =
+        getConfiguredTargetAndTargetForTesting(eventHandler, label, configuration, transition);
+    return configuredTargetAndTarget == null
+        ? null
+        : configuredTargetAndTarget.getConfiguredTarget();
+  }
+
+  @VisibleForTesting
+  @Nullable
+  public ConfiguredTargetAndTarget getConfiguredTargetAndTargetForTesting(
+      ExtendedEventHandler eventHandler,
+      Label label,
+      BuildConfiguration configuration,
+      ConfigurationTransition transition) {
+    ConfiguredTargetAndTarget configuredTargetAndTarget =
         Iterables.getFirst(
             getConfiguredTargetsForTesting(
                 eventHandler,
@@ -1662,9 +1674,15 @@
                         : Dependency.withTransitionAndAspects(
                             label, transition, AspectCollection.EMPTY))),
             null);
-    return configuredTargetAndTarget == null
-        ? null
-        : configuredTargetAndTarget.getConfiguredTarget();
+    return configuredTargetAndTarget;
+  }
+
+  @VisibleForTesting
+  @Nullable
+  public ConfiguredTargetAndTarget getConfiguredTargetAndTargetForTesting(
+      ExtendedEventHandler eventHandler, Label label, BuildConfiguration configuration) {
+    return getConfiguredTargetAndTargetForTesting(
+        eventHandler, label, configuration, NoTransition.INSTANCE);
   }
 
   /**
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AspectAwareAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AspectAwareAttributeMapperTest.java
index a5e2c46..7f20fff 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/AspectAwareAttributeMapperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/AspectAwareAttributeMapperTest.java
@@ -23,6 +23,7 @@
 import com.google.devtools.build.lib.packages.Attribute;
 import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.Rule;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndTarget;
 import com.google.devtools.build.lib.util.FileTypeSet;
 import org.junit.Before;
 import org.junit.Test;
@@ -40,12 +41,17 @@
 
   @Before
   public final void createMapper() throws Exception {
-    RuleConfiguredTarget ct = (RuleConfiguredTarget) scratchConfiguredTarget("foo", "myrule",
-        "cc_binary(",
-        "    name = 'myrule',",
-        "    srcs = [':a.cc'],",
-        "    linkstatic = select({'//conditions:default': 1}))");
-    rule = ct.getTarget();
+    ConfiguredTargetAndTarget ctat =
+        scratchConfiguredTargetAndTarget(
+            "foo",
+            "myrule",
+            "cc_binary(",
+            "    name = 'myrule',",
+            "    srcs = [':a.cc'],",
+            "    linkstatic = select({'//conditions:default': 1}))");
+
+    RuleConfiguredTarget ct = (RuleConfiguredTarget) ctat.getConfiguredTarget();
+    rule = (Rule) ctat.getTarget();
     Attribute aspectAttr = new Attribute.Builder<Label>("fromaspect", BuildType.LABEL)
         .allowedFileTypes(FileTypeSet.ANY_FILE)
         .build();
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java
index 510be59..6af2d40 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java
@@ -44,6 +44,7 @@
 import com.google.devtools.build.lib.events.OutputFilter.RegexOutputFilter;
 import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.Rule;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndTarget;
 import com.google.devtools.build.lib.testutil.Suite;
 import com.google.devtools.build.lib.testutil.TestConstants;
 import com.google.devtools.build.lib.testutil.TestSpec;
@@ -91,9 +92,9 @@
     Rule ruleTarget = (Rule) getTarget("//pkg:foo");
     assertThat(ruleTarget.getRuleClass()).isEqualTo("genrule");
 
-    ConfiguredTarget ruleCT = getConfiguredTarget("//pkg:foo");
+    ConfiguredTargetAndTarget ruleCTAT = getConfiguredTargetAndTarget("//pkg:foo");
 
-    assertThat(ruleCT.getTarget()).isSameAs(ruleTarget);
+    assertThat(ruleCTAT.getTarget()).isSameAs(ruleTarget);
   }
 
   @Test
@@ -115,14 +116,17 @@
     //scratch.file("tests/small_test_1.py");
 
     update("//tests:smallTests");
+    ConfiguredTargetAndTarget test1 = getConfiguredTargetAndTarget("//tests:small_test_1");
+    ConfiguredTargetAndTarget test2 = getConfiguredTargetAndTarget("//tests:small_test_2");
+    ConfiguredTargetAndTarget suite = getConfiguredTargetAndTarget("//tests:smallTests");
 
-    ConfiguredTarget test1 = getConfiguredTarget("//tests:small_test_1");
-    ConfiguredTarget test2 = getConfiguredTarget("//tests:small_test_2");
-    ConfiguredTarget suite = getConfiguredTarget("//tests:smallTests");
+    ConfiguredTarget test1CT = test1.getConfiguredTarget();
+    ConfiguredTarget test2CT = test2.getConfiguredTarget();
+    ConfiguredTarget suiteCT = suite.getConfiguredTarget();
     assertNoEvents(); // start from a clean slate
 
     Collection<ConfiguredTarget> targets =
-        new LinkedHashSet<>(ImmutableList.of(test1, test2, suite));
+        new LinkedHashSet<>(ImmutableList.of(test1CT, test2CT, suiteCT));
     targets =
         Lists.<ConfiguredTarget>newArrayList(
             BuildView.filterTestsByTargets(
@@ -130,7 +134,7 @@
                 Sets.newHashSet(test1.getTarget(), suite.getTarget()),
                 NullEventHandler.INSTANCE,
                 skyframeExecutor.getPackageManager()));
-    assertThat(targets).containsExactlyElementsIn(Sets.newHashSet(test1, suite));
+    assertThat(targets).containsExactlyElementsIn(Sets.newHashSet(test1CT, suiteCT));
   }
 
   @Test
@@ -147,17 +151,16 @@
   public void testGeneratedArtifact() throws Exception {
     setupDummyRule();
     update("//pkg:a.out");
-    OutputFileConfiguredTarget outputCT = (OutputFileConfiguredTarget)
-        getConfiguredTarget("//pkg:a.out");
-    Artifact outputArtifact = outputCT.getArtifact();
+    OutputFileConfiguredTarget output =
+        (OutputFileConfiguredTarget) getConfiguredTarget("//pkg:a.out");
+    Artifact outputArtifact = output.getArtifact();
     assertThat(outputArtifact.getRoot())
         .isEqualTo(
-            outputCT
+            output
                 .getConfiguration()
-                .getBinDirectory(
-                    outputCT.getTarget().getLabel().getPackageIdentifier().getRepository()));
+                .getBinDirectory(output.getLabel().getPackageIdentifier().getRepository()));
     assertThat(outputArtifact.getExecPath())
-        .isEqualTo(outputCT.getConfiguration().getBinFragment().getRelative("pkg/a.out"));
+        .isEqualTo(output.getConfiguration().getBinFragment().getRelative("pkg/a.out"));
     assertThat(outputArtifact.getRootRelativePath()).isEqualTo(PathFragment.create("pkg/a.out"));
 
     Action action = getGeneratingAction(outputArtifact);
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
index 519807f..fc9aa99 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
@@ -58,6 +58,7 @@
 import com.google.devtools.build.lib.runtime.KeepGoingOption;
 import com.google.devtools.build.lib.runtime.LoadingPhaseThreadsOption;
 import com.google.devtools.build.lib.skyframe.BazelSkyframeExecutorConstants;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndTarget;
 import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
 import com.google.devtools.build.lib.skyframe.PrecomputedValue;
 import com.google.devtools.build.lib.skyframe.SequencedSkyframeExecutor;
@@ -389,6 +390,23 @@
     return update(new EventBus(), defaultFlags(), aspects, labels);
   }
 
+  protected ConfiguredTargetAndTarget getConfiguredTargetAndTarget(String label)
+      throws InterruptedException {
+    return getConfiguredTargetAndTarget(label, getTargetConfiguration());
+  }
+
+  protected ConfiguredTargetAndTarget getConfiguredTargetAndTarget(
+      String label, BuildConfiguration config) {
+    ensureUpdateWasCalled();
+    Label parsedLabel;
+    try {
+      parsedLabel = Label.parseAbsolute(label);
+    } catch (LabelSyntaxException e) {
+      throw new AssertionError(e);
+    }
+    return skyframeExecutor.getConfiguredTargetAndTargetForTesting(reporter, parsedLabel, config);
+  }
+
   protected Target getTarget(String label) throws InterruptedException {
     try {
       return SkyframeExecutorTestUtils.getExistingTarget(skyframeExecutor,
@@ -403,6 +421,14 @@
     return getConfiguredTargetForSkyframe(label, configuration);
   }
 
+  /**
+   * Returns the corresponding configured target, if it exists. Note that this will only return
+   * anything useful after a call to update() with the same label.
+   */
+  protected ConfiguredTarget getConfiguredTarget(String label) throws InterruptedException {
+    return getConfiguredTarget(label, getTargetConfiguration());
+  }
+
   private ConfiguredTarget getConfiguredTargetForSkyframe(String label,
       BuildConfiguration configuration) {
     Label parsedLabel;
@@ -416,14 +442,6 @@
 
   /**
    * Returns the corresponding configured target, if it exists. Note that this will only return
-   * anything useful after a call to update() with the same label.
-   */
-  protected ConfiguredTarget getConfiguredTarget(String label) throws InterruptedException {
-    return getConfiguredTarget(label, getTargetConfiguration());
-  }
-
-  /**
-   * Returns the corresponding configured target, if it exists. Note that this will only return
    * anything useful after a call to update() with the same label. The label passed in must
    * represent an input file.
    */
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
index 8d89ee0..479cde3 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
@@ -123,6 +123,7 @@
 import com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction;
 import com.google.devtools.build.lib.skyframe.AspectValue;
 import com.google.devtools.build.lib.skyframe.BazelSkyframeExecutorConstants;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndTarget;
 import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
 import com.google.devtools.build.lib.skyframe.DiffAwareness;
 import com.google.devtools.build.lib.skyframe.LegacyLoadingPhaseRunner;
@@ -624,25 +625,6 @@
     return skyframeExecutor.getActionGraph(reporter);
   }
 
-  protected final Action getGeneratingAction(Artifact artifact) {
-    Preconditions.checkNotNull(artifact);
-    ActionAnalysisMetadata action = mutableActionGraph.getGeneratingAction(artifact);
-
-    if (action == null) {
-      action = getActionGraph().getGeneratingAction(artifact);
-    }
-
-    if (action != null) {
-      Preconditions.checkState(
-          action instanceof Action,
-          "%s is not a proper Action object",
-          action.prettyPrint());
-      return (Action) action;
-    } else {
-      return null;
-    }
-  }
-
   @Nullable
   protected final ParameterFileWriteAction findParamsFileAction(SpawnAction spawnAction) {
     for (Artifact input : spawnAction.getInputs()) {
@@ -670,6 +652,23 @@
     return getGeneratingAction(artifact);
   }
 
+  protected final Action getGeneratingAction(Artifact artifact) {
+    Preconditions.checkNotNull(artifact);
+    ActionAnalysisMetadata action = mutableActionGraph.getGeneratingAction(artifact);
+
+    if (action == null) {
+      action = getActionGraph().getGeneratingAction(artifact);
+    }
+
+    if (action != null) {
+      Preconditions.checkState(
+          action instanceof Action, "%s is not a proper Action object", action.prettyPrint());
+      return (Action) action;
+    } else {
+      return null;
+    }
+  }
+
   protected Action getGeneratingActionInOutputGroup(
       ConfiguredTarget target, String outputName, String outputGroupName) {
     NestedSet<Artifact> outputGroup =
@@ -685,6 +684,11 @@
     return (SpawnAction) getGeneratingAction(artifact);
   }
 
+  protected SpawnAction getGeneratingSpawnAction(ConfiguredTarget target, String outputName) {
+    return getGeneratingSpawnAction(
+        Iterables.find(getFilesToBuild(target), artifactNamed(outputName)));
+  }
+
   protected final List<String> getGeneratingSpawnActionArgs(Artifact artifact)
       throws CommandLineExpansionException {
     SpawnAction a = getGeneratingSpawnAction(artifact);
@@ -694,11 +698,6 @@
         : ImmutableList.copyOf(Iterables.concat(a.getArguments(), p.getContents()));
   }
 
-  protected SpawnAction getGeneratingSpawnAction(ConfiguredTarget target, String outputName) {
-    return getGeneratingSpawnAction(
-        Iterables.find(getFilesToBuild(target), artifactNamed(outputName)));
-  }
-
   protected ActionsTestUtil actionsTestUtil() {
     return new ActionsTestUtil(getActionGraph());
   }
@@ -743,6 +742,25 @@
   }
 
   /**
+   * Returns a ConfiguredTargetAndTarget for the specified label, using the given build
+   * configuration.
+   */
+  protected ConfiguredTargetAndTarget getConfiguredTargetAndTarget(
+      Label label, BuildConfiguration config) {
+    return view.getConfiguredTargetAndTargetForTesting(reporter, label, config);
+  }
+
+  /**
+   * Returns the ConfiguredTargetAndTarget for the specified label. If the label corresponds to a
+   * target with a top-level configuration transition, that transition is applied to the given
+   * config in the ConfiguredTargetAndTarget's ConfiguredTarget.
+   */
+  public ConfiguredTargetAndTarget getConfiguredTargetAndTarget(String label)
+      throws LabelSyntaxException {
+    return getConfiguredTargetAndTarget(Label.parseAbsolute(label), targetConfig);
+  }
+
+  /**
    * Returns the ConfiguredTarget for the specified file label, configured for
    * the "build" (aka "target") configuration.
    */
@@ -803,6 +821,57 @@
   }
 
   /**
+   * Create and return a configured scratch rule.
+   *
+   * @param packageName the package name of the rule.
+   * @param ruleName the name of the rule.
+   * @param config the configuration to use to construct the configured rule.
+   * @param lines the text of the rule.
+   * @return the configured target instance for the created rule.
+   * @throws IOException
+   * @throws Exception
+   */
+  protected ConfiguredTarget scratchConfiguredTarget(
+      String packageName, String ruleName, BuildConfiguration config, String... lines)
+      throws IOException, Exception {
+    ConfiguredTargetAndTarget ctat =
+        scratchConfiguredTargetAndTarget(packageName, ruleName, config, lines);
+    return ctat == null ? null : ctat.getConfiguredTarget();
+  }
+
+  /**
+   * Creates and returns a configured scratch rule and it's target.
+   *
+   * @param packageName the package name of the rule.
+   * @param rulename the name of the rule.
+   * @param lines the text of the rule.
+   * @return the configured tatarget and target instance for the created rule.
+   * @throws Exception
+   */
+  protected ConfiguredTargetAndTarget scratchConfiguredTargetAndTarget(
+      String packageName, String rulename, String... lines) throws Exception {
+    return scratchConfiguredTargetAndTarget(packageName, rulename, targetConfig, lines);
+  }
+
+  /**
+   * Creates and returns a configured scratch rule and it's target.
+   *
+   * @param packageName the package name of the rule.
+   * @param ruleName the name of the rule.
+   * @param config the configuration to use to construct the configured rule.
+   * @param lines the text of the rule.
+   * @return the ConfiguredTargetAndTarget instance for the created rule.
+   * @throws IOException
+   * @throws Exception
+   */
+  protected ConfiguredTargetAndTarget scratchConfiguredTargetAndTarget(
+      String packageName, String ruleName, BuildConfiguration config, String... lines)
+      throws Exception {
+    Target rule = scratchRule(packageName, ruleName, lines);
+    return view.getConfiguredTargetAndTargetForTesting(reporter, rule.getLabel(), config);
+  }
+
+  /**
    * Create and return a scratch rule.
    *
    * @param packageName the package name of the rule.
@@ -829,26 +898,6 @@
   }
 
   /**
-   * Create and return a configured scratch rule.
-   *
-   * @param packageName the package name of the rule.
-   * @param ruleName the name of the rule.
-   * @param config the configuration to use to construct the configured rule.
-   * @param lines the text of the rule.
-   * @return the configured target instance for the created rule.
-   * @throws IOException
-   * @throws Exception
-   */
-  protected ConfiguredTarget scratchConfiguredTarget(String packageName,
-                                                     String ruleName,
-                                                     BuildConfiguration config,
-                                                     String... lines)
-      throws IOException, Exception {
-    Target rule = scratchRule(packageName, ruleName, lines);
-    return view.getConfiguredTargetForTesting(reporter, rule.getLabel(), config);
-  }
-
-  /**
    * Check that configuration of the target named 'ruleName' in the
    * specified BUILD file fails with an error message ending in
    * 'expectedErrorMessage'.
@@ -1156,18 +1205,6 @@
   }
 
   /**
-   * Strips the C++-contributed prefix out of an output path when tests are run with trimmed
-   * configurations. e.g. turns "bazel-out/gcc-X-glibc-Y-k8-fastbuild/ to "bazel-out/fastbuild/".
-   *
-   * <p>This should be used for targets use configurations with C++ fragments.
-   */
-  protected String stripCppPrefixForTrimmedConfigs(String outputPath) {
-    return targetConfig.trimConfigurations()
-        ? AnalysisTestUtil.OUTPUT_PATH_CPP_PREFIX_PATTERN.matcher(outputPath).replaceFirst("")
-        : outputPath;
-  }
-
-  /**
    * Gets a derived Artifact for testing in the subdirectory of the {@link
    * BuildConfiguration#getGenfilesDirectory} corresponding to the package of {@code owner}. So to
    * specify a file foo/foo.o owned by target //foo:foo, {@code packageRelativePath} should just be
@@ -1219,6 +1256,18 @@
     return getGeneratingAction(getFileConfiguredTarget(label).getArtifact());
   }
 
+  /**
+   * Strips the C++-contributed prefix out of an output path when tests are run with trimmed
+   * configurations. e.g. turns "bazel-out/gcc-X-glibc-Y-k8-fastbuild/ to "bazel-out/fastbuild/".
+   *
+   * <p>This should be used for targets use configurations with C++ fragments.
+   */
+  protected String stripCppPrefixForTrimmedConfigs(String outputPath) {
+    return targetConfig.trimConfigurations()
+        ? AnalysisTestUtil.OUTPUT_PATH_CPP_PREFIX_PATTERN.matcher(outputPath).replaceFirst("")
+        : outputPath;
+  }
+
   protected String fileName(Artifact artifact) {
     return artifact.getExecPathString();
   }
@@ -1301,20 +1350,6 @@
     }
   }
 
-  private BuildConfiguration getConfiguration(String label) {
-    BuildConfiguration config;
-    try {
-      config = getConfiguredTarget(label).getConfiguration();
-      config = view.getConfigurationForTesting(getTarget(label), config, reporter);
-    } catch (LabelSyntaxException e) {
-      throw new IllegalArgumentException(e);
-    } catch (Exception e) {
-      //TODO(b/36585204): Clean this up
-      throw new RuntimeException(e);
-    }
-    return config;
-  }
-
   private ConfiguredTargetKey makeConfiguredTargetKey(String label) {
     return ConfiguredTargetKey.of(makeLabel(label), getConfiguration(label));
   }
@@ -1519,6 +1554,20 @@
     }
   }
 
+  private BuildConfiguration getConfiguration(String label) {
+    BuildConfiguration config;
+    try {
+      config = getConfiguredTarget(label).getConfiguration();
+      config = view.getConfigurationForTesting(getTarget(label), config, reporter);
+    } catch (LabelSyntaxException e) {
+      throw new IllegalArgumentException(e);
+    } catch (Exception e) {
+      // TODO(b/36585204): Clean this up
+      throw new RuntimeException(e);
+    }
+    return config;
+  }
+
   /**
    * Returns an attribute value retriever for the given rule for the target configuration.
    */
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryIntegrationTest.java
index aec222e..7fa018d 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryIntegrationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryIntegrationTest.java
@@ -21,7 +21,6 @@
 import com.google.common.collect.ImmutableMap;
 import com.google.devtools.build.lib.analysis.BlazeDirectories;
 import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
-import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.util.AnalysisMock;
 import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
 import com.google.devtools.build.lib.bazel.repository.downloader.HttpDownloader;
@@ -32,6 +31,7 @@
 import com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction;
 import com.google.devtools.build.lib.rules.repository.RepositoryFunction;
 import com.google.devtools.build.lib.rules.repository.RepositoryLoaderFunction;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndTarget;
 import com.google.devtools.build.lib.skyframe.SkyFunctions;
 import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
 import com.google.devtools.build.skyframe.SkyFunction;
@@ -142,7 +142,7 @@
             .add("repo(name='foo', path='/repo2')")
             .build());
     invalidatePackages();
-    ConfiguredTarget target = getConfiguredTarget("@foo//:bar");
+    ConfiguredTargetAndTarget target = getConfiguredTargetAndTarget("@foo//:bar");
     Object path = target.getTarget().getAssociatedRule().getAttributeContainer().getAttr("path");
     assertThat(path).isEqualTo("foo");
   }
@@ -170,7 +170,7 @@
             .add("repo(name='foo')")
             .build());
     invalidatePackages();
-    ConfiguredTarget target = getConfiguredTarget("@foo//:bar");
+    ConfiguredTargetAndTarget target = getConfiguredTargetAndTarget("@foo//:bar");
     Object path = target.getTarget().getAssociatedRule().getAttributeContainer().getAttr("path");
     assertThat(path).isEqualTo("foo");
   }
@@ -199,7 +199,7 @@
             .add("repo(name='foo')")
             .build());
     invalidatePackages();
-    ConfiguredTarget target = getConfiguredTarget("@foo//:bar");
+    ConfiguredTargetAndTarget target = getConfiguredTargetAndTarget("@foo//:bar");
     Object path = target.getTarget().getAssociatedRule().getAttributeContainer().getAttr("path");
     assertThat(path).isEqualTo("foo");
   }
@@ -229,7 +229,7 @@
             .add("repo(name='foobar')")
             .build());
     invalidatePackages();
-    ConfiguredTarget target = getConfiguredTarget("@foobar//:bar");
+    ConfiguredTargetAndTarget target = getConfiguredTargetAndTarget("@foobar//:bar");
     Object path = target.getTarget().getAssociatedRule().getAttributeContainer().getAttr("path");
     assertThat(path).isEqualTo("foobar");
   }
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryTest.java
index c2bfad3..facfac3 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryTest.java
@@ -18,12 +18,12 @@
 
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
-import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.FilesToRunProvider;
 import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.packages.AttributeContainer;
 import com.google.devtools.build.lib.packages.BuildFileNotFoundException;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndTarget;
 import com.google.devtools.build.lib.testutil.MoreAsserts;
 import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
@@ -169,7 +169,8 @@
         ")");
     invalidatePackages();
 
-    ConfiguredTarget cpufeatures = getConfiguredTarget("@androidndk//:cpufeatures");
+    ConfiguredTargetAndTarget cpufeatures =
+        getConfiguredTargetAndTarget("@androidndk//:cpufeatures");
     assertThat(cpufeatures).isNotNull();
     AttributeContainer attributes =
         cpufeatures.getTarget().getAssociatedRule().getAttributeContainer();
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/SdkMavenRepositoryTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/SdkMavenRepositoryTest.java
index 02cf802..8f55fcc 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/SdkMavenRepositoryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/SdkMavenRepositoryTest.java
@@ -105,7 +105,9 @@
   public void testGeneratedAarImport() throws Exception {
     sdkMavenRepository.writeBuildFiles(workspaceDir);
     Rule aarImport =
-        getConfiguredTarget("//com.google.android:bar-1.0.0").getTarget().getAssociatedRule();
+        getConfiguredTargetAndTarget("//com.google.android:bar-1.0.0")
+            .getTarget()
+            .getAssociatedRule();
     assertThat(aarImport.getRuleClass()).isEqualTo("aar_import");
     AttributeMap attributes = RawAttributeMapper.of(aarImport);
     assertThat(attributes.get("aar", BuildType.LABEL))
@@ -118,7 +120,9 @@
   public void testGeneratedJavaImport() throws Exception {
     sdkMavenRepository.writeBuildFiles(workspaceDir);
     Rule javaImport =
-        getConfiguredTarget("//com.google.android:foo-1.0.0").getTarget().getAssociatedRule();
+        getConfiguredTargetAndTarget("//com.google.android:foo-1.0.0")
+            .getTarget()
+            .getAssociatedRule();
     assertThat(javaImport.getRuleClass()).isEqualTo("java_import");
     AttributeMap attributes = RawAttributeMapper.of(javaImport);
     assertThat(attributes.get("jars", BuildType.LABEL_LIST)).containsExactly(
@@ -130,7 +134,9 @@
   public void testGeneratedRuleForInvalidPackaging() throws Exception {
     sdkMavenRepository.writeBuildFiles(workspaceDir);
     Rule invalidPackagingGenrule =
-        getConfiguredTarget("//com.google.android:baz-1.0.0").getTarget().getAssociatedRule();
+        getConfiguredTargetAndTarget("//com.google.android:baz-1.0.0")
+            .getTarget()
+            .getAssociatedRule();
     assertThat(invalidPackagingGenrule.getRuleClass()).isEqualTo("genrule");
     assertThat(RawAttributeMapper.of(invalidPackagingGenrule).get("cmd", Type.STRING))
         .isEqualTo("echo Bazel does not recognize the Maven packaging type for: "
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java
index 227406c..26d908c 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java
@@ -51,6 +51,7 @@
 import com.google.devtools.build.lib.rules.java.JavaCompileAction;
 import com.google.devtools.build.lib.rules.java.JavaInfo;
 import com.google.devtools.build.lib.rules.java.JavaSemantics;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndTarget;
 import com.google.devtools.build.lib.testutil.MoreAsserts;
 import com.google.devtools.build.lib.util.FileType;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
@@ -1547,19 +1548,6 @@
         "png");
   }
 
-  private void testDirectResourceFiltering(
-      String filters, List<String> unexpectedQualifiers, ImmutableList<String> expectedQualifiers)
-      throws Exception {
-    testDirectResourceFiltering(
-        filters,
-        /* densities= */ "",
-        unexpectedQualifiers,
-        expectedQualifiers,
-        /* expectUnqualifiedResource= */ true,
-        "drawable",
-        "png");
-  }
-
   private void testDensityResourceFiltering(
       String densities, List<String> unexpectedQualifiers, List<String> expectedQualifiers)
       throws Exception {
@@ -1574,6 +1562,19 @@
   }
 
   private void testDirectResourceFiltering(
+      String filters, List<String> unexpectedQualifiers, ImmutableList<String> expectedQualifiers)
+      throws Exception {
+    testDirectResourceFiltering(
+        filters,
+        /* densities= */ "",
+        unexpectedQualifiers,
+        expectedQualifiers,
+        /* expectUnqualifiedResource= */ true,
+        "drawable",
+        "png");
+  }
+
+  private void testDirectResourceFiltering(
       String resourceConfigurationFilters,
       String densities,
       List<String> unexpectedQualifiers,
@@ -2004,7 +2005,7 @@
         "<resources><string name = 'lib_string'>Libs!</string></resources>");
     scratch.file("java/r/android/res/values/strings.xml",
         "<resources><string name = 'hello'>Hello Android!</string></resources>");
-    Artifact jar = getResourceClassJar(getConfiguredTarget("//java/r/android:r"));
+    Artifact jar = getResourceClassJar(getConfiguredTargetAndTarget("//java/r/android:r"));
     assertThat(getGeneratingAction(jar).getMnemonic()).isEqualTo("RClassGenerator");
     assertThat(getGeneratingSpawnActionArgs(jar))
         .containsAllOf("--primaryRTxt", "--primaryManifest", "--library", "--classJarOutput");
@@ -2019,7 +2020,7 @@
         "               )");
     scratch.file("java/r/android/res/values/strings.xml",
         "<resources><string name = 'hello'>Hello Android!</string></resources>");
-    Artifact jar = getResourceClassJar(getConfiguredTarget("//java/r/android:r"));
+    Artifact jar = getResourceClassJar(getConfiguredTargetAndTarget("//java/r/android:r"));
     assertThat(getGeneratingAction(jar).getMnemonic()).isEqualTo("RClassGenerator");
     List<String> args = getGeneratingSpawnActionArgs(jar);
     assertThat(args).containsAllOf("--primaryRTxt", "--primaryManifest", "--classJarOutput");
@@ -2044,7 +2045,7 @@
         "<resources><string name = 'lib_string'>Libs!</string></resources>");
     scratch.file("java/r/android/res/values/strings.xml",
         "<resources><string name = 'hello'>Hello Android!</string></resources>");
-    ConfiguredTarget binary = getConfiguredTarget("//java/r/android:r");
+    ConfiguredTargetAndTarget binary = getConfiguredTargetAndTarget("//java/r/android:r");
     Artifact jar = getResourceClassJar(binary);
     assertThat(getGeneratingAction(jar).getMnemonic()).isEqualTo("RClassGenerator");
     List<String> args = getGeneratingSpawnActionArgs(jar);
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
index 70003b2..657ecac 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
@@ -39,6 +39,7 @@
 import com.google.devtools.build.lib.rules.java.JavaCompileAction;
 import com.google.devtools.build.lib.rules.java.JavaInfo;
 import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndTarget;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -137,9 +138,9 @@
         transitive ? info.getTransitiveAndroidResources() : info.getDirectAndroidResources());
   }
 
-  protected Artifact getResourceClassJar(final ConfiguredTarget target) {
+  protected Artifact getResourceClassJar(final ConfiguredTargetAndTarget target) {
     JavaRuleOutputJarsProvider jarProvider =
-        JavaInfo.getProvider(JavaRuleOutputJarsProvider.class, target);
+        JavaInfo.getProvider(JavaRuleOutputJarsProvider.class, target.getConfiguredTarget());
     assertThat(jarProvider).isNotNull();
     return Iterables.find(
             jarProvider.getOutputJars(),
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestTest.java
index 50d9864..f50823b 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestTest.java
@@ -25,6 +25,7 @@
 import com.google.devtools.build.lib.analysis.RunfilesProvider;
 import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndTarget;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -117,9 +118,11 @@
 
   @Test
   public void testTestExecutableRunfiles() throws Exception {
-    ConfiguredTarget androidInstrumentationTest = getConfiguredTarget("//javatests/com/app/ait");
+    ConfiguredTargetAndTarget androidInstrumentationTest =
+        getConfiguredTargetAndTarget("//javatests/com/app/ait");
     NestedSet<Artifact> runfiles =
         androidInstrumentationTest
+            .getConfiguredTarget()
             .getProvider(RunfilesProvider.class)
             .getDefaultRunfiles()
             .getAllArtifacts();
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java
index 8466857..4d7c3fc 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java
@@ -35,6 +35,7 @@
 import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
 import com.google.devtools.build.lib.packages.ImplicitOutputsFunction;
 import com.google.devtools.build.lib.packages.util.MockCcSupport;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndTarget;
 import com.google.devtools.build.lib.testutil.TestConstants;
 import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
 import com.google.devtools.build.lib.util.FileType;
@@ -1126,14 +1127,15 @@
   public void addOnlyStaticLibraryToFilesToBuildWhenWrappingIffImplicitOutput() throws Exception {
     // This shared library has the same name as the archive generated by this rule, so it should
     // override said archive. However, said archive should still be put in files to build.
-    ConfiguredTarget target =
-        scratchConfiguredTarget("a", "b", "cc_library(name = 'b', srcs = ['libb.so'])");
+    ConfiguredTargetAndTarget target =
+        scratchConfiguredTargetAndTarget("a", "b", "cc_library(name = 'b', srcs = ['libb.so'])");
 
     if (target.getTarget().getAssociatedRule().getImplicitOutputsFunction()
         != ImplicitOutputsFunction.NONE) {
-      assertThat(artifactsToStrings(getFilesToBuild(target))).containsExactly("bin a/libb.a");
+      assertThat(artifactsToStrings(getFilesToBuild(target.getConfiguredTarget())))
+          .containsExactly("bin a/libb.a");
     } else {
-      assertThat(artifactsToStrings(getFilesToBuild(target))).isEmpty();
+      assertThat(artifactsToStrings(getFilesToBuild(target.getConfiguredTarget()))).isEmpty();
     }
   }
 
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/util/SkyframeExecutorTestUtils.java b/src/test/java/com/google/devtools/build/lib/skyframe/util/SkyframeExecutorTestUtils.java
index 9f8e1d0..7b575ac 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/util/SkyframeExecutorTestUtils.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/util/SkyframeExecutorTestUtils.java
@@ -111,11 +111,12 @@
    */
   public static Iterable<ConfiguredTarget> getExistingConfiguredTargets(
       SkyframeExecutor skyframeExecutor, final Label label) {
-    return Iterables.filter(getAllExistingConfiguredTargets(skyframeExecutor),
+    return Iterables.filter(
+        getAllExistingConfiguredTargets(skyframeExecutor),
         new Predicate<ConfiguredTarget>() {
           @Override
           public boolean apply(ConfiguredTarget input) {
-            return input.getTarget().getLabel().equals(label);
+            return input.getLabel().equals(label);
           }
         });
   }
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java
index 40500e6..6f8e384 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java
@@ -39,6 +39,7 @@
 import com.google.devtools.build.lib.packages.Provider;
 import com.google.devtools.build.lib.packages.SkylarkProvider;
 import com.google.devtools.build.lib.packages.SkylarkProvider.SkylarkKey;
+import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndTarget;
 import com.google.devtools.build.lib.skyframe.PackageFunction;
 import com.google.devtools.build.lib.skyframe.SkyFunctions;
 import com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction;
@@ -107,7 +108,7 @@
   }
 
   private AttributeContainer getContainerForTarget(String targetName) throws Exception {
-    ConfiguredTarget target = getConfiguredTarget("//test/skylark:" + targetName);
+    ConfiguredTargetAndTarget target = getConfiguredTargetAndTarget("//test/skylark:" + targetName);
     return target.getTarget().getAssociatedRule().getAttributeContainer();
   }
 
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java
index bc6a903..61dd892 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java
@@ -20,6 +20,7 @@
 import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
 import static org.junit.Assert.fail;
 
+import com.google.common.base.Splitter;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import com.google.devtools.build.lib.actions.ActionAnalysisMetadata;
@@ -1401,7 +1402,7 @@
     invalidatePackages(/*alsoConfigs=*/false); // Repository shuffling messes with toolchain labels.
     assertThat(
             (List<Label>)
-                getConfiguredTarget("@foo//:baz")
+                getConfiguredTargetAndTarget("@foo//:baz")
                     .getTarget()
                     .getAssociatedRule()
                     .getAttributeContainer()
@@ -2035,10 +2036,11 @@
       } catch (AssertionError e) {
         assertThat(e)
             .hasMessageThat()
-            .contains("cannot access field or method '"
-                + attribute.split("\\(")[0]
-                + "' of rule context for '//test:dep' outside of its own rule implementation "
-                + "function");
+            .contains(
+                "cannot access field or method '"
+                    + Iterables.get(Splitter.on('(').split(attribute), 0)
+                    + "' of rule context for '//test:dep' outside of its own rule implementation "
+                    + "function");
       }
     }
   }
@@ -2083,10 +2085,11 @@
       } catch (AssertionError e) {
         assertThat(e)
             .hasMessageThat()
-            .contains("cannot access field or method '"
-                + attribute.split("\\(")[0]
-                + "' of rule context for '//test:dep' outside of its own rule implementation "
-                + "function");
+            .contains(
+                "cannot access field or method '"
+                    + Iterables.get(Splitter.on('(').split(attribute), 0)
+                    + "' of rule context for '//test:dep' outside of its own rule implementation "
+                    + "function");
       }
     }
   }