Fix toolchain and execution platform registration to use patterns.

This allows more flexibility in registering toolchains and execution
platforms, both in the WORKSPACE and from the command-line.

Change-Id: I6fe75507d1a74de74085b7c927fdf093c152b894
PiperOrigin-RevId: 188813688
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 03f2de6..25c375e 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
@@ -203,8 +203,8 @@
   private ImmutableList<Event> events;
   private ImmutableList<Postable> posts;
 
-  private ImmutableList<Label> registeredExecutionPlatformLabels;
-  private ImmutableList<Label> registeredToolchainLabels;
+  private ImmutableList<String> registeredExecutionPlatforms;
+  private ImmutableList<String> registeredToolchains;
 
   /**
    * Package initialization, part 1 of 3: instantiates a new package with the
@@ -340,9 +340,8 @@
     this.features = ImmutableSortedSet.copyOf(builder.features);
     this.events = ImmutableList.copyOf(builder.events);
     this.posts = ImmutableList.copyOf(builder.posts);
-    this.registeredExecutionPlatformLabels =
-        ImmutableList.copyOf(builder.registeredExecutionPlatformLabels);
-    this.registeredToolchainLabels = ImmutableList.copyOf(builder.registeredToolchainLabels);
+    this.registeredExecutionPlatforms = ImmutableList.copyOf(builder.registeredExecutionPlatforms);
+    this.registeredToolchains = ImmutableList.copyOf(builder.registeredToolchains);
   }
 
   /**
@@ -659,12 +658,12 @@
     return defaultRestrictedTo;
   }
 
-  public ImmutableList<Label> getRegisteredExecutionPlatformLabels() {
-    return registeredExecutionPlatformLabels;
+  public ImmutableList<String> getRegisteredExecutionPlatforms() {
+    return registeredExecutionPlatforms;
   }
 
-  public ImmutableList<Label> getRegisteredToolchainLabels() {
-    return registeredToolchainLabels;
+  public ImmutableList<String> getRegisteredToolchains() {
+    return registeredToolchains;
   }
 
   @Override
@@ -789,8 +788,8 @@
     protected Map<Label, Path> subincludes = null;
     protected ImmutableList<Label> skylarkFileDependencies = ImmutableList.of();
 
-    protected List<Label> registeredExecutionPlatformLabels = new ArrayList<>();
-    protected List<Label> registeredToolchainLabels = new ArrayList<>();
+    protected List<String> registeredExecutionPlatforms = new ArrayList<>();
+    protected List<String> registeredToolchains = new ArrayList<>();
 
     /**
      * True iff the "package" function has already been called in this package.
@@ -1313,12 +1312,12 @@
       addRuleUnchecked(rule);
     }
 
-    public void addRegisteredExecutionPlatformLabels(List<Label> platforms) {
-      this.registeredExecutionPlatformLabels.addAll(platforms);
+    public void addRegisteredExecutionPlatforms(List<String> platforms) {
+      this.registeredExecutionPlatforms.addAll(platforms);
     }
 
-    void addRegisteredToolchainLabels(List<Label> toolchains) {
-      this.registeredToolchainLabels.addAll(toolchains);
+    void addRegisteredToolchains(List<String> toolchains) {
+      this.registeredToolchains.addAll(toolchains);
     }
 
     private Builder beforeBuild(boolean discoverAssumedInputFiles)