diff options
20 files changed, 126 insertions, 76 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AbstractConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/analysis/AbstractConfiguredTarget.java index cbe5056dd2..39d6221aa6 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/AbstractConfiguredTarget.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/AbstractConfiguredTarget.java @@ -47,8 +47,6 @@ public abstract class AbstractConfiguredTarget // Accessors for Skylark private static final String DATA_RUNFILES_FIELD = "data_runfiles"; private static final String DEFAULT_RUNFILES_FIELD = "default_runfiles"; - private static final String LABEL_FIELD = "label"; - private static final String FILES_FIELD = "files"; AbstractConfiguredTarget(Target target, BuildConfiguration configuration) { diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAspect.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAspect.java index eb98851c69..6196bce78c 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAspect.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAspect.java @@ -26,6 +26,8 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.events.Location; +import com.google.devtools.build.lib.packages.AspectClass; +import com.google.devtools.build.lib.packages.AspectParameters; import com.google.devtools.build.lib.packages.SkylarkClassObject; import com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor.Key; import com.google.devtools.build.lib.syntax.EvalException; @@ -53,11 +55,11 @@ import javax.annotation.Nullable; */ @Immutable public final class ConfiguredAspect implements Iterable<TransitiveInfoProvider> { - private final String name; private final TransitiveInfoProviderMap providers; + private final AspectDescriptor descriptor; - private ConfiguredAspect(String name, TransitiveInfoProviderMap providers) { - this.name = name; + private ConfiguredAspect(AspectDescriptor descriptor, TransitiveInfoProviderMap providers) { + this.descriptor = descriptor; this.providers = providers; } @@ -65,7 +67,14 @@ public final class ConfiguredAspect implements Iterable<TransitiveInfoProvider> * Returns the aspect name. */ public String getName() { - return name; + return descriptor.getAspectClass().getName(); + } + + /** + * The aspect descriptor originating this ConfiguredAspect. + */ + public AspectDescriptor getDescriptor() { + return descriptor; } /** Returns the providers created by the aspect. */ @@ -85,7 +94,7 @@ public final class ConfiguredAspect implements Iterable<TransitiveInfoProvider> } public static ConfiguredAspect forAlias(ConfiguredAspect real) { - return new ConfiguredAspect(real.getName(), real.getProviders()); + return new ConfiguredAspect(real.descriptor, real.getProviders()); } /** @@ -96,11 +105,18 @@ public final class ConfiguredAspect implements Iterable<TransitiveInfoProvider> private final Map<String, NestedSetBuilder<Artifact>> outputGroupBuilders = new TreeMap<>(); private final ImmutableMap.Builder<String, Object> skylarkProviderBuilder = ImmutableMap.builder(); - private final String name; private final RuleContext ruleContext; + private final AspectDescriptor descriptor; + + public Builder( + AspectClass aspectClass, + AspectParameters parameters, + RuleContext context) { + this(new AspectDescriptor(aspectClass, parameters), context); + } - public Builder(String name, RuleContext ruleContext) { - this.name = name; + public Builder(AspectDescriptor descriptor, RuleContext ruleContext) { + this.descriptor = descriptor; this.ruleContext = ruleContext; } @@ -193,7 +209,7 @@ public final class ConfiguredAspect implements Iterable<TransitiveInfoProvider> ImmutableSet.<ActionAnalysisMetadata>of() /* actionsWithoutExtraAction */, ruleContext)); - return new ConfiguredAspect(name, providers.build()); + return new ConfiguredAspect(descriptor, providers.build()); } } } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTarget.java index 995c2b907a..155110cc2f 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTarget.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTarget.java @@ -30,6 +30,18 @@ import javax.annotation.Nullable; * accessible from the action graph. */ public interface ConfiguredTarget extends TransitiveInfoCollection { + + /** + * All <code>ConfiguredTarget</code>s have a "label" field. + */ + String LABEL_FIELD = "label"; + + /** + * All <code>ConfiguredTarget</code>s have a "files" field. + */ + String FILES_FIELD = "files"; + + /** * Returns the Target with which this {@link ConfiguredTarget} is associated. */ diff --git a/src/main/java/com/google/devtools/build/lib/analysis/MergedConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/analysis/MergedConfiguredTarget.java index c8462980f7..e2b21eb75e 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/MergedConfiguredTarget.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/MergedConfiguredTarget.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.analysis; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.packages.SkylarkClassObject; @@ -30,6 +31,7 @@ import javax.annotation.Nullable; */ public final class MergedConfiguredTarget extends AbstractConfiguredTarget { private final ConfiguredTarget base; + private final ImmutableList<AspectDescriptor> aspects; private final TransitiveInfoProviderMap providers; /** @@ -43,9 +45,12 @@ public final class MergedConfiguredTarget extends AbstractConfiguredTarget { } } - private MergedConfiguredTarget(ConfiguredTarget base, TransitiveInfoProviderMap providers) { + private MergedConfiguredTarget(ConfiguredTarget base, + ImmutableList<AspectDescriptor> aspects, + TransitiveInfoProviderMap providers) { super(base.getTarget(), base.getConfiguration()); this.base = base; + this.aspects = aspects; this.providers = providers; } @@ -73,6 +78,13 @@ public final class MergedConfiguredTarget extends AbstractConfiguredTarget { return provider; } + /** + * List of aspects applied to the target. + */ + public ImmutableList<AspectDescriptor> getAspects() { + return aspects; + } + /** Creates an instance based on a configured target and a set of aspects. */ public static ConfiguredTarget of(ConfiguredTarget base, Iterable<ConfiguredAspect> aspects) throws DuplicateException { @@ -111,6 +123,8 @@ public final class MergedConfiguredTarget extends AbstractConfiguredTarget { aspectProviders.add(mergedExtraActionProviders); } + ImmutableList.Builder<AspectDescriptor> aspectRepresentations = ImmutableList.builder(); + for (ConfiguredAspect aspect : aspects) { for (Map.Entry<Class<? extends TransitiveInfoProvider>, TransitiveInfoProvider> entry : aspect.getProviders().entrySet()) { @@ -126,9 +140,11 @@ public final class MergedConfiguredTarget extends AbstractConfiguredTarget { } aspectProviders.add(entry.getValue()); + aspectRepresentations.add(aspect.getDescriptor()); } + } - return new MergedConfiguredTarget(base, aspectProviders.build()); + return new MergedConfiguredTarget(base, aspectRepresentations.build(), aspectProviders.build()); } private static <T extends TransitiveInfoProvider> List<T> getAllProviders( diff --git a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java b/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java index 55a04fc7b6..8bef4d68ed 100644 --- a/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/ideinfo/AndroidStudioInfoAspect.java @@ -156,7 +156,7 @@ public class AndroidStudioInfoAspect extends NativeAspectClass implements Config @Override public AspectDefinition getDefinition(AspectParameters aspectParameters) { AspectDefinition.Builder builder = - new AspectDefinition.Builder(NAME) + new AspectDefinition.Builder(this) .attributeAspect("runtime_deps", this) .attributeAspect("resources", this) .add( @@ -184,7 +184,7 @@ public class AndroidStudioInfoAspect extends NativeAspectClass implements Config @Override public ConfiguredAspect create( ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) { - ConfiguredAspect.Builder builder = new Builder(NAME, ruleContext); + ConfiguredAspect.Builder builder = new Builder(this, parameters, ruleContext); AndroidStudioInfoFilesProvider.Builder providerBuilder = new AndroidStudioInfoFilesProvider.Builder(); diff --git a/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java b/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java index 02405df882..f3186d765a 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java +++ b/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java @@ -55,7 +55,7 @@ import javax.annotation.Nullable; @Immutable public final class AspectDefinition { - private final String name; + private final AspectClass aspectClass; private final ImmutableSet<Class<?>> requiredProviders; private final ImmutableSet<String> requiredProviderNames; private final ImmutableMap<String, Attribute> attributes; @@ -67,12 +67,12 @@ public final class AspectDefinition { } private AspectDefinition( - String name, + AspectClass aspectClass, ImmutableSet<Class<?>> requiredProviders, ImmutableMap<String, Attribute> attributes, PropagationFunction attributeAspects, @Nullable ConfigurationFragmentPolicy configurationFragmentPolicy) { - this.name = name; + this.aspectClass = aspectClass; this.requiredProviders = requiredProviders; this.requiredProviderNames = toStringSet(requiredProviders); this.attributes = attributes; @@ -81,7 +81,11 @@ public final class AspectDefinition { } public String getName() { - return name; + return aspectClass.getName(); + } + + public AspectClass getAspectClass() { + return aspectClass; } /** @@ -222,7 +226,7 @@ public final class AspectDefinition { * Builder class for {@link AspectDefinition}. */ public static final class Builder { - private final String name; + private final AspectClass aspectClass; private final Map<String, Attribute> attributes = new LinkedHashMap<>(); private final Set<Class<?>> requiredProviders = new LinkedHashSet<>(); private final Multimap<String, AspectClass> attributeAspects = LinkedHashMultimap.create(); @@ -230,8 +234,8 @@ public final class AspectDefinition { private final ConfigurationFragmentPolicy.Builder configurationFragmentPolicy = new ConfigurationFragmentPolicy.Builder(); - public Builder(String name) { - this.name = name; + public Builder(AspectClass aspectClass) { + this.aspectClass = aspectClass; } /** @@ -408,7 +412,7 @@ public final class AspectDefinition { * <p>The builder object is reusable afterwards. */ public AspectDefinition build() { - return new AspectDefinition(name, ImmutableSet.copyOf(requiredProviders), + return new AspectDefinition(aspectClass, ImmutableSet.copyOf(requiredProviders), ImmutableMap.copyOf(attributes), allAttributesAspects != null ? new AllAttributesPropagationFunction(allAttributesAspects) diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java index ca921a3a0a..fdb2bb804c 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkAspect.java @@ -116,7 +116,7 @@ public class SkylarkAspect implements SkylarkExportable { private static final List<String> allAttrAspects = Arrays.asList("*"); public AspectDefinition getDefinition(AspectParameters aspectParams) { - AspectDefinition.Builder builder = new AspectDefinition.Builder(getName()); + AspectDefinition.Builder builder = new AspectDefinition.Builder(aspectClass); if (allAttrAspects.equals(attributeAspects)) { builder.allAttributesAspect(aspectClass); } else { diff --git a/src/main/java/com/google/devtools/build/lib/rules/AliasConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/rules/AliasConfiguredTarget.java index 1c6eebd6a6..a6363b7659 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/AliasConfiguredTarget.java +++ b/src/main/java/com/google/devtools/build/lib/rules/AliasConfiguredTarget.java @@ -117,9 +117,9 @@ public final class AliasConfiguredTarget implements ConfiguredTarget, ClassObjec @Override public Object getValue(String name) { - if (name.equals("label")) { + if (name.equals(LABEL_FIELD)) { return getLabel(); - } else if (name.equals("files")) { + } else if (name.equals(FILES_FIELD)) { // A shortcut for files to build in Skylark. FileConfiguredTarget and RuleConfiguredTarget // always has FileProvider and Error- and PackageGroupConfiguredTarget-s shouldn't be // accessible in Skylark. diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidNeverlinkAspect.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidNeverlinkAspect.java index 4d31393903..e743a92e62 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidNeverlinkAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidNeverlinkAspect.java @@ -49,7 +49,7 @@ public class AndroidNeverlinkAspect extends NativeAspectClass implements Configu ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) { if (!JavaCommon.getConstraints(ruleContext).contains("android") && !ruleContext.getRule().getRuleClass().startsWith("android_")) { - return new ConfiguredAspect.Builder(NAME, ruleContext).build(); + return new ConfiguredAspect.Builder(this, parameters, ruleContext).build(); } List<TransitiveInfoCollection> deps = new ArrayList<>(); @@ -65,7 +65,7 @@ public class AndroidNeverlinkAspect extends NativeAspectClass implements Configu deps.addAll(ruleContext.getPrerequisites(attribute, Mode.TARGET)); } - return new ConfiguredAspect.Builder(NAME, ruleContext) + return new ConfiguredAspect.Builder(this, parameters, ruleContext) .addProvider( AndroidNeverLinkLibrariesProvider.create( AndroidCommon.collectTransitiveNeverlinkLibraries( @@ -77,7 +77,7 @@ public class AndroidNeverlinkAspect extends NativeAspectClass implements Configu @Override public AspectDefinition getDefinition(AspectParameters aspectParameters) { - AspectDefinition.Builder builder = new AspectDefinition.Builder("AndroidNeverlinkAspect"); + AspectDefinition.Builder builder = new AspectDefinition.Builder(this); for (String attribute : ATTRIBUTES) { builder.attributeAspect(attribute, this); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java b/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java index de29a01d2d..eec142cff3 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java @@ -110,7 +110,7 @@ public final class DexArchiveAspect extends NativeAspectClass implements Configu @Override public AspectDefinition getDefinition(AspectParameters params) { - AspectDefinition.Builder result = new AspectDefinition.Builder(NAME) + AspectDefinition.Builder result = new AspectDefinition.Builder(this) // Actually we care about JavaRuntimeJarProvider, but rules don't advertise that provider. .requireProvider(JavaCompilationArgsProvider.class) // Parse labels since we don't have RuleDefinitionEnvironment.getLabel like in a rule @@ -136,7 +136,7 @@ public final class DexArchiveAspect extends NativeAspectClass implements Configu @Override public ConfiguredAspect create(ConfiguredTarget base, RuleContext ruleContext, AspectParameters params) throws InterruptedException { - ConfiguredAspect.Builder result = new ConfiguredAspect.Builder(NAME, ruleContext); + ConfiguredAspect.Builder result = new ConfiguredAspect.Builder(this, params, ruleContext); Function<Artifact, Artifact> desugaredJars = desugarJarsIfRequested(base, ruleContext, result); diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/JackAspect.java b/src/main/java/com/google/devtools/build/lib/rules/android/JackAspect.java index 0a39076fbd..4df83e7532 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/JackAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/JackAspect.java @@ -60,7 +60,7 @@ public final class JackAspect extends NativeAspectClass implements ConfiguredAsp throw new IllegalStateException(e); } - return new AspectDefinition.Builder("JackAspect") + return new AspectDefinition.Builder(this) .requireProvider(JavaSourceInfoProvider.class) .add(attr(":android_sdk", LABEL) .allowedRuleClasses("android_sdk") @@ -76,7 +76,7 @@ public final class JackAspect extends NativeAspectClass implements ConfiguredAsp public ConfiguredAspect create( ConfiguredTarget base, RuleContext ruleContext, AspectParameters params) { if (base.getProvider(JackLibraryProvider.class) != null) { - return new ConfiguredAspect.Builder(NAME, ruleContext).build(); + return new ConfiguredAspect.Builder(this, params, ruleContext).build(); } JavaSourceInfoProvider sourceProvider = base.getProvider(JavaSourceInfoProvider.class); PathFragment rulePath = ruleContext.getLabel().toPathFragment(); @@ -116,7 +116,7 @@ public final class JackAspect extends NativeAspectClass implements ConfiguredAsp JavaCommon.isNeverLink(ruleContext) ? jackHelper.compileAsNeverlinkLibrary() : jackHelper.compileAsLibrary(); - return new ConfiguredAspect.Builder(NAME, ruleContext).addProvider(result).build(); + return new ConfiguredAspect.Builder(this, params, ruleContext).addProvider(result).build(); } /** Gets a list of targets on the given LABEL_LIST attribute if it exists, else an empty list. */ diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java index 5760cbd0fc..7ae7cadd19 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java @@ -89,7 +89,7 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException { ConfiguredAspect.Builder aspect = - new ConfiguredAspect.Builder(getClass().getSimpleName(), ruleContext); + new ConfiguredAspect.Builder(this, parameters, ruleContext); // Get SupportData, which is provided by the proto_library rule we attach to. SupportData supportData = @@ -103,7 +103,7 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured @Override public AspectDefinition getDefinition(AspectParameters aspectParameters) { AspectDefinition.Builder result = - new AspectDefinition.Builder(getClass().getSimpleName()) + new AspectDefinition.Builder(this) .attributeAspect("deps", this) .requiresConfigurationFragments(JavaConfiguration.class, ProtoConfiguration.class) .requireProvider(ProtoSourcesProvider.class) diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java index 721648f90a..9de56254df 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java @@ -125,7 +125,7 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException { ConfiguredAspect.Builder aspect = - new ConfiguredAspect.Builder(getClass().getSimpleName(), ruleContext); + new ConfiguredAspect.Builder(this, parameters, ruleContext); if (!rpcSupport.checkAttributes(ruleContext, parameters)) { return aspect.build(); @@ -153,7 +153,7 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe @Override public AspectDefinition getDefinition(AspectParameters aspectParameters) { AspectDefinition.Builder result = - new AspectDefinition.Builder(getClass().getSimpleName()) + new AspectDefinition.Builder(this) .attributeAspect("deps", this) .requiresConfigurationFragments(JavaConfiguration.class, ProtoConfiguration.class) .requireProvider(ProtoSourcesProvider.class) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java index c4dabc65c9..a6a8a1ec62 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java @@ -82,7 +82,7 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass @Override public AspectDefinition getDefinition(AspectParameters aspectParameters) { - AspectDefinition.Builder builder = new AspectDefinition.Builder("J2ObjcProtoAspect") + AspectDefinition.Builder builder = new AspectDefinition.Builder(this) .requireProvider(ProtoSourcesProvider.class) .requiresConfigurationFragments( AppleConfiguration.class, @@ -125,7 +125,7 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException { if (!checkShouldCreateAspect(ruleContext)) { - return new ConfiguredAspect.Builder(getName(), ruleContext).build(); + return new ConfiguredAspect.Builder(this, parameters, ruleContext).build(); } ProtoSourcesProvider protoSourcesProvider = base.getProvider(ProtoSourcesProvider.class); @@ -195,7 +195,7 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass NestedSet<Artifact> j2ObjcTransitiveClassMappingFiles = j2ObjcTransitiveClassMappingFiles( ruleContext, classMappingFiles); - return new ConfiguredAspect.Builder(getName(), ruleContext) + return new ConfiguredAspect.Builder(this, parameters, ruleContext) .addProviders( new J2ObjcMappingFileProvider( j2ObjcTransitiveHeaderMappingFiles, diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java index 4653d1fabb..8679970a68 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java @@ -106,7 +106,7 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF @Override public AspectDefinition getDefinition(AspectParameters aspectParameters) { - return addAdditionalAttributes(new AspectDefinition.Builder("J2ObjCAspect")) + return addAdditionalAttributes(new AspectDefinition.Builder(this)) .attributeAspect("deps", this, j2ObjcProtoAspect) .attributeAspect("exports", this, j2ObjcProtoAspect) .attributeAspect("runtime_deps", this, j2ObjcProtoAspect) @@ -167,7 +167,7 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF public ConfiguredAspect create( ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException { - ConfiguredAspect.Builder builder = new ConfiguredAspect.Builder(NAME, ruleContext); + ConfiguredAspect.Builder builder = new ConfiguredAspect.Builder(this, parameters, ruleContext); JavaCompilationArgsProvider compilationArgsProvider = base.getProvider(JavaCompilationArgsProvider.class); JavaSourceInfoProvider sourceInfoProvider = diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoAspect.java index 4184f704f9..fa959e140d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoAspect.java @@ -35,7 +35,7 @@ public class ObjcProtoAspect extends NativeAspectClass implements ConfiguredAspe @Override public AspectDefinition getDefinition(AspectParameters aspectParameters) { - return new AspectDefinition.Builder(NAME) + return new AspectDefinition.Builder(this) .attributeAspect("deps", this) .build(); } @@ -44,7 +44,8 @@ public class ObjcProtoAspect extends NativeAspectClass implements ConfiguredAspe public ConfiguredAspect create( ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException { - ConfiguredAspect.Builder aspectBuilder = new ConfiguredAspect.Builder(NAME, ruleContext); + ConfiguredAspect.Builder aspectBuilder = new ConfiguredAspect.Builder( + this, parameters, ruleContext); ObjcProtoProvider.Builder aspectObjcProtoProvider = new ObjcProtoProvider.Builder(); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkAspectFactory.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkAspectFactory.java index eb3922ad1a..7a058fd5eb 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkAspectFactory.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkAspectFactory.java @@ -83,7 +83,7 @@ public class SkylarkAspectFactory implements ConfiguredAspectFactory { } ConfiguredAspect.Builder builder = new ConfiguredAspect.Builder( - skylarkAspect.getName(), ruleContext); + skylarkAspect.getAspectClass(), parameters, ruleContext); SkylarkClassObject struct = (SkylarkClassObject) aspectSkylarkObject; Location loc = struct.getCreationLoc(); diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AspectDefinitionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AspectDefinitionTest.java index 667af95af3..eb6b8f8070 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/AspectDefinitionTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/AspectDefinitionTest.java @@ -40,6 +40,7 @@ import org.junit.runners.JUnit4; */ @RunWith(JUnit4.class) public class AspectDefinitionTest { + /** * A dummy aspect factory. Is there to demonstrate how to define aspects and so that we can test * {@code attributeAspect}. @@ -77,7 +78,7 @@ public class AspectDefinitionTest { return Label.parseAbsoluteUnchecked("//run:away"); } }; - AspectDefinition simple = new AspectDefinition.Builder("simple") + AspectDefinition simple = new AspectDefinition.Builder(TEST_ASPECT_CLASS) .add(implicit) .add(attr(":latebound", BuildType.LABEL).value(latebound)) .build(); @@ -90,7 +91,7 @@ public class AspectDefinitionTest { @Test public void testAspectWithDuplicateAttribute_FailsToAdd() throws Exception { try { - new AspectDefinition.Builder("clash") + new AspectDefinition.Builder(TEST_ASPECT_CLASS) .add(attr("$runtime", BuildType.LABEL).value(Label.parseAbsoluteUnchecked("//run:time"))) .add(attr("$runtime", BuildType.LABEL).value(Label.parseAbsoluteUnchecked("//oops"))); fail(); // expected IllegalArgumentException @@ -102,7 +103,7 @@ public class AspectDefinitionTest { @Test public void testAspectWithUserVisibleAttribute_FailsToAdd() throws Exception { try { - new AspectDefinition.Builder("user_visible_attribute") + new AspectDefinition.Builder(TEST_ASPECT_CLASS) .add( attr("invalid", BuildType.LABEL) .value(Label.parseAbsoluteUnchecked("//run:time")) @@ -116,7 +117,7 @@ public class AspectDefinitionTest { @Test public void testAttributeAspect_WrapsAndAddsToMap() throws Exception { - AspectDefinition withAspects = new AspectDefinition.Builder("attribute_aspect") + AspectDefinition withAspects = new AspectDefinition.Builder(TEST_ASPECT_CLASS) .attributeAspect("srcs", TEST_ASPECT_CLASS) .attributeAspect("deps", TEST_ASPECT_CLASS) .build(); @@ -129,7 +130,7 @@ public class AspectDefinitionTest { @Test public void testAttributeAspect_AllAttributes() throws Exception { - AspectDefinition withAspects = new AspectDefinition.Builder("attribute_aspect") + AspectDefinition withAspects = new AspectDefinition.Builder(TEST_ASPECT_CLASS) .allAttributesAspect(TEST_ASPECT_CLASS) .build(); @@ -148,7 +149,7 @@ public class AspectDefinitionTest { @Test public void testRequireProvider_AddsToSetOfRequiredProvidersAndNames() throws Exception { - AspectDefinition requiresProviders = new AspectDefinition.Builder("required_providers") + AspectDefinition requiresProviders = new AspectDefinition.Builder(TEST_ASPECT_CLASS) .requireProvider(String.class) .requireProvider(Integer.class) .build(); @@ -160,14 +161,14 @@ public class AspectDefinitionTest { @Test public void testNoConfigurationFragmentPolicySetup_HasNonNullPolicy() throws Exception { - AspectDefinition noPolicy = new AspectDefinition.Builder("no_policy") + AspectDefinition noPolicy = new AspectDefinition.Builder(TEST_ASPECT_CLASS) .build(); assertThat(noPolicy.getConfigurationFragmentPolicy()).isNotNull(); } @Test public void testMissingFragmentPolicy_PropagatedToConfigurationFragmentPolicy() throws Exception { - AspectDefinition missingFragments = new AspectDefinition.Builder("missing_fragments") + AspectDefinition missingFragments = new AspectDefinition.Builder(TEST_ASPECT_CLASS) .setMissingFragmentPolicy(MissingFragmentPolicy.IGNORE) .build(); assertThat(missingFragments.getConfigurationFragmentPolicy()).isNotNull(); @@ -178,7 +179,7 @@ public class AspectDefinitionTest { @Test public void testRequiresConfigurationFragments_PropagatedToConfigurationFragmentPolicy() throws Exception { - AspectDefinition requiresFragments = new AspectDefinition.Builder("requires_fragments") + AspectDefinition requiresFragments = new AspectDefinition.Builder(TEST_ASPECT_CLASS) .requiresConfigurationFragments(Integer.class, String.class) .build(); assertThat(requiresFragments.getConfigurationFragmentPolicy()).isNotNull(); @@ -190,7 +191,7 @@ public class AspectDefinitionTest { @Test public void testRequiresHostConfigurationFragments_PropagatedToConfigurationFragmentPolicy() throws Exception { - AspectDefinition requiresFragments = new AspectDefinition.Builder("requires_fragments") + AspectDefinition requiresFragments = new AspectDefinition.Builder(TEST_ASPECT_CLASS) .requiresHostConfigurationFragments(Integer.class, String.class) .build(); assertThat(requiresFragments.getConfigurationFragmentPolicy()).isNotNull(); @@ -202,7 +203,7 @@ public class AspectDefinitionTest { @Test public void testRequiresConfigurationFragmentNames_PropagatedToConfigurationFragmentPolicy() throws Exception { - AspectDefinition requiresFragments = new AspectDefinition.Builder("requires_fragments") + AspectDefinition requiresFragments = new AspectDefinition.Builder(TEST_ASPECT_CLASS) .requiresConfigurationFragmentsBySkylarkModuleName(ImmutableList.of("test_fragment")) .build(); assertThat(requiresFragments.getConfigurationFragmentPolicy()).isNotNull(); @@ -215,7 +216,7 @@ public class AspectDefinitionTest { @Test public void testRequiresHostConfigurationFragmentNames_PropagatedToConfigurationFragmentPolicy() throws Exception { - AspectDefinition requiresFragments = new AspectDefinition.Builder("requires_fragments") + AspectDefinition requiresFragments = new AspectDefinition.Builder(TEST_ASPECT_CLASS) .requiresHostConfigurationFragmentsBySkylarkModuleName(ImmutableList.of("test_fragment")) .build(); assertThat(requiresFragments.getConfigurationFragmentPolicy()).isNotNull(); @@ -227,7 +228,7 @@ public class AspectDefinitionTest { @Test public void testEmptySkylarkConfigurationFragmentPolicySetup_HasNonNullPolicy() throws Exception { - AspectDefinition noPolicy = new AspectDefinition.Builder("no_policy") + AspectDefinition noPolicy = new AspectDefinition.Builder(TEST_ASPECT_CLASS) .requiresConfigurationFragmentsBySkylarkModuleName(ImmutableList.<String>of()) .requiresHostConfigurationFragmentsBySkylarkModuleName(ImmutableList.<String>of()) .build(); diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java index af00a7ee76..37abaafb46 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java @@ -321,7 +321,7 @@ public class AspectTest extends AnalysisTestCase { implements ConfiguredAspectFactory { @Override public AspectDefinition getDefinition(AspectParameters params) { - return new AspectDefinition.Builder("testaspect") + return new AspectDefinition.Builder(this) .add(attr(":late", LABEL).value(EMPTY_LATE_BOUND_LABEL)).build(); } @@ -330,7 +330,7 @@ public class AspectTest extends AnalysisTestCase { ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException { Object lateBoundPrereq = ruleContext.getPrerequisite(":late", TARGET); - return new ConfiguredAspect.Builder("testaspect", ruleContext) + return new ConfiguredAspect.Builder(this, parameters, ruleContext) .addProvider( AspectInfo.class, new AspectInfo( @@ -385,15 +385,17 @@ public class AspectTest extends AnalysisTestCase { implements ConfiguredAspectFactory { @Override public AspectDefinition getDefinition(AspectParameters params) { - return new AspectDefinition.Builder("testaspect").build(); + return new AspectDefinition.Builder(this).build(); } + + @Override public ConfiguredAspect create( ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException { ruleContext.registerAction(new NullAction(ruleContext.createOutputArtifact())); - return new ConfiguredAspect.Builder("testaspect", ruleContext).build(); + return new ConfiguredAspect.Builder(this, parameters, ruleContext).build(); } } private static final AspectThatRegistersAction ASPECT_THAT_REGISTERS_ACTION = diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/TestAspects.java b/src/test/java/com/google/devtools/build/lib/analysis/util/TestAspects.java index f6f693e0e3..55b0fe84d8 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/TestAspects.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/TestAspects.java @@ -170,7 +170,7 @@ public class TestAspects { String information = parameters.isEmpty() ? "" : " data " + Iterables.getFirst(parameters.getAttribute("baz"), null); - return new ConfiguredAspect.Builder(getClass().getName(), ruleContext) + return new ConfiguredAspect.Builder(this, parameters, ruleContext) .addProvider( new AspectInfo( collectAspectData("aspect " + ruleContext.getLabel() + information, ruleContext))) @@ -180,7 +180,7 @@ public class TestAspects { public static final SimpleAspect SIMPLE_ASPECT = new SimpleAspect(); private static final AspectDefinition SIMPLE_ASPECT_DEFINITION = - new AspectDefinition.Builder("simple").build(); + new AspectDefinition.Builder(SIMPLE_ASPECT).build(); /** * A very simple aspect. @@ -194,14 +194,14 @@ public class TestAspects { public static final ExtraAttributeAspect EXTRA_ATTRIBUTE_ASPECT = new ExtraAttributeAspect(); private static final AspectDefinition EXTRA_ATTRIBUTE_ASPECT_DEFINITION = - new AspectDefinition.Builder("extra_attribute") + new AspectDefinition.Builder(EXTRA_ATTRIBUTE_ASPECT) .add(attr("$dep", LABEL).value(Label.parseAbsoluteUnchecked("//extra:extra"))) .build(); private static final ExtraAttributeAspectRequiringProvider EXTRA_ATTRIBUTE_ASPECT_REQUIRING_PROVIDER = new ExtraAttributeAspectRequiringProvider(); private static final AspectDefinition EXTRA_ATTRIBUTE_ASPECT_REQUIRING_PROVIDER_DEFINITION = - new AspectDefinition.Builder("extra_attribute_with_provider") + new AspectDefinition.Builder(EXTRA_ATTRIBUTE_ASPECT_REQUIRING_PROVIDER) .add(attr("$dep", LABEL).value(Label.parseAbsoluteUnchecked("//extra:extra"))) .requireProvider(RequiredProvider.class) .build(); @@ -218,7 +218,7 @@ public class TestAspects { public static final AttributeAspect ATTRIBUTE_ASPECT = new AttributeAspect(); private static final AspectDefinition ATTRIBUTE_ASPECT_DEFINITION = - new AspectDefinition.Builder("attribute") + new AspectDefinition.Builder(ATTRIBUTE_ASPECT) .attributeAspect("foo", ATTRIBUTE_ASPECT) .build(); @@ -234,7 +234,7 @@ public class TestAspects { } public static final NativeAspectClass ALL_ATTRIBUTES_ASPECT = new AllAttributesAspect(); private static final AspectDefinition ALL_ATTRIBUTES_ASPECT_DEFINITION = - new AspectDefinition.Builder("all_attributes_aspect") + new AspectDefinition.Builder(ALL_ATTRIBUTES_ASPECT) .allAttributesAspect(ALL_ATTRIBUTES_ASPECT) .build(); @@ -250,7 +250,7 @@ public class TestAspects { public static final NativeAspectClass ALL_ATTRIBUTES_WITH_TOOL_ASPECT = new AllAttributesWithToolAspect(); private static final AspectDefinition ALL_ATTRIBUTES_WITH_TOOL_ASPECT_DEFINITION = - new AspectDefinition.Builder("all_attributes_with_tool_aspect") + new AspectDefinition.Builder(ALL_ATTRIBUTES_WITH_TOOL_ASPECT) .allAttributesAspect(ALL_ATTRIBUTES_WITH_TOOL_ASPECT) .add( attr("$tool", BuildType.LABEL) @@ -294,7 +294,7 @@ public class TestAspects { @Override public AspectDefinition getDefinition(AspectParameters aspectParameters) { AspectDefinition.Builder builder = - new AspectDefinition.Builder("parametrized_definition_aspect") + new AspectDefinition.Builder(PARAMETRIZED_DEFINITION_ASPECT) .attributeAspect("foo", this); ImmutableCollection<String> baz = aspectParameters.getAttribute("baz"); if (baz != null) { @@ -323,7 +323,7 @@ public class TestAspects { information.append(dep.getLabel()); } information.append("]"); - return new ConfiguredAspect.Builder(getClass().getName(), ruleContext) + return new ConfiguredAspect.Builder(this, parameters, ruleContext) .addProvider(new AspectInfo(collectAspectData(information.toString(), ruleContext))) .build(); } @@ -335,7 +335,7 @@ public class TestAspects { private static final AspectRequiringProvider ASPECT_REQUIRING_PROVIDER = new AspectRequiringProvider(); private static final AspectDefinition ASPECT_REQUIRING_PROVIDER_DEFINITION = - new AspectDefinition.Builder("requiring_provider") + new AspectDefinition.Builder(ASPECT_REQUIRING_PROVIDER) .requireProvider(RequiredProvider.class) .build(); @@ -349,7 +349,7 @@ public class TestAspects { public ConfiguredAspect create( ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) { ruleContext.ruleWarning("Aspect warning on " + base.getTarget().getLabel()); - return new ConfiguredAspect.Builder("warning", ruleContext).build(); + return new ConfiguredAspect.Builder(this, parameters, ruleContext).build(); } @Override @@ -360,7 +360,7 @@ public class TestAspects { public static final WarningAspect WARNING_ASPECT = new WarningAspect(); private static final AspectDefinition WARNING_ASPECT_DEFINITION = - new AspectDefinition.Builder("warning") + new AspectDefinition.Builder(WARNING_ASPECT) .attributeAspect("bar", WARNING_ASPECT) .build(); @@ -385,7 +385,7 @@ public class TestAspects { public static final ErrorAspect ERROR_ASPECT = new ErrorAspect(); private static final AspectDefinition ERROR_ASPECT_DEFINITION = - new AspectDefinition.Builder("error") + new AspectDefinition.Builder(ERROR_ASPECT) .attributeAspect("bar", ERROR_ASPECT) .build(); |