Automated rollback of commit 771cb7a026f2c9034fb016966dfd0e154c48ff2e.

*** Reason for rollback ***

Breaks bazel-skylib

See https://github.com/bazelbuild/bazel/issues/8227 for details.

*** Original change description ***

Make target pattern parsing repository-renaming aware.

Platform and toolchain resolution rely on the target pattern parsing code to turn target pattern strings into Labels. Since most of the target pattern parsing codepaths turn target patterns that originated from the command line, they don't need to pass along the repository renaming map. But instances that affect platform and toolchain target patterns, we need to pass the map.

This allows us to turn on the --incompatible_remap_main_repo flag on by default in Bazel.

Closes #7902.
Fixes #7755, #7773, #7654.

RELNOTES: None
PiperOrigin-RevId: 246546091
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/TargetPattern.java b/src/main/java/com/google/devtools/build/lib/cmdline/TargetPattern.java
index 53d8354..be65076 100644
--- a/src/main/java/com/google/devtools/build/lib/cmdline/TargetPattern.java
+++ b/src/main/java/com/google/devtools/build/lib/cmdline/TargetPattern.java
@@ -144,15 +144,14 @@
   }
 
   /**
-   * Evaluates the current target pattern, excluding targets under directories in both {@code
-   * blacklistedSubdirectories} and {@code excludedSubdirectories}, and returns the result.
+   * Evaluates the current target pattern, excluding targets under directories in both
+   * {@code blacklistedSubdirectories} and {@code excludedSubdirectories}, and returns the result.
    *
-   * @throws IllegalArgumentException if either {@code blacklistedSubdirectories} or {@code
-   *     excludedSubdirectories} is nonempty and this pattern does not have type {@code
-   *     Type.TARGETS_BELOW_DIRECTORY}.
+   * @throws IllegalArgumentException if either {@code blacklistedSubdirectories} or
+   *      {@code excludedSubdirectories} is nonempty and this pattern does not have type
+   *      {@code Type.TARGETS_BELOW_DIRECTORY}.
    */
   public abstract <T, E extends Exception> void eval(
-      ImmutableMap<RepositoryName, RepositoryName> repositoryMapping,
       TargetPatternResolver<T> resolver,
       ImmutableSet<PathFragment> blacklistedSubdirectories,
       ImmutableSet<PathFragment> excludedSubdirectories,
@@ -161,28 +160,21 @@
       throws TargetParsingException, E, InterruptedException;
 
   /**
-   * Evaluates this {@link TargetPattern} synchronously, feeding the result to the given {@code
-   * callback}, and then returns an appropriate immediate {@link ListenableFuture}.
+   * Evaluates this {@link TargetPattern} synchronously, feeding the result to the given
+   * {@code callback}, and then returns an appropriate immediate {@link ListenableFuture}.
    *
-   * <p>If the returned {@link ListenableFuture}'s {@link ListenableFuture#get} throws an {@link
-   * ExecutionException}, the cause will be an instance of either {@link TargetParsingException} or
-   * the given {@code exceptionClass}.
+   * <p>If the returned {@link ListenableFuture}'s {@link ListenableFuture#get} throws an
+   * {@link ExecutionException}, the cause will be an instance of either
+   * {@link TargetParsingException} or the given {@code exceptionClass}.
    */
   public final <T, E extends Exception> ListenableFuture<Void> evalAdaptedForAsync(
-      ImmutableMap<RepositoryName, RepositoryName> repositoryMapping,
       TargetPatternResolver<T> resolver,
       ImmutableSet<PathFragment> blacklistedSubdirectories,
       ImmutableSet<PathFragment> excludedSubdirectories,
       ThreadSafeBatchCallback<T, E> callback,
       Class<E> exceptionClass) {
     try {
-      eval(
-          repositoryMapping,
-          resolver,
-          blacklistedSubdirectories,
-          excludedSubdirectories,
-          callback,
-          exceptionClass);
+      eval(resolver, blacklistedSubdirectories, excludedSubdirectories, callback, exceptionClass);
       return Futures.immediateFuture(null);
     } catch (TargetParsingException e) {
       return Futures.immediateFailedFuture(e);
@@ -197,15 +189,14 @@
   }
 
   /**
-   * Returns a {@link ListenableFuture} representing the asynchronous evaluation of this {@link
-   * TargetPattern} that feeds the results to the given {@code callback}.
+   * Returns a {@link ListenableFuture} representing the asynchronous evaluation of this
+   * {@link TargetPattern} that feeds the results to the given {@code callback}.
    *
-   * <p>If the returned {@link ListenableFuture}'s {@link ListenableFuture#get} throws an {@link
-   * ExecutionException}, the cause will be an instance of either {@link TargetParsingException} or
-   * the given {@code exceptionClass}.
+   * <p>If the returned {@link ListenableFuture}'s {@link ListenableFuture#get} throws an
+   * {@link ExecutionException}, the cause will be an instance of either
+   * {@link TargetParsingException} or the given {@code exceptionClass}.
    */
   public <T, E extends Exception> ListenableFuture<Void> evalAsync(
-      ImmutableMap<RepositoryName, RepositoryName> repositoryMapping,
       TargetPatternResolver<T> resolver,
       ImmutableSet<PathFragment> blacklistedSubdirectories,
       ImmutableSet<PathFragment> excludedSubdirectories,
@@ -213,12 +204,7 @@
       Class<E> exceptionClass,
       ListeningExecutorService executor) {
     return evalAdaptedForAsync(
-        repositoryMapping,
-        resolver,
-        blacklistedSubdirectories,
-        excludedSubdirectories,
-        callback,
-        exceptionClass);
+        resolver, blacklistedSubdirectories, excludedSubdirectories, callback, exceptionClass);
   }
 
   /**
@@ -290,8 +276,8 @@
   /**
    * For patterns of type {@link Type#PATH_AS_TARGET}, returns the path in question.
    *
-   * <p>The interpretation of this path, of course, depends on the existence of packages. See {@link
-   * TargetPattern#eval}.
+   * <p>The interpretation of this path, of course, depends on the existence of packages.
+   * See {@link InterpretPathAsTarget#eval}.
    */
   public String getPathForPathAsTarget() {
     throw new IllegalStateException();
@@ -332,15 +318,12 @@
 
     @Override
     public <T, E extends Exception> void eval(
-        ImmutableMap<RepositoryName, RepositoryName> repositoryMapping,
         TargetPatternResolver<T> resolver,
         ImmutableSet<PathFragment> blacklistedSubdirectories,
         ImmutableSet<PathFragment> excludedSubdirectories,
         BatchCallback<T, E> callback,
-        Class<E> exceptionClass)
-        throws TargetParsingException, E, InterruptedException {
-      callback.process(
-          resolver.getExplicitTarget(label(targetName, repositoryMapping)).getTargets());
+        Class<E> exceptionClass) throws TargetParsingException, E, InterruptedException {
+      callback.process(resolver.getExplicitTarget(label(targetName)).getTargets());
     }
 
     @Override
@@ -392,17 +375,14 @@
 
     @Override
     public <T, E extends Exception> void eval(
-        ImmutableMap<RepositoryName, RepositoryName> repositoryMapping,
         TargetPatternResolver<T> resolver,
         ImmutableSet<PathFragment> blacklistedSubdirectories,
         ImmutableSet<PathFragment> excludedSubdirectories,
-        BatchCallback<T, E> callback,
-        Class<E> exceptionClass)
+        BatchCallback<T, E> callback, Class<E> exceptionClass)
         throws TargetParsingException, E, InterruptedException {
       if (resolver.isPackage(PackageIdentifier.createInMainRepo(path))) {
         // User has specified a package name. lookout for default target.
-        callback.process(
-            resolver.getExplicitTarget(label("//" + path, repositoryMapping)).getTargets());
+        callback.process(resolver.getExplicitTarget(label("//" + path)).getTargets());
       } else {
 
         List<String> pieces = SLASH_SPLITTER.splitToList(path);
@@ -415,8 +395,7 @@
             String targetName = SLASH_JOINER.join(pieces.subList(i, pieces.size()));
             callback.process(
                 resolver
-                    .getExplicitTarget(
-                        label("//" + packageName + ":" + targetName, repositoryMapping))
+                    .getExplicitTarget(label("//" + packageName + ":" + targetName))
                     .getTargets());
             return;
           }
@@ -481,12 +460,10 @@
 
     @Override
     public <T, E extends Exception> void eval(
-        ImmutableMap<RepositoryName, RepositoryName> repositoryMapping,
         TargetPatternResolver<T> resolver,
         ImmutableSet<PathFragment> blacklistedSubdirectories,
         ImmutableSet<PathFragment> excludedSubdirectories,
-        BatchCallback<T, E> callback,
-        Class<E> exceptionClass)
+        BatchCallback<T, E> callback, Class<E> exceptionClass)
         throws TargetParsingException, E, InterruptedException {
       if (checkWildcardConflict) {
         ResolvedTargets<T> targets = getWildcardConflict(resolver);
@@ -592,7 +569,6 @@
 
     @Override
     public <T, E extends Exception> void eval(
-        ImmutableMap<RepositoryName, RepositoryName> repositoryMapping,
         TargetPatternResolver<T> resolver,
         ImmutableSet<PathFragment> blacklistedSubdirectories,
         ImmutableSet<PathFragment> excludedSubdirectories,
@@ -612,7 +588,6 @@
 
     @Override
     public <T, E extends Exception> ListenableFuture<Void> evalAsync(
-        ImmutableMap<RepositoryName, RepositoryName> repositoryMapping,
         TargetPatternResolver<T> resolver,
         ImmutableSet<PathFragment> blacklistedSubdirectories,
         ImmutableSet<PathFragment> excludedSubdirectories,
@@ -907,11 +882,9 @@
 
   // Parse 'label' as a Label, mapping LabelSyntaxException into
   // TargetParsingException.
-  private static Label label(
-      String label, ImmutableMap<RepositoryName, RepositoryName> repositoryMapping)
-      throws TargetParsingException {
+  private static Label label(String label) throws TargetParsingException {
     try {
-      return Label.parseAbsolute(label, repositoryMapping);
+      return Label.parseAbsolute(label, ImmutableMap.of());
     } catch (LabelSyntaxException e) {
       throw new TargetParsingException("invalid target format: '"
           + StringUtilities.sanitizeControlChars(label) + "'; "