diff options
author | mjhalupka <mjhalupka@google.com> | 2018-03-12 12:43:15 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-12 12:45:18 -0700 |
commit | cfa0bb7393c030682ee263586ea974f6f0b4bb5c (patch) | |
tree | d0fcd3dc5f4aaa2b199902995322028270863399 /src/main/java/com/google/devtools/build/lib/packages | |
parent | bff3472e4013c053e452fad7948ad68c5cbd5692 (diff) |
Tag Attribute, SkylarkDefinedAspect and some other Skylark classes with
@AutoCodec. Remove Environment from SkylarkDefinedAspect.
Add a note to BuiltInFunction that we shouldn't need to serialize it because
all instances should be constant.
PiperOrigin-RevId: 188763259
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages')
4 files changed, 81 insertions, 52 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java index 5623847960..045520aa6d 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java @@ -37,6 +37,7 @@ import com.google.devtools.build.lib.events.EventHandler; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassNamePredicate; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; import com.google.devtools.build.lib.syntax.ClassObject; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.EvalUtils; @@ -62,23 +63,22 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; /** - * Metadata of a rule attribute. Contains the attribute name and type, and an - * default value to be used if none is provided in a rule declaration in a BUILD - * file. Attributes are immutable, and may be shared by more than one rule (for - * example, <code>foo_binary</code> and <code>foo_library</code> may share many - * attributes in common). + * Metadata of a rule attribute. Contains the attribute name and type, and an default value to be + * used if none is provided in a rule declaration in a BUILD file. Attributes are immutable, and may + * be shared by more than one rule (for example, <code>foo_binary</code> and <code>foo_library + * </code> may share many attributes in common). */ @Immutable +@AutoCodec public final class Attribute implements Comparable<Attribute> { public static final RuleClassNamePredicate ANY_RULE = RuleClassNamePredicate.unspecified(); public static final RuleClassNamePredicate NO_RULE = RuleClassNamePredicate.only(); - /** - * Wraps the information necessary to construct an Aspect. - */ - private abstract static class RuleAspect<C extends AspectClass> { + /** Wraps the information necessary to construct an Aspect. */ + @VisibleForSerialization + abstract static class RuleAspect<C extends AspectClass> { protected final C aspectClass; protected final Function<Rule, AspectParameters> parametersExtractor; @@ -115,7 +115,8 @@ public final class Attribute implements Comparable<Attribute> { } } - private static class SkylarkRuleAspect extends RuleAspect<SkylarkAspectClass> { + @AutoCodec + static class SkylarkRuleAspect extends RuleAspect<SkylarkAspectClass> { private final SkylarkDefinedAspect aspect; public SkylarkRuleAspect(SkylarkDefinedAspect aspect) { @@ -150,7 +151,8 @@ public final class Attribute implements Comparable<Attribute> { } } - private enum PropertyFlag { + @VisibleForSerialization + enum PropertyFlag { MANDATORY, EXECUTABLE, UNDOCUMENTED, @@ -258,6 +260,7 @@ public final class Attribute implements Comparable<Attribute> { String checkValid(Rule from, Rule to); } + @AutoCodec public static final ValidityPredicate ANY_EDGE = new ValidityPredicate() { @Override @@ -297,9 +300,8 @@ public final class Attribute implements Comparable<Attribute> { } } - /** - * A predicate class to check if the value of the attribute comes from a predefined set. - */ + /** A predicate class to check if the value of the attribute comes from a predefined set. */ + @AutoCodec public static class AllowedValueSet implements PredicateWithMessage<Object> { private final Set<Object> allowedValues; @@ -314,6 +316,12 @@ public final class Attribute implements Comparable<Attribute> { allowedValues = ImmutableSet.copyOf(values); } + @AutoCodec.Instantiator + @VisibleForSerialization + AllowedValueSet(Set<Object> allowedValues) { + this.allowedValues = allowedValues; + } + @Override public boolean apply(Object input) { return allowedValues.contains(input); @@ -1839,7 +1847,8 @@ public final class Attribute implements Comparable<Attribute> { * @param configTransition the configuration transition for this attribute (which must be of type * LABEL, LABEL_LIST, NODEP_LABEL or NODEP_LABEL_LIST). */ - private Attribute( + @VisibleForSerialization + Attribute( String name, Type<?> type, Set<PropertyFlag> propertyFlags, diff --git a/src/main/java/com/google/devtools/build/lib/packages/PredicatesWithMessage.java b/src/main/java/com/google/devtools/build/lib/packages/PredicatesWithMessage.java index b0c8edab36..cfec2c78cc 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/PredicatesWithMessage.java +++ b/src/main/java/com/google/devtools/build/lib/packages/PredicatesWithMessage.java @@ -13,26 +13,30 @@ // limitations under the License. package com.google.devtools.build.lib.packages; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; + /** * A helper class for PredicateWithMessage with default predicates. */ public abstract class PredicatesWithMessage implements PredicateWithMessage<Object> { - private static final PredicateWithMessage<?> ALWAYS_TRUE = new PredicateWithMessage<Object>() { - @Override - public boolean apply(Object input) { - return true; - } + @AutoCodec @VisibleForSerialization + static final PredicateWithMessage<?> ALWAYS_TRUE = + new PredicateWithMessage<Object>() { + @Override + public boolean apply(Object input) { + return true; + } - @Override - public String getErrorReason(Object param) { - throw new UnsupportedOperationException(); - } - }; + @Override + public String getErrorReason(Object param) { + throw new UnsupportedOperationException(); + } + }; @SuppressWarnings("unchecked") public static <T> PredicateWithMessage<T> alwaysTrue() { return (PredicateWithMessage<T>) ALWAYS_TRUE; } - } diff --git a/src/main/java/com/google/devtools/build/lib/packages/RequiredProviders.java b/src/main/java/com/google/devtools/build/lib/packages/RequiredProviders.java index 6e5060de4a..1551d70f35 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/RequiredProviders.java +++ b/src/main/java/com/google/devtools/build/lib/packages/RequiredProviders.java @@ -18,27 +18,28 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; import java.util.function.Function; import java.util.function.Predicate; import javax.annotation.Nullable; /** - * Represents a constraint on a set of providers required by a dependency (of a rule - * or an aspect). + * Represents a constraint on a set of providers required by a dependency (of a rule or an aspect). + * + * <p>Currently we support three kinds of constraints: * - * Currently we support three kinds of constraints: * <ul> - * <li>accept any dependency.</li> - * <li>accept no dependency (used for aspects-on-aspects to indicate - * that an aspect never wants to see any other aspect applied to a target.</li> - * <li>accept a dependency that provides all providers from one of several sets of providers. - * It just so happens that in all current usages these sets are either all - * native providers or all Skylark providers, so this is the only use case this - * class currently supports. - * </li> + * <li>accept any dependency. + * <li>accept no dependency (used for aspects-on-aspects to indicate that an aspect never wants to + * see any other aspect applied to a target. + * <li>accept a dependency that provides all providers from one of several sets of providers. It + * just so happens that in all current usages these sets are either all native providers or + * all Skylark providers, so this is the only use case this class currently supports. * </ul> */ @Immutable +@AutoCodec public final class RequiredProviders { /** A constraint: either ANY, NONE, or RESTRICTED */ private final Constraint constraint; @@ -62,10 +63,9 @@ public final class RequiredProviders { return getDescription(); } - /** - * Represents one of the constraints as desctibed in {@link RequiredProviders} - */ - private enum Constraint { + /** Represents one of the constraints as desctibed in {@link RequiredProviders} */ + @VisibleForSerialization + enum Constraint { /** Accept any dependency */ ANY { @Override @@ -272,8 +272,8 @@ public final class RequiredProviders { return constraint.equals(Constraint.ANY); } - - private RequiredProviders( + @VisibleForSerialization + RequiredProviders( Constraint constraint, ImmutableList<ImmutableSet<Class<?>>> nativeProviders, ImmutableList<ImmutableSet<SkylarkProviderIdentifier>> skylarkProviders) { diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkDefinedAspect.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkDefinedAspect.java index 35d38c6510..14ec9d646e 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkDefinedAspect.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkDefinedAspect.java @@ -21,15 +21,17 @@ import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.analysis.config.transitions.ConfigurationTransition; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.Location; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization; import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter; import com.google.devtools.build.lib.syntax.BaseFunction; -import com.google.devtools.build.lib.syntax.Environment; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.Type; import java.util.Arrays; import java.util.List; /** A Skylark value that is a result of an 'aspect(..)' function call. */ +@AutoCodec public class SkylarkDefinedAspect implements SkylarkExportable, SkylarkAspect { private final BaseFunction implementation; private final ImmutableList<String> attributeAspects; @@ -42,7 +44,6 @@ public class SkylarkDefinedAspect implements SkylarkExportable, SkylarkAspect { private final ImmutableSet<String> hostFragments; private final ImmutableList<Label> requiredToolchains; - private final Environment funcallEnv; private SkylarkAspectClass aspectClass; public SkylarkDefinedAspect( @@ -56,8 +57,7 @@ public class SkylarkDefinedAspect implements SkylarkExportable, SkylarkAspect { // The host transition is in lib.analysis, so we can't reference it directly here. ConfigurationTransition hostTransition, ImmutableSet<String> hostFragments, - ImmutableList<Label> requiredToolchains, - Environment funcallEnv) { + ImmutableList<Label> requiredToolchains) { this.implementation = implementation; this.attributeAspects = attributeAspects; this.attributes = attributes; @@ -68,7 +68,27 @@ public class SkylarkDefinedAspect implements SkylarkExportable, SkylarkAspect { this.hostTransition = hostTransition; this.hostFragments = hostFragments; this.requiredToolchains = requiredToolchains; - this.funcallEnv = funcallEnv; + } + + /** Constructor for post export reconstruction for serialization. */ + @VisibleForSerialization + @AutoCodec.Instantiator + SkylarkDefinedAspect( + BaseFunction implementation, + ImmutableList<String> attributeAspects, + ImmutableList<Attribute> attributes, + ImmutableList<ImmutableSet<SkylarkProviderIdentifier>> requiredAspectProviders, + ImmutableSet<SkylarkProviderIdentifier> provides, + ImmutableSet<String> paramAttributes, + ImmutableSet<String> fragments, + // The host transition is in lib.analysis, so we can't reference it directly here. + ConfigurationTransition hostTransition, + ImmutableSet<String> hostFragments, + ImmutableList<Label> requiredToolchains, + SkylarkAspectClass aspectClass) { + this(implementation, attributeAspects, attributes, requiredAspectProviders, provides, + paramAttributes, fragments, hostTransition, hostFragments, requiredToolchains); + this.aspectClass = aspectClass; } public BaseFunction getImplementation() { @@ -79,10 +99,6 @@ public class SkylarkDefinedAspect implements SkylarkExportable, SkylarkAspect { return attributeAspects; } - public Environment getFuncallEnv() { - return funcallEnv; - } - public ImmutableList<Attribute> getAttributes() { return attributes; } |