Implement aspect(...) Skylark function.

--
MOS_MIGRATED_REVID=105844221
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java
index 16277c7..5a4052f 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java
@@ -22,6 +22,7 @@
 import com.google.devtools.build.lib.analysis.ConfiguredAspectFactory;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.cmdline.PackageIdentifier;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.events.Location;
 import com.google.devtools.build.lib.packages.AspectParameters;
@@ -35,21 +36,17 @@
  * An aspect in the context of the Skyframe graph.
  */
 public final class AspectValue extends ActionLookupValue {
-  /**
-   * The key of an action that is generated by an aspect.
-   */
-  public static final class AspectKey extends ActionLookupKey {
-    private final Label label;
-    private final BuildConfiguration configuration;
-    private final AspectWithParameters aspect;
 
-    private AspectKey(Label label, BuildConfiguration configuration,
-        Class<? extends ConfiguredAspectFactory> aspectFactory,
-        AspectParameters parameters) {
-      Preconditions.checkNotNull(parameters);
+  /**
+   * A base class for a key representing an aspect applied to a particular target.
+   */
+  public abstract static class AspectKey extends ActionLookupKey {
+    protected final Label label;
+    protected final BuildConfiguration configuration;
+
+    protected AspectKey(Label label, BuildConfiguration configuration) {
       this.label = label;
       this.configuration = configuration;
-      this.aspect = new AspectWithParameters(aspectFactory, parameters);
     }
 
     @Override
@@ -57,14 +54,34 @@
       return label;
     }
 
+    public abstract AspectParameters getParameters();
+
     public BuildConfiguration getConfiguration() {
       return configuration;
     }
+  }
+
+  /**
+   * The key of an action that is generated by a native aspect.
+   */
+  public static final class NativeAspectKey extends AspectKey {
+    private final AspectWithParameters aspect;
+
+    private NativeAspectKey(
+        Label label,
+        BuildConfiguration configuration,
+        Class<? extends ConfiguredAspectFactory> aspectFactory,
+        AspectParameters parameters) {
+      super(label, configuration);
+      Preconditions.checkNotNull(parameters);
+      this.aspect = new AspectWithParameters(aspectFactory, parameters);
+    }
 
     public Class<? extends ConfiguredAspectFactory> getAspect() {
       return aspect.getAspectFactory();
     }
 
+    @Override
     @Nullable
     public AspectParameters getParameters() {
       return aspect.getParameters();
@@ -72,7 +89,7 @@
 
     @Override
     SkyFunctionName getType() {
-      return SkyFunctions.ASPECT;
+      return SkyFunctions.NATIVE_ASPECT;
     }
 
     @Override
@@ -86,11 +103,11 @@
         return true;
       }
 
-      if (!(other instanceof AspectKey)) {
+      if (!(other instanceof NativeAspectKey)) {
         return false;
       }
 
-      AspectKey that = (AspectKey) other;
+      NativeAspectKey that = (NativeAspectKey) other;
       return Objects.equal(label, that.label)
           && Objects.equal(configuration, that.configuration)
           && Objects.equal(aspect, that.aspect);
@@ -104,6 +121,43 @@
     }
   }
 
+  /**
+   * The key of an action that is generated by a skylark aspect.
+   */
+  public static class SkylarkAspectKey extends AspectKey {
+    private final PackageIdentifier extensionFile;
+    private final String skylarkFunctionName;
+
+    private SkylarkAspectKey(
+        Label targetLabel,
+        BuildConfiguration targetConfiguration,
+        PackageIdentifier extensionFile,
+        String skylarkFunctionName) {
+      super(targetLabel, targetConfiguration);
+      this.extensionFile = extensionFile;
+      this.skylarkFunctionName = skylarkFunctionName;
+    }
+
+    public PackageIdentifier getExtensionFile() {
+      return extensionFile;
+    }
+
+    public String getSkylarkValueName() {
+      return skylarkFunctionName;
+    }
+
+    @Override
+    public AspectParameters getParameters() {
+      return AspectParameters.EMPTY;
+    }
+
+    @Override
+    SkyFunctionName getType() {
+      return SkyFunctions.SKYLARK_ASPECT;
+    }
+  }
+
+
   private final Label label;
   private final Location location;
   private final AspectKey key;
@@ -144,18 +198,27 @@
   public static SkyKey key(Label label, BuildConfiguration configuration,
       Class<? extends ConfiguredAspectFactory> aspectFactory,
       AspectParameters additionalConfiguration) {
-    return new SkyKey(SkyFunctions.ASPECT,
-        new AspectKey(label, configuration, aspectFactory, additionalConfiguration));
+    return new SkyKey(
+        SkyFunctions.NATIVE_ASPECT,
+        new NativeAspectKey(label, configuration, aspectFactory, additionalConfiguration));
   }
 
   public static SkyKey key(AspectKey aspectKey) {
-    return new SkyKey(SkyFunctions.ASPECT, aspectKey);
+    return new SkyKey(aspectKey.getType(), aspectKey);
   }
 
-  public static AspectKey createAspectKey(
+  public static NativeAspectKey createAspectKey(
       Label label,
       BuildConfiguration configuration,
       Class<? extends ConfiguredAspectFactory> aspectFactory) {
-    return new AspectKey(label, configuration, aspectFactory, AspectParameters.EMPTY);
+    return new NativeAspectKey(label, configuration, aspectFactory, AspectParameters.EMPTY);
+  }
+
+  public static SkylarkAspectKey createSkylarkAspectKey(
+      Label targetLabel,
+      BuildConfiguration targetConfiguration,
+      PackageIdentifier bzlFile,
+      String skylarkFunctionName) {
+    return new SkylarkAspectKey(targetLabel, targetConfiguration, bzlFile, skylarkFunctionName);
   }
 }