From ac7195025b073948785db8c6975a53fc305c5087 Mon Sep 17 00:00:00 2001 From: Dmitry Lomov Date: Fri, 16 Oct 2015 13:32:02 +0000 Subject: Implement aspect(...) Skylark function. -- MOS_MIGRATED_REVID=105596479 --- .../devtools/build/lib/skyframe/AspectValue.java | 99 ++++++++++++++++++---- 1 file changed, 81 insertions(+), 18 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/AspectValue.java') 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 16277c7a47..5a4052fb8c 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.AspectWithParameters; 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 @@ import javax.annotation.Nullable; * 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. + * A base class for a key representing an aspect applied to a particular target. */ - public static final class AspectKey extends ActionLookupKey { - private final Label label; - private final BuildConfiguration configuration; - private final AspectWithParameters aspect; + public abstract static class AspectKey extends ActionLookupKey { + protected final Label label; + protected final BuildConfiguration configuration; - private AspectKey(Label label, BuildConfiguration configuration, - Class aspectFactory, - AspectParameters parameters) { - Preconditions.checkNotNull(parameters); + protected AspectKey(Label label, BuildConfiguration configuration) { this.label = label; this.configuration = configuration; - this.aspect = new AspectWithParameters(aspectFactory, parameters); } @Override @@ -57,14 +54,34 @@ public final class AspectValue extends ActionLookupValue { 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 aspectFactory, + AspectParameters parameters) { + super(label, configuration); + Preconditions.checkNotNull(parameters); + this.aspect = new AspectWithParameters(aspectFactory, parameters); + } public Class getAspect() { return aspect.getAspectFactory(); } + @Override @Nullable public AspectParameters getParameters() { return aspect.getParameters(); @@ -72,7 +89,7 @@ public final class AspectValue extends ActionLookupValue { @Override SkyFunctionName getType() { - return SkyFunctions.ASPECT; + return SkyFunctions.NATIVE_ASPECT; } @Override @@ -86,11 +103,11 @@ public final class AspectValue extends ActionLookupValue { 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 @@ public final class AspectValue extends ActionLookupValue { } } + /** + * 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 final class AspectValue extends ActionLookupValue { public static SkyKey key(Label label, BuildConfiguration configuration, Class 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 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); } } -- cgit v1.2.3