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/analysis/ResolvedToolchainContext.java b/src/main/java/com/google/devtools/build/lib/analysis/ResolvedToolchainContext.java
index 182328b..9a19b10 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/ResolvedToolchainContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/ResolvedToolchainContext.java
@@ -1,4 +1,4 @@
-// Copyright 2019 The Bazel Authors. All rights reserved.
+// Copyright 2017 The Bazel Authors. All rights reserved.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
 import static java.util.stream.Collectors.joining;
 
 import com.google.auto.value.AutoValue;
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
@@ -25,7 +24,6 @@
 import com.google.devtools.build.lib.analysis.platform.PlatformProviderUtils;
 import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
 import com.google.devtools.build.lib.analysis.platform.ToolchainTypeInfo;
-import com.google.devtools.build.lib.analysis.skylark.BazelStarlarkContext;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
@@ -187,8 +185,7 @@
     printer.append(">");
   }
 
-  private Label transformKey(Object key, Location loc, BazelStarlarkContext context)
-      throws EvalException {
+  private Label transformKey(Object key, Location loc) throws EvalException {
     if (key instanceof Label) {
       return (Label) key;
     } else if (key instanceof ToolchainTypeInfo) {
@@ -197,7 +194,7 @@
       Label toolchainType;
       String rawLabel = (String) key;
       try {
-        toolchainType = Label.parseAbsolute(rawLabel, context.getRepoMapping());
+        toolchainType = Label.parseAbsolute(rawLabel, ImmutableMap.of());
       } catch (LabelSyntaxException e) {
         throw new EvalException(
             loc, String.format("Unable to parse toolchain %s: %s", rawLabel, e.getMessage()), e);
@@ -215,8 +212,7 @@
   @Override
   public ToolchainInfo getIndex(Object key, Location loc, StarlarkContext context)
       throws EvalException {
-    Preconditions.checkArgument(context instanceof BazelStarlarkContext);
-    Label toolchainTypeLabel = transformKey(key, loc, (BazelStarlarkContext) context);
+    Label toolchainTypeLabel = transformKey(key, loc);
 
     if (!containsKey(key, loc, context)) {
       throw new EvalException(
@@ -236,8 +232,7 @@
   @Override
   public boolean containsKey(Object key, Location loc, StarlarkContext context)
       throws EvalException {
-    Preconditions.checkArgument(context instanceof BazelStarlarkContext);
-    Label toolchainTypeLabel = transformKey(key, loc, (BazelStarlarkContext) context);
+    Label toolchainTypeLabel = transformKey(key, loc);
     Optional<Label> matching =
         toolchains().keySet().stream()
             .map(ToolchainTypeInfo::typeLabel)
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java
index 5372e4f..d465c70 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java
@@ -43,7 +43,6 @@
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
 import com.google.devtools.build.lib.cmdline.LabelValidator;
-import com.google.devtools.build.lib.cmdline.RepositoryName;
 import com.google.devtools.build.lib.events.Location;
 import com.google.devtools.build.lib.packages.Attribute;
 import com.google.devtools.build.lib.packages.AttributeMap;
@@ -290,7 +289,6 @@
       throws EvalException {
     SkylarkUtils.checkLoadingOrWorkspacePhase(funcallEnv, "rule", ast.getLocation());
 
-    Preconditions.checkArgument(context instanceof BazelStarlarkContext);
     BazelStarlarkContext bazelContext = (BazelStarlarkContext) context;
     // analysis_test=true implies test=true.
     test |= Boolean.TRUE.equals(analysisTest);
@@ -357,9 +355,7 @@
         funcallEnv.getGlobals().getLabel(), funcallEnv.getTransitiveContentHashCode());
     builder.addRequiredToolchains(
         collectToolchainLabels(
-            toolchains.getContents(String.class, "toolchains"),
-            bazelContext.getRepoMapping(),
-            ast.getLocation()));
+            toolchains.getContents(String.class, "toolchains"), ast.getLocation()));
 
     if (!buildSetting.equals(Runtime.NONE) && !cfg.equals(Runtime.NONE)) {
       throw new EvalException(
@@ -400,7 +396,6 @@
       builder.addExecutionPlatformConstraints(
           collectConstraintLabels(
               execCompatibleWith.getContents(String.class, "exec_compatile_with"),
-              bazelContext.getRepoMapping(),
               ast.getLocation()));
     }
 
@@ -439,14 +434,11 @@
   }
 
   private static ImmutableList<Label> collectToolchainLabels(
-      Iterable<String> rawLabels,
-      ImmutableMap<RepositoryName, RepositoryName> repoMapping,
-      Location loc)
-      throws EvalException {
+      Iterable<String> rawLabels, Location loc) throws EvalException {
     ImmutableList.Builder<Label> requiredToolchains = new ImmutableList.Builder<>();
     for (String rawLabel : rawLabels) {
       try {
-        Label toolchainLabel = Label.parseAbsolute(rawLabel, repoMapping);
+        Label toolchainLabel = Label.parseAbsolute(rawLabel, ImmutableMap.of());
         requiredToolchains.add(toolchainLabel);
       } catch (LabelSyntaxException e) {
         throw new EvalException(
@@ -458,14 +450,11 @@
   }
 
   private static ImmutableList<Label> collectConstraintLabels(
-      Iterable<String> rawLabels,
-      ImmutableMap<RepositoryName, RepositoryName> repoMapping,
-      Location loc)
-      throws EvalException {
+      Iterable<String> rawLabels, Location loc) throws EvalException {
     ImmutableList.Builder<Label> constraintLabels = new ImmutableList.Builder<>();
     for (String rawLabel : rawLabels) {
       try {
-        Label constraintLabel = Label.parseAbsolute(rawLabel, repoMapping);
+        Label constraintLabel = Label.parseAbsolute(rawLabel, ImmutableMap.of());
         constraintLabels.add(constraintLabel);
       } catch (LabelSyntaxException e) {
         throw new EvalException(
@@ -488,10 +477,8 @@
       SkylarkList<?> toolchains,
       String doc,
       FuncallExpression ast,
-      Environment funcallEnv,
-      StarlarkContext context)
+      Environment funcallEnv)
       throws EvalException {
-    Preconditions.checkArgument(context instanceof BazelStarlarkContext);
     Location location = ast.getLocation();
     ImmutableList.Builder<String> attrAspects = ImmutableList.builder();
     for (Object attributeAspect : attributeAspects) {
@@ -579,9 +566,7 @@
         HostTransition.INSTANCE,
         ImmutableSet.copyOf(hostFragments.getContents(String.class, "host_fragments")),
         collectToolchainLabels(
-            toolchains.getContents(String.class, "toolchains"),
-            ((BazelStarlarkContext) context).getRepoMapping(),
-            ast.getLocation()));
+            toolchains.getContents(String.class, "toolchains"), ast.getLocation()));
   }
 
   /**
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) + "'; "
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Package.java b/src/main/java/com/google/devtools/build/lib/packages/Package.java
index 8663a60..11b0fa4 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Package.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Package.java
@@ -17,7 +17,6 @@
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableListMultimap;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSortedSet;
@@ -216,8 +215,8 @@
   private ImmutableList<Event> events;
   private ImmutableList<Postable> posts;
 
-  private ImmutableListMultimap<RepositoryName, String> registeredExecutionPlatforms;
-  private ImmutableListMultimap<RepositoryName, String> registeredToolchains;
+  private ImmutableList<String> registeredExecutionPlatforms;
+  private ImmutableList<String> registeredToolchains;
 
   /**
    * Package initialization, part 1 of 3: instantiates a new package with the
@@ -405,8 +404,8 @@
     this.features = ImmutableSortedSet.copyOf(builder.features);
     this.events = ImmutableList.copyOf(builder.events);
     this.posts = ImmutableList.copyOf(builder.posts);
-    this.registeredExecutionPlatforms = builder.registeredExecutionPlatforms.build();
-    this.registeredToolchains = builder.registeredToolchains.build();
+    this.registeredExecutionPlatforms = ImmutableList.copyOf(builder.registeredExecutionPlatforms);
+    this.registeredToolchains = ImmutableList.copyOf(builder.registeredToolchains);
     this.repositoryMapping = Preconditions.checkNotNull(builder.repositoryMapping);
     ImmutableMap.Builder<RepositoryName, ImmutableMap<RepositoryName, RepositoryName>>
         repositoryMappingsBuilder = ImmutableMap.builder();
@@ -698,11 +697,11 @@
     return defaultRestrictedTo;
   }
 
-  public ImmutableListMultimap<RepositoryName, String> getRegisteredExecutionPlatforms() {
+  public ImmutableList<String> getRegisteredExecutionPlatforms() {
     return registeredExecutionPlatforms;
   }
 
-  public ImmutableListMultimap<RepositoryName, String> getRegisteredToolchains() {
+  public ImmutableList<String> getRegisteredToolchains() {
     return registeredToolchains;
   }
 
@@ -836,10 +835,8 @@
 
     private ImmutableList<Label> skylarkFileDependencies = ImmutableList.of();
 
-    private final ImmutableListMultimap.Builder<RepositoryName, String>
-        registeredExecutionPlatforms = ImmutableListMultimap.builder();
-    private final ImmutableListMultimap.Builder<RepositoryName, String> registeredToolchains =
-        ImmutableListMultimap.builder();
+    private final List<String> registeredExecutionPlatforms = new ArrayList<>();
+    private final List<String> registeredToolchains = new ArrayList<>();
 
     private ThirdPartyLicenseExistencePolicy thirdPartyLicenceExistencePolicy =
         ThirdPartyLicenseExistencePolicy.USER_CONTROLLABLE;
@@ -1404,21 +1401,12 @@
       addRuleUnchecked(rule);
     }
 
-    void addRegisteredToolchains(RepositoryName repositoryName, List<String> toolchains) {
-      this.registeredToolchains.putAll(repositoryName, toolchains);
+    void addRegisteredExecutionPlatforms(List<String> platforms) {
+      this.registeredExecutionPlatforms.addAll(platforms);
     }
 
-    void addRegisteredToolchains(ImmutableListMultimap<RepositoryName, String> toolchains) {
-      this.registeredToolchains.putAll(toolchains);
-    }
-
-    void addRegisteredExecutionPlatforms(RepositoryName repositoryName, List<String> platforms) {
-      this.registeredExecutionPlatforms.putAll(repositoryName, platforms);
-    }
-
-    void addRegisteredExecutionPlatforms(
-        ImmutableListMultimap<RepositoryName, String> executionPlatforms) {
-      this.registeredExecutionPlatforms.putAll(executionPlatforms);
+    void addRegisteredToolchains(List<String> toolchains) {
+      this.registeredToolchains.addAll(toolchains);
     }
 
     private Builder beforeBuild(boolean discoverAssumedInputFiles) throws NoSuchPackageException {
diff --git a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java
index 2cea873..409fbb9 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java
@@ -191,7 +191,7 @@
                 new BazelStarlarkContext(
                     /* toolsRepository= */ null,
                     /* fragmentNameToClass= */ null,
-                    /* repoMapping= */ ImmutableMap.of(),
+                    ImmutableMap.of(),
                     new SymbolGenerator<>(workspaceFileKey)))
             .build();
     SkylarkUtils.setPhase(workspaceEnv, Phase.WORKSPACE);
diff --git a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceGlobals.java b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceGlobals.java
index fb37437..f4e02f3 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceGlobals.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceGlobals.java
@@ -201,9 +201,8 @@
       throws EvalException, InterruptedException {
     // Add to the package definition for later.
     Package.Builder builder = PackageFactory.getContext(env, location).pkgBuilder;
-    RepositoryName repositoryName = getRepositoryName(env.getGlobals().getLabel());
     builder.addRegisteredExecutionPlatforms(
-        repositoryName, platformLabels.getContents(String.class, "platform_labels"));
+        platformLabels.getContents(String.class, "platform_labels"));
 
     return NONE;
   }
@@ -214,25 +213,11 @@
       throws EvalException, InterruptedException {
     // Add to the package definition for later.
     Package.Builder builder = PackageFactory.getContext(env, location).pkgBuilder;
-    RepositoryName repositoryName = getRepositoryName(env.getGlobals().getLabel());
-    builder.addRegisteredToolchains(
-        repositoryName, toolchainLabels.getContents(String.class, "toolchain_labels"));
+    builder.addRegisteredToolchains(toolchainLabels.getContents(String.class, "toolchain_labels"));
 
     return NONE;
   }
 
-  private RepositoryName getRepositoryName(Label bzlLabel) {
-    RepositoryName repositoryName;
-    if (bzlLabel == null) {
-      // registration happened directly in the main WORKSPACE
-      repositoryName = RepositoryName.MAIN;
-    } else {
-      // registeration happened in a loaded bzl file
-      repositoryName = bzlLabel.getPackageIdentifier().getRepository();
-    }
-    return repositoryName;
-  }
-
   @Override
   public NoneType bind(String name, Object actual, FuncallExpression ast, Environment env)
       throws EvalException, InterruptedException {
diff --git a/src/main/java/com/google/devtools/build/lib/query2/ActionGraphQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/ActionGraphQueryEnvironment.java
index 4163538..593157b 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/ActionGraphQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/ActionGraphQueryEnvironment.java
@@ -14,7 +14,6 @@
 package com.google.devtools.build.lib.query2;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.util.concurrent.AsyncFunction;
 import com.google.common.util.concurrent.Futures;
@@ -273,7 +272,7 @@
       QueryExpression owner, String pattern, Callback<ConfiguredTargetValue> callback) {
     TargetPattern patternToEval;
     try {
-      patternToEval = getPatternKey(pattern);
+      patternToEval = getPattern(pattern);
     } catch (TargetParsingException tpe) {
       try {
         reportBuildFileError(owner, tpe.getMessage());
@@ -292,7 +291,6 @@
       return QueryTaskFutureImpl.ofDelegate(
           Futures.catchingAsync(
               patternToEval.evalAdaptedForAsync(
-                  /* repositoryMapping= */ ImmutableMap.of(),
                   resolver,
                   getBlacklistedPackagePrefixesPathFragments(),
                   /* excludedSubdirectories= */ ImmutableSet.of(),
diff --git a/src/main/java/com/google/devtools/build/lib/query2/ConfiguredTargetQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/ConfiguredTargetQueryEnvironment.java
index a6f84db..fcbc15f0 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/ConfiguredTargetQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/ConfiguredTargetQueryEnvironment.java
@@ -14,7 +14,6 @@
 package com.google.devtools.build.lib.query2;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.util.concurrent.AsyncFunction;
 import com.google.common.util.concurrent.Futures;
@@ -213,7 +212,7 @@
       QueryExpression owner, String pattern, Callback<ConfiguredTarget> callback) {
     TargetPattern patternToEval;
     try {
-      patternToEval = getPatternKey(pattern);
+      patternToEval = getPattern(pattern);
     } catch (TargetParsingException tpe) {
       try {
         reportBuildFileError(owner, tpe.getMessage());
@@ -232,7 +231,6 @@
       return QueryTaskFutureImpl.ofDelegate(
           Futures.catchingAsync(
               patternToEval.evalAdaptedForAsync(
-                  /* repositoryMapping = */ ImmutableMap.of(),
                   resolver,
                   getBlacklistedPackagePrefixesPathFragments(),
                   /* excludedSubdirectories= */ ImmutableSet.of(),
diff --git a/src/main/java/com/google/devtools/build/lib/query2/PostAnalysisQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/PostAnalysisQueryEnvironment.java
index aaab632..edefd40 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/PostAnalysisQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/PostAnalysisQueryEnvironment.java
@@ -27,7 +27,6 @@
 import com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory;
 import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
 import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.cmdline.RepositoryName;
 import com.google.devtools.build.lib.cmdline.TargetParsingException;
 import com.google.devtools.build.lib.cmdline.TargetPattern;
 import com.google.devtools.build.lib.collect.compacthashset.CompactHashSet;
@@ -115,12 +114,7 @@
     ALL_PATTERNS =
         ImmutableList.of(
             new TargetPatternKey(
-                targetPattern,
-                FilteringPolicies.NO_FILTER,
-                false,
-                "",
-                ImmutableSet.of(),
-                RepositoryName.MAIN));
+                targetPattern, FilteringPolicies.NO_FILTER, false, "", ImmutableSet.of()));
   }
 
   protected RecursivePackageProviderBackedTargetPatternResolver resolver;
@@ -245,7 +239,7 @@
   @Nullable
   protected abstract T getValueFromKey(SkyKey key) throws InterruptedException;
 
-  protected TargetPattern getPatternKey(String pattern) throws TargetParsingException {
+  protected TargetPattern getPattern(String pattern) throws TargetParsingException {
     TargetPatternKey targetPatternKey =
         ((TargetPatternKey)
             TargetPatternValue.key(
diff --git a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
index 3aee5dc..5c168958 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
@@ -741,7 +741,6 @@
     }
     ListenableFuture<Void> evalFuture =
         patternToEval.evalAsync(
-            /* repositoryMapping= */ ImmutableMap.of(),
             resolver,
             blacklistedSubdirectoriesToExclude,
             additionalSubdirectoriesToExclude,
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternFunction.java
index 3bbc298..6112c72 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternFunction.java
@@ -99,16 +99,8 @@
     DepsOfPatternPreparer preparer =
         new DepsOfPatternPreparer(env, pkgPath.get(), traverseTestSuites);
 
-    RepositoryMappingValue repositoryMappingValue =
-        (RepositoryMappingValue)
-            env.getValue(RepositoryMappingValue.key(patternKey.getRepositoryName()));
-    if (repositoryMappingValue == null) {
-      return null;
-    }
-
     try {
       parsedPattern.eval(
-          repositoryMappingValue.getRepositoryMapping(),
           preparer,
           blacklistedSubdirectories,
           excludedSubdirectories,
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternValue.java
index d891af2..bfbb45d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternValue.java
@@ -14,9 +14,7 @@
 package com.google.devtools.build.lib.skyframe;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableListMultimap;
 import com.google.common.collect.Interner;
-import com.google.devtools.build.lib.cmdline.RepositoryName;
 import com.google.devtools.build.lib.cmdline.TargetParsingException;
 import com.google.devtools.build.lib.cmdline.TargetPattern;
 import com.google.devtools.build.lib.cmdline.TargetPattern.Type;
@@ -93,12 +91,8 @@
         ImmutableList.builder();
     ImmutableList.Builder<PrepareDepsOfPatternSkyKeyException> resultExceptionsBuilder =
         ImmutableList.builder();
-    ImmutableListMultimap.Builder<RepositoryName, String> builder = ImmutableListMultimap.builder();
-    builder.putAll(RepositoryName.MAIN, patterns);
-    ImmutableListMultimap<RepositoryName, String> patternsMap = builder.build();
-
     Iterable<TargetPatternSkyKeyOrException> keysMaybe =
-        TargetPatternValue.keys(patternsMap, FilteringPolicies.NO_FILTER, offset);
+        TargetPatternValue.keys(patterns, FilteringPolicies.NO_FILTER, offset);
     ImmutableList.Builder<TargetPatternKey> targetPatternKeysBuilder = ImmutableList.builder();
     for (TargetPatternSkyKeyOrException keyMaybe : keysMaybe) {
       try {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
index 3e2fed6..255fe0e 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
@@ -21,7 +21,6 @@
 import com.google.auto.value.AutoValue;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableListMultimap;
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.PlatformConfiguration;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
@@ -29,7 +28,6 @@
 import com.google.devtools.build.lib.analysis.platform.PlatformProviderUtils;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.cmdline.LabelConstants;
-import com.google.devtools.build.lib.cmdline.RepositoryName;
 import com.google.devtools.build.lib.cmdline.TargetParsingException;
 import com.google.devtools.build.lib.packages.Package;
 import com.google.devtools.build.lib.packages.RuleClass;
@@ -64,19 +62,22 @@
     }
     BuildConfiguration configuration = buildConfigurationValue.getConfiguration();
 
+    ImmutableList.Builder<String> targetPatternBuilder = new ImmutableList.Builder<>();
+
     // Get the execution platforms from the configuration.
     PlatformConfiguration platformConfiguration =
         configuration.getFragment(PlatformConfiguration.class);
+    if (platformConfiguration != null) {
+      targetPatternBuilder.addAll(platformConfiguration.getExtraExecutionPlatforms());
+    }
 
     // Get the registered execution platforms from the WORKSPACE.
-    ImmutableListMultimap<RepositoryName, String> workspaceExecutionPlatforms =
-        getWorkspaceExecutionPlatforms(env);
+    List<String> workspaceExecutionPlatforms = getWorkspaceExecutionPlatforms(env);
     if (workspaceExecutionPlatforms == null) {
       return null;
     }
-
-    ImmutableListMultimap<RepositoryName, String> targetPatterns =
-        mergeExecutionPlatforms(workspaceExecutionPlatforms, platformConfiguration);
+    targetPatternBuilder.addAll(workspaceExecutionPlatforms);
+    ImmutableList<String> targetPatterns = targetPatternBuilder.build();
 
     // Expand target patterns.
     ImmutableList<Label> platformLabels;
@@ -109,8 +110,8 @@
    */
   @Nullable
   @VisibleForTesting
-  public static ImmutableListMultimap<RepositoryName, String> getWorkspaceExecutionPlatforms(
-      Environment env) throws InterruptedException {
+  public static List<String> getWorkspaceExecutionPlatforms(Environment env)
+      throws InterruptedException {
     PackageValue externalPackageValue =
         (PackageValue) env.getValue(PackageValue.key(LabelConstants.EXTERNAL_PACKAGE_IDENTIFIER));
     if (externalPackageValue == null) {
@@ -121,19 +122,6 @@
     return externalPackage.getRegisteredExecutionPlatforms();
   }
 
-  private ImmutableListMultimap<RepositoryName, String> mergeExecutionPlatforms(
-      ImmutableListMultimap<RepositoryName, String> workspaceExecutionPlatforms,
-      @Nullable PlatformConfiguration platformConfiguration) {
-
-    ImmutableListMultimap.Builder<RepositoryName, String> builder = ImmutableListMultimap.builder();
-    // This ensures that execution platforms specified via a flag are considered first
-    if (platformConfiguration != null) {
-      builder.putAll(RepositoryName.MAIN, platformConfiguration.getExtraExecutionPlatforms());
-    }
-    builder.putAll(workspaceExecutionPlatforms);
-    return builder.build();
-  }
-
   private ImmutableList<ConfiguredTargetKey> configureRegisteredExecutionPlatforms(
       Environment env,
       BuildConfiguration configuration,
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java
index 7aa1169..7d7b054 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java
@@ -18,14 +18,12 @@
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableListMultimap;
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.PlatformConfiguration;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.analysis.platform.DeclaredToolchainInfo;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.cmdline.LabelConstants;
-import com.google.devtools.build.lib.cmdline.RepositoryName;
 import com.google.devtools.build.lib.cmdline.TargetParsingException;
 import com.google.devtools.build.lib.packages.Package;
 import com.google.devtools.build.lib.pkgcache.FilteringPolicies;
@@ -58,18 +56,19 @@
     }
     BuildConfiguration configuration = buildConfigurationValue.getConfiguration();
 
+    ImmutableList.Builder<String> targetPatternBuilder = new ImmutableList.Builder<>();
+
     // Get the toolchains from the configuration.
     PlatformConfiguration platformConfiguration =
         configuration.getFragment(PlatformConfiguration.class);
+    targetPatternBuilder.addAll(platformConfiguration.getExtraToolchains());
 
-    // Get the registered toolchains from the WORKSPACE
-    ImmutableListMultimap<RepositoryName, String> workspaceToolchains = getWorkspaceToolchains(env);
+    // Get the registered toolchains from the WORKSPACE.
+    targetPatternBuilder.addAll(getWorkspaceToolchains(env));
     if (env.valuesMissing()) {
       return null;
     }
-
-    ImmutableListMultimap<RepositoryName, String> targetPatterns =
-        mergeToolchains(workspaceToolchains, platformConfiguration);
+    ImmutableList<String> targetPatterns = targetPatternBuilder.build();
 
     // Expand target patterns.
     ImmutableList<Label> toolchainLabels;
@@ -95,15 +94,23 @@
     return RegisteredToolchainsValue.create(registeredToolchains);
   }
 
+  private Iterable<? extends String> getWorkspaceToolchains(Environment env)
+      throws InterruptedException {
+    List<String> patterns = getRegisteredToolchains(env);
+    if (patterns == null) {
+      return ImmutableList.of();
+    }
+    return patterns;
+  }
+
   /**
-   * Loads the external package and then returns the registered toolchains with repository name.
+   * Loads the external package and then returns the registered toolchains.
    *
    * @param env the environment to use for lookups
    */
   @Nullable
   @VisibleForTesting
-  public static ImmutableListMultimap<RepositoryName, String> getWorkspaceToolchains(
-      Environment env) throws InterruptedException {
+  public static List<String> getRegisteredToolchains(Environment env) throws InterruptedException {
     PackageValue externalPackageValue =
         (PackageValue) env.getValue(PackageValue.key(LabelConstants.EXTERNAL_PACKAGE_IDENTIFIER));
     if (externalPackageValue == null) {
@@ -114,19 +121,6 @@
     return externalPackage.getRegisteredToolchains();
   }
 
-  private ImmutableListMultimap<RepositoryName, String> mergeToolchains(
-      ImmutableListMultimap<RepositoryName, String> workspaceToolchains,
-      @Nullable PlatformConfiguration platformConfiguration) {
-
-    ImmutableListMultimap.Builder<RepositoryName, String> builder = ImmutableListMultimap.builder();
-    // This ensures that toolchains specified via a flag are considered first
-    if (platformConfiguration != null) {
-      builder.putAll(RepositoryName.MAIN, platformConfiguration.getExtraToolchains());
-    }
-    builder.putAll(workspaceToolchains);
-    return builder.build();
-  }
-
   private ImmutableList<DeclaredToolchainInfo> configureRegisteredToolchains(
       Environment env,
       BuildConfiguration configuration,
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeTargetPatternEvaluator.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeTargetPatternEvaluator.java
index 4c177bc..e9849ac 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeTargetPatternEvaluator.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeTargetPatternEvaluator.java
@@ -15,11 +15,9 @@
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableListMultimap;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.cmdline.RepositoryName;
 import com.google.devtools.build.lib.cmdline.ResolvedTargets;
 import com.google.devtools.build.lib.cmdline.TargetParsingException;
 import com.google.devtools.build.lib.events.Event;
@@ -112,14 +110,8 @@
       ImmutableList<String> targetPatterns,
       FilteringPolicy policy,
       boolean keepGoing) throws TargetParsingException {
-
-    ImmutableListMultimap.Builder<RepositoryName, String> patternsBuilder =
-        ImmutableListMultimap.builder();
-    patternsBuilder.putAll(RepositoryName.MAIN, targetPatterns);
-    ImmutableListMultimap<RepositoryName, String> patternsMap = patternsBuilder.build();
-
     Iterable<TargetPatternSkyKeyOrException> keysMaybe =
-        TargetPatternValue.keys(patternsMap, policy, offset);
+        TargetPatternValue.keys(targetPatterns, policy, offset);
     ImmutableList.Builder<TargetPatternKey> builder = ImmutableList.builder();
     for (TargetPatternSkyKeyOrException skyKeyOrException : keysMaybe) {
       try {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternFunction.java
index 25f7033..b195308 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternFunction.java
@@ -74,14 +74,7 @@
               Iterables.addAll(results, partialResult);
             }
           };
-      RepositoryMappingValue repositoryMappingValue =
-          (RepositoryMappingValue)
-              env.getValue(RepositoryMappingValue.key(patternKey.getRepositoryName()));
-      if (repositoryMappingValue == null) {
-        return null;
-      }
       parsedPattern.eval(
-          repositoryMappingValue.getRepositoryMapping(),
           resolver,
           blacklisted.getPatterns(),
           excludedSubdirectories,
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseFunction.java
index 984e142f..969d656a 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseFunction.java
@@ -18,14 +18,12 @@
 import com.google.auto.value.AutoValue;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableListMultimap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSetMultimap;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.cmdline.LabelConstants;
-import com.google.devtools.build.lib.cmdline.RepositoryName;
 import com.google.devtools.build.lib.cmdline.ResolvedTargets;
 import com.google.devtools.build.lib.cmdline.TargetParsingException;
 import com.google.devtools.build.lib.events.Event;
@@ -263,14 +261,9 @@
       Environment env, TargetPatternPhaseKey options, List<String> failedPatterns)
       throws InterruptedException {
     List<TargetPatternKey> patternSkyKeys = new ArrayList<>(options.getTargetPatterns().size());
-
-    ImmutableListMultimap.Builder<RepositoryName, String> builder = ImmutableListMultimap.builder();
-    builder.putAll(RepositoryName.MAIN, options.getTargetPatterns());
-    ImmutableListMultimap<RepositoryName, String> patternsMap = builder.build();
-
     for (TargetPatternSkyKeyOrException keyOrException :
         TargetPatternValue.keys(
-            patternsMap,
+            options.getTargetPatterns(),
             options.getBuildManualTests()
                 ? FilteringPolicies.NO_FILTER
                 : FilteringPolicies.FILTER_MANUAL,
@@ -390,13 +383,8 @@
       Environment env, List<String> targetPatterns, String offset, TestFilter testFilter)
       throws InterruptedException {
     List<TargetPatternKey> patternSkyKeys = new ArrayList<>();
-
-    ImmutableListMultimap.Builder<RepositoryName, String> builder = ImmutableListMultimap.builder();
-    builder.putAll(RepositoryName.MAIN, targetPatterns);
-    ImmutableListMultimap<RepositoryName, String> patternsMap = builder.build();
-
     for (TargetPatternSkyKeyOrException keyOrException :
-        TargetPatternValue.keys(patternsMap, FilteringPolicies.FILTER_TESTS, offset)) {
+        TargetPatternValue.keys(targetPatterns, FilteringPolicies.FILTER_TESTS, offset)) {
       try {
         patternSkyKeys.add(keyOrException.getSkyKey());
       } catch (TargetParsingException e) {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternUtil.java b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternUtil.java
index 67f094a..56602b2 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternUtil.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternUtil.java
@@ -15,10 +15,9 @@
 package com.google.devtools.build.lib.skyframe;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableListMultimap;
 import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.cmdline.RepositoryName;
 import com.google.devtools.build.lib.cmdline.TargetParsingException;
+import com.google.devtools.build.lib.pkgcache.FilteringPolicies;
 import com.google.devtools.build.lib.pkgcache.FilteringPolicy;
 import com.google.devtools.build.skyframe.SkyFunction.Environment;
 import com.google.devtools.build.skyframe.SkyKey;
@@ -34,15 +33,25 @@
 public class TargetPatternUtil {
 
   /**
+   * Expand the given {@code targetPatterns}. This handles the needed underlying Skyframe calls (via
+   * {@code env}), and will return {@code null} to signal a Skyframe restart.
+   */
+  @Nullable
+  public static ImmutableList<Label> expandTargetPatterns(
+      Environment env, List<String> targetPatterns)
+      throws InvalidTargetPatternException, InterruptedException {
+
+    return expandTargetPatterns(env, targetPatterns, FilteringPolicies.NO_FILTER);
+  }
+
+  /**
    * Expand the given {@code targetPatterns}, using the {@code filteringPolicy}. This handles the
    * needed underlying Skyframe calls (via {@code env}), and will return {@code null} to signal a
    * Skyframe restart.
    */
   @Nullable
   public static ImmutableList<Label> expandTargetPatterns(
-      Environment env,
-      ImmutableListMultimap<RepositoryName, String> targetPatterns,
-      FilteringPolicy filteringPolicy)
+      Environment env, List<String> targetPatterns, FilteringPolicy filteringPolicy)
       throws InvalidTargetPatternException, InterruptedException {
 
     // First parse the patterns, and throw any errors immediately.
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternValue.java
index d9cdcee..1aea611 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternValue.java
@@ -15,14 +15,12 @@
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableListMultimap;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
 import com.google.devtools.build.lib.cmdline.PackageIdentifier;
-import com.google.devtools.build.lib.cmdline.RepositoryName;
 import com.google.devtools.build.lib.cmdline.ResolvedTargets;
 import com.google.devtools.build.lib.cmdline.TargetParsingException;
 import com.google.devtools.build.lib.cmdline.TargetPattern;
@@ -116,9 +114,7 @@
   @ThreadSafe
   public static TargetPatternKey key(String pattern, FilteringPolicy policy, String offset)
       throws TargetParsingException {
-    ImmutableListMultimap<RepositoryName, String> patternMap =
-        ImmutableListMultimap.of(RepositoryName.MAIN, pattern);
-    return Iterables.getOnlyElement(keys(patternMap, policy, offset)).getSkyKey();
+    return Iterables.getOnlyElement(keys(ImmutableList.of(pattern), policy, offset)).getSkyKey();
   }
 
   /**
@@ -127,41 +123,34 @@
    * fails to parse, the element in the returned iterable corresponding to it will throw when its
    * {@link TargetPatternSkyKeyOrException#getSkyKey} method is called.
    *
-   * @param patterns A multimap from {@code RepositoryName}s of where the pattern originated ({@code
-   *     "@"}, i.e. main repository if the pattern appeared on the command line), to patterns, eg
-   *     "-foo/biz...". If a pattern's first character is "-", it is treated as a negative pattern.
+   * @param patterns The list of patterns, eg "-foo/biz...". If a pattern's first character is "-",
+   *     it is treated as a negative pattern.
    * @param policy The filtering policy, eg "only return test targets"
    * @param offset The offset to apply to relative target patterns.
    */
   @ThreadSafe
-  public static Iterable<TargetPatternSkyKeyOrException> keys(
-      ImmutableListMultimap<RepositoryName, String> patterns,
-      FilteringPolicy policy,
-      String offset) {
+  public static Iterable<TargetPatternSkyKeyOrException> keys(List<String> patterns,
+      FilteringPolicy policy, String offset) {
     TargetPattern.Parser parser = new TargetPattern.Parser(offset);
     ImmutableList.Builder<TargetPatternSkyKeyOrException> builder = ImmutableList.builder();
-
-    for (RepositoryName repositoryName : patterns.keySet()) {
-      for (String pattern : patterns.get(repositoryName)) {
-        boolean positive = !pattern.startsWith("-");
-        String absoluteValueOfPattern = positive ? pattern : pattern.substring(1);
-        TargetPattern targetPattern;
-        try {
-          targetPattern = parser.parse(absoluteValueOfPattern);
-        } catch (TargetParsingException e) {
-          builder.add(new TargetPatternSkyKeyException(e, absoluteValueOfPattern));
-          continue;
-        }
-        TargetPatternKey targetPatternKey =
-            new TargetPatternKey(
-                targetPattern,
-                positive ? policy : FilteringPolicies.NO_FILTER,
-                /*isNegative=*/ !positive,
-                offset,
-                ImmutableSet.<PathFragment>of(),
-                repositoryName);
-        builder.add(new TargetPatternSkyKeyValue(targetPatternKey));
+    for (String pattern : patterns) {
+      boolean positive = !pattern.startsWith("-");
+      String absoluteValueOfPattern = positive ? pattern : pattern.substring(1);
+      TargetPattern targetPattern;
+      try {
+        targetPattern = parser.parse(absoluteValueOfPattern);
+      } catch (TargetParsingException e) {
+        builder.add(new TargetPatternSkyKeyException(e, absoluteValueOfPattern));
+        continue;
       }
+      TargetPatternKey targetPatternKey =
+          new TargetPatternKey(
+              targetPattern,
+              positive ? policy : FilteringPolicies.NO_FILTER,
+              /*isNegative=*/ !positive,
+              offset,
+              ImmutableSet.<PathFragment>of());
+      builder.add(new TargetPatternSkyKeyValue(targetPatternKey));
     }
     return builder.build();
   }
@@ -207,8 +196,7 @@
         policy,
         original.isNegative(),
         original.getOffset(),
-        excludedSubdirectories,
-        RepositoryName.MAIN);
+        excludedSubdirectories);
   }
 
   private static class TargetPatternKeyWithExclusionsResult {
@@ -299,21 +287,17 @@
     private final String offset;
     private final ImmutableSet<PathFragment> excludedSubdirectories;
 
-    private final RepositoryName repositoryName;
-
     public TargetPatternKey(
         TargetPattern parsedPattern,
         FilteringPolicy policy,
         boolean isNegative,
         String offset,
-        ImmutableSet<PathFragment> excludedSubdirectories,
-        RepositoryName repositoryName) {
+        ImmutableSet<PathFragment> excludedSubdirectories) {
       this.parsedPattern = Preconditions.checkNotNull(parsedPattern);
       this.policy = Preconditions.checkNotNull(policy);
       this.isNegative = isNegative;
       this.offset = offset;
       this.excludedSubdirectories = Preconditions.checkNotNull(excludedSubdirectories);
-      this.repositoryName = Preconditions.checkNotNull(repositoryName);
     }
 
     @Override
@@ -345,10 +329,6 @@
       return excludedSubdirectories;
     }
 
-    public RepositoryName getRepositoryName() {
-      return repositoryName;
-    }
-
     ImmutableSet<PathFragment> getAllSubdirectoriesToExclude(
         Iterable<PathFragment> blacklistedPackagePrefixes) throws InterruptedException {
       ImmutableSet.Builder<PathFragment> excludedPathsBuilder = ImmutableSet.builder();
@@ -395,8 +375,8 @@
 
     @Override
     public int hashCode() {
-      return Objects.hash(
-          parsedPattern, isNegative, policy, offset, excludedSubdirectories, repositoryName);
+      return Objects.hash(parsedPattern, isNegative, policy, offset,
+          excludedSubdirectories);
     }
 
     @Override
@@ -406,12 +386,9 @@
       }
       TargetPatternKey other = (TargetPatternKey) obj;
 
-      return other.isNegative == this.isNegative
-          && other.parsedPattern.equals(this.parsedPattern)
-          && other.offset.equals(this.offset)
-          && other.policy.equals(this.policy)
-          && other.excludedSubdirectories.equals(this.excludedSubdirectories)
-          && other.repositoryName.equals(this.repositoryName);
+      return other.isNegative == this.isNegative && other.parsedPattern.equals(this.parsedPattern)
+          && other.offset.equals(this.offset) && other.policy.equals(this.policy)
+          && other.excludedSubdirectories.equals(this.excludedSubdirectories);
     }
   }
 
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkRuleFunctionsApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkRuleFunctionsApi.java
index 90ffcf3..a35c698 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkRuleFunctionsApi.java
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkRuleFunctionsApi.java
@@ -472,8 +472,7 @@
                     + "tools.")
       },
       useEnvironment = true,
-      useAst = true,
-      useContext = true)
+      useAst = true)
   public SkylarkAspectApi aspect(
       BaseFunction implementation,
       SkylarkList<?> attributeAspects,
@@ -485,8 +484,7 @@
       SkylarkList<?> toolchains,
       String doc,
       FuncallExpression ast,
-      Environment funcallEnv,
-      StarlarkContext context)
+      Environment funcallEnv)
       throws EvalException;
 
   @SkylarkCallable(
diff --git a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeSkylarkRuleFunctionsApi.java b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeSkylarkRuleFunctionsApi.java
index f3a6a38..9201d4d 100644
--- a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeSkylarkRuleFunctionsApi.java
+++ b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeSkylarkRuleFunctionsApi.java
@@ -170,20 +170,10 @@
   }
 
   @Override
-  public SkylarkAspectApi aspect(
-      BaseFunction implementation,
-      SkylarkList<?> attributeAspects,
-      Object attrs,
-      SkylarkList<?> requiredAspectProvidersArg,
-      SkylarkList<?> providesArg,
-      SkylarkList<?> fragments,
-      SkylarkList<?> hostFragments,
-      SkylarkList<?> toolchains,
-      String doc,
-      FuncallExpression ast,
-      Environment funcallEnv,
-      StarlarkContext context)
-      throws EvalException {
+  public SkylarkAspectApi aspect(BaseFunction implementation, SkylarkList<?> attributeAspects,
+      Object attrs, SkylarkList<?> requiredAspectProvidersArg, SkylarkList<?> providesArg,
+      SkylarkList<?> fragments, SkylarkList<?> hostFragments, SkylarkList<?> toolchains, String doc,
+      FuncallExpression ast, Environment funcallEnv) throws EvalException {
     return new FakeSkylarkAspect();
   }