aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Michael Staib <mstaib@google.com>2017-02-13 21:25:25 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2017-02-14 14:21:53 +0000
commit57a8e6674e5bd5abc3a54a7771f09322f19413c7 (patch)
tree048d4aa8d1ff2ff54aeca4b3166ee48abf88cfa1 /src
parentb6d1123f2320bc60d1e620f00cade48d980d39ee (diff)
*** Reason for rollback *** Breaks Skylark aspects running over rules with LABEL_DICT_UNARY attributes. *** Original change description *** Refactoring: Types report what class of labels they contain. Currently label-type attributes are detected in many places across the codebase by simply reference-comparing against each of the label types. This CL aims to generalize most of these cases, moving the encoding of this logic into a single place (Type/BuildType itself). Not all of these cases can be made general without further refactoring, and some perhaps shouldn't be - serialization and Skylark rule context, for example, need to do... -- PiperOrigin-RevId: 147385072 MOS_MIGRATED_REVID=147385072
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java29
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java45
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/Attribute.java29
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/BuildType.java29
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/DependencyFilter.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java13
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteRule.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeSuiteRule.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/Type.java54
-rw-r--r--src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java23
12 files changed, 81 insertions, 163 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
index 656ca2595f..937cf74c45 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -81,7 +81,6 @@ import com.google.devtools.build.lib.rules.fileset.FilesetProvider;
import com.google.devtools.build.lib.shell.ShellUtils;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Type;
-import com.google.devtools.build.lib.syntax.Type.LabelClass;
import com.google.devtools.build.lib.util.FileTypeSet;
import com.google.devtools.build.lib.util.OrderedSetMultimap;
import com.google.devtools.build.lib.util.Preconditions;
@@ -1084,7 +1083,8 @@ public final class RuleContext extends TargetContext
throw new IllegalStateException(getRule().getLocation() + ": " + getRuleClassNameForLogging()
+ " attribute " + attributeName + " is not defined");
}
- if (attributeDefinition.getType().getLabelClass() != LabelClass.DEPENDENCY) {
+ if (!(attributeDefinition.getType() == BuildType.LABEL
+ || attributeDefinition.getType() == BuildType.LABEL_LIST)) {
throw new IllegalStateException(getRuleClassNameForLogging() + " attribute " + attributeName
+ " is not a label type attribute");
}
@@ -1125,7 +1125,8 @@ public final class RuleContext extends TargetContext
throw new IllegalStateException(getRule().getLocation() + ": " + getRuleClassNameForLogging()
+ " attribute " + attributeName + " is not defined");
}
- if (attributeDefinition.getType().getLabelClass() != LabelClass.DEPENDENCY) {
+ if (!(attributeDefinition.getType() == BuildType.LABEL
+ || attributeDefinition.getType() == BuildType.LABEL_LIST)) {
throw new IllegalStateException(getRuleClassNameForLogging() + " attribute " + attributeName
+ " is not a label type attribute");
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java b/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java
index 33f7d348f6..86d736d60a 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java
@@ -36,8 +36,6 @@ import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.syntax.Type;
-import com.google.devtools.build.lib.syntax.Type.LabelClass;
-import com.google.devtools.build.lib.syntax.Type.LabelVisitor;
import com.google.devtools.build.lib.util.Preconditions;
import java.util.Collection;
@@ -741,7 +739,7 @@ public class ConstraintSemantics {
AttributeMap attributes = ruleContext.attributes();
for (String attr : attributes.getAttributeNames()) {
Attribute attrDef = attributes.getAttributeDefinition(attr);
- if (attrDef.getType().getLabelClass() != LabelClass.DEPENDENCY
+ if ((attrDef.getType() != BuildType.LABEL && attrDef.getType() != BuildType.LABEL_LIST)
|| attrDef.skipConstraintsOverride()) {
continue;
}
@@ -821,22 +819,21 @@ public class ConstraintSemantics {
* Adds all label values from the given select to the given set. Automatically handles different
* value types (e.g. labels vs. label lists).
*/
- private static void addSelectValuesToSet(BuildType.Selector<?> select, final Set<Label> set) {
+ private static void addSelectValuesToSet(BuildType.Selector<?> select, Set<Label> set) {
Type<?> type = select.getOriginalType();
- LabelVisitor visitor = new LabelVisitor() {
- @Override
- public void visit(Label label) {
- set.add(label);
+ if (type == BuildType.LABEL || type == BuildType.NODEP_LABEL) {
+ set.addAll(((BuildType.Selector<Label>) select).getEntries().values());
+ } else if (type == BuildType.LABEL_LIST || type == BuildType.NODEP_LABEL_LIST) {
+ for (List<Label> labels : ((BuildType.Selector<List<Label>>) select).getEntries().values()) {
+ set.addAll(labels);
}
- };
- for (Object value : select.getEntries().values()) {
- try {
- type.visitLabels(visitor, value);
- } catch (InterruptedException ex) {
- // Because the LabelVisitor does not throw InterruptedException, it should not be thrown
- // by visitLabels here.
- throw new AssertionError(ex);
+ } else if (type == BuildType.LABEL_DICT_UNARY) {
+ for (Map<String, Label> mapEntry :
+ ((BuildType.Selector<Map<String, Label>>) select).getEntries().values()) {
+ set.addAll(mapEntry.values());
}
+ } else {
+ throw new IllegalStateException("Expected a label-based type for this select");
}
}
}
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 a305e515d2..338d4bfce8 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
@@ -25,12 +25,11 @@ import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.ConfigurationFragmentPolicy.MissingFragmentPolicy;
import com.google.devtools.build.lib.syntax.Type;
-import com.google.devtools.build.lib.syntax.Type.LabelClass;
-import com.google.devtools.build.lib.syntax.Type.LabelVisitor;
import com.google.devtools.build.lib.util.Preconditions;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
@@ -191,36 +190,32 @@ public final class AspectDefinition {
* Collects all attribute labels from the specified aspectDefinition.
*/
public static void addAllAttributesOfAspect(
- final Rule from,
- final Multimap<Attribute, Label> labelBuilder,
+ Rule from,
+ Multimap<Attribute, Label> labelBuilder,
Aspect aspect,
DependencyFilter dependencyFilter) {
ImmutableMap<String, Attribute> attributes = aspect.getDefinition().getAttributes();
- for (final Attribute aspectAttribute : attributes.values()) {
+ for (Attribute aspectAttribute : attributes.values()) {
if (!dependencyFilter.apply(aspect, aspectAttribute)) {
continue;
}
- Type type = aspectAttribute.getType();
- if (type.getLabelClass() != LabelClass.DEPENDENCY) {
- continue;
- }
- try {
- type.visitLabels(
- new LabelVisitor() {
- @Override
- public void visit(Label label) {
- Label repositoryRelative = maybeGetRepositoryRelativeLabel(from, label);
- if (repositoryRelative == null) {
- return;
- }
- labelBuilder.put(aspectAttribute, repositoryRelative);
- }
- },
+ if (aspectAttribute.getType() == BuildType.LABEL) {
+ Label label = maybeGetRepositoryRelativeLabel(
+ from, BuildType.LABEL.cast(aspectAttribute.getDefaultValue(from)));
+ if (label != null) {
+ labelBuilder.put(aspectAttribute, label);
+ }
+ } else if (aspectAttribute.getType() == BuildType.LABEL_LIST) {
+ List<Label> defaultLabels = BuildType.LABEL_LIST.cast(
aspectAttribute.getDefaultValue(from));
- } catch (InterruptedException ex) {
- // Because the LabelVisitor does not throw InterruptedException, it should not be thrown
- // by visitLabels here.
- throw new AssertionError(ex);
+ if (defaultLabels != null) {
+ for (Label defaultLabel : defaultLabels) {
+ Label label = maybeGetRepositoryRelativeLabel(from, defaultLabel);
+ if (label != null) {
+ labelBuilder.put(aspectAttribute, label);
+ }
+ }
+ }
}
}
}
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 f5e9b95eb9..2288a76210 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
@@ -36,7 +36,6 @@ import com.google.devtools.build.lib.syntax.Runtime;
import com.google.devtools.build.lib.syntax.SkylarkCallbackFunction;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.syntax.Type.ConversionException;
-import com.google.devtools.build.lib.syntax.Type.LabelClass;
import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.util.FileTypeSet;
import com.google.devtools.build.lib.util.Preconditions;
@@ -508,7 +507,7 @@ public final class Attribute implements Comparable<Attribute> {
* Makes the built attribute producing a single artifact.
*/
public Builder<TYPE> singleArtifact() {
- Preconditions.checkState(type.getLabelClass() == LabelClass.DEPENDENCY,
+ Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
"attribute '%s' must be a label-valued type", name);
return setPropertyFlag(PropertyFlag.SINGLE_ARTIFACT, "single_artifact");
}
@@ -518,7 +517,7 @@ public final class Attribute implements Comparable<Attribute> {
* This flag is introduced to handle plugins, do not use it in other cases.
*/
public Builder<TYPE> silentRuleClassFilter() {
- Preconditions.checkState(type.getLabelClass() == LabelClass.DEPENDENCY,
+ Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
"must be a label-valued type");
return setPropertyFlag(PropertyFlag.SILENT_RULECLASS_FILTER, "silent_ruleclass_filter");
}
@@ -527,7 +526,7 @@ public final class Attribute implements Comparable<Attribute> {
* Skip analysis time filetype check. Don't use it if avoidable.
*/
public Builder<TYPE> skipAnalysisTimeFileTypeCheck() {
- Preconditions.checkState(type.getLabelClass() == LabelClass.DEPENDENCY,
+ Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
"must be a label-valued type");
return setPropertyFlag(PropertyFlag.SKIP_ANALYSIS_TIME_FILETYPE_CHECK,
"skip_analysis_time_filetype_check");
@@ -802,7 +801,7 @@ public final class Attribute implements Comparable<Attribute> {
* other words, it works for 'deps' attributes, but not 'srcs' attributes.
*/
public Builder<TYPE> allowedRuleClasses(Predicate<RuleClass> allowedRuleClasses) {
- Preconditions.checkState(type.getLabelClass() == LabelClass.DEPENDENCY,
+ Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
"must be a label-valued type");
propertyFlags.add(PropertyFlag.STRICT_LABEL_CHECKING);
allowedRuleClassesForLabels = allowedRuleClasses;
@@ -832,7 +831,7 @@ public final class Attribute implements Comparable<Attribute> {
* other words, it works for 'deps' attributes, but not 'srcs' attributes.
*/
public Builder<TYPE> allowedFileTypes(FileTypeSet allowedFileTypes) {
- Preconditions.checkState(type.getLabelClass() == LabelClass.DEPENDENCY,
+ Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
"must be a label-valued type");
propertyFlags.add(PropertyFlag.STRICT_LABEL_CHECKING);
allowedFileTypesForLabels = Preconditions.checkNotNull(allowedFileTypes);
@@ -887,7 +886,7 @@ public final class Attribute implements Comparable<Attribute> {
* other words, it works for 'deps' attributes, but not 'srcs' attributes.
*/
public Builder<TYPE> allowedRuleClassesWithWarning(Predicate<RuleClass> allowedRuleClasses) {
- Preconditions.checkState(type.getLabelClass() == LabelClass.DEPENDENCY,
+ Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
"must be a label-valued type");
propertyFlags.add(PropertyFlag.STRICT_LABEL_CHECKING);
allowedRuleClassesForLabelsWarning = allowedRuleClasses;
@@ -915,7 +914,7 @@ public final class Attribute implements Comparable<Attribute> {
*/
public final Builder<TYPE> mandatoryNativeProvidersList(
Iterable<? extends Iterable<Class<? extends TransitiveInfoProvider>>> providersList) {
- Preconditions.checkState(type.getLabelClass() == LabelClass.DEPENDENCY,
+ Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
"must be a label-valued type");
ImmutableList.Builder<ImmutableList<Class<? extends TransitiveInfoProvider>>> listBuilder
= ImmutableList.builder();
@@ -942,7 +941,7 @@ public final class Attribute implements Comparable<Attribute> {
*/
public Builder<TYPE> mandatoryProvidersList(
Iterable<? extends Iterable<SkylarkProviderIdentifier>> providersList){
- Preconditions.checkState(type.getLabelClass() == LabelClass.DEPENDENCY,
+ Preconditions.checkState((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST),
"must be a label-valued type");
ImmutableList.Builder<ImmutableSet<SkylarkProviderIdentifier>> listBuilder
= ImmutableList.builder();
@@ -1087,13 +1086,13 @@ public final class Attribute implements Comparable<Attribute> {
// do not modify this.allowedFileTypesForLabels, instead create a copy.
FileTypeSet allowedFileTypesForLabels = this.allowedFileTypesForLabels;
- if (type.getLabelClass() == LabelClass.DEPENDENCY) {
+ if ((type == BuildType.LABEL) || (type == BuildType.LABEL_LIST)) {
if (isPrivateAttribute(name) && allowedFileTypesForLabels == null) {
allowedFileTypesForLabels = FileTypeSet.ANY_FILE;
}
Preconditions.checkNotNull(
allowedFileTypesForLabels, "allowedFileTypesForLabels not set for %s", name);
- } else if (type.getLabelClass() == LabelClass.OUTPUT) {
+ } else if ((type == BuildType.OUTPUT) || (type == BuildType.OUTPUT_LIST)) {
// TODO(bazel-team): Set the default to no file type and make explicit calls instead.
if (allowedFileTypesForLabels == null) {
allowedFileTypesForLabels = FileTypeSet.ANY_FILE;
@@ -1770,8 +1769,8 @@ public final class Attribute implements Comparable<Attribute> {
Preconditions.checkNotNull(configTransition);
Preconditions.checkArgument(
(configTransition == ConfigurationTransition.NONE && configurator == null)
- || type.getLabelClass() == LabelClass.DEPENDENCY
- || type.getLabelClass() == LabelClass.NONDEP_REFERENCE,
+ || type == BuildType.LABEL || type == BuildType.LABEL_LIST
+ || type == BuildType.NODEP_LABEL || type == BuildType.NODEP_LABEL_LIST,
"Configuration transitions can only be specified for label or label list attributes");
Preconditions.checkArgument(
isLateBound(name) == (defaultValue instanceof LateBoundDefault),
@@ -1976,8 +1975,8 @@ public final class Attribute implements Comparable<Attribute> {
* Returns true if this attribute's value can be influenced by the build configuration.
*/
public boolean isConfigurable() {
- // Output types are excluded because of Rule#populateExplicitOutputFiles.
- return !(type.getLabelClass() == LabelClass.OUTPUT
+ return !(type == BuildType.OUTPUT // Excluded because of Rule#populateExplicitOutputFiles.
+ || type == BuildType.OUTPUT_LIST
|| getPropertyFlag(PropertyFlag.NONCONFIGURABLE));
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/BuildType.java b/src/main/java/com/google/devtools/build/lib/packages/BuildType.java
index 051b7e033f..ae3b1214ed 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/BuildType.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/BuildType.java
@@ -27,7 +27,6 @@ import com.google.devtools.build.lib.syntax.SelectorValue;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.syntax.Type.ConversionException;
import com.google.devtools.build.lib.syntax.Type.DictType;
-import com.google.devtools.build.lib.syntax.Type.LabelClass;
import com.google.devtools.build.lib.syntax.Type.ListType;
import java.util.Collections;
import java.util.LinkedHashMap;
@@ -48,7 +47,7 @@ public final class BuildType {
* attributes that it's worth treating them specially (and providing support
* for resolution of relative-labels in the <code>convert()</code> method).
*/
- public static final Type<Label> LABEL = new LabelType(LabelClass.DEPENDENCY);
+ public static final Type<Label> LABEL = new LabelType();
/**
* The type of a dictionary of {@linkplain #LABEL labels}.
*/
@@ -63,7 +62,7 @@ public final class BuildType {
* certain rules want to verify the type of a target referenced by one of their attributes, but
* if there was a dependency edge there, it would be a circular dependency.
*/
- public static final Type<Label> NODEP_LABEL = new LabelType(LabelClass.NONDEP_REFERENCE);
+ public static final Type<Label> NODEP_LABEL = new LabelType();
/**
* The type of a list of {@linkplain #NODEP_LABEL labels} that do not cause
* dependencies.
@@ -137,7 +136,8 @@ public final class BuildType {
* Returns whether the specified type is a label type or not.
*/
public static boolean isLabelType(Type<?> type) {
- return type.getLabelClass() != LabelClass.NONE;
+ return type == LABEL || type == LABEL_LIST || type == LABEL_DICT_UNARY
+ || type == NODEP_LABEL || type == NODEP_LABEL_LIST || type == FILESET_ENTRY_LIST;
}
/**
@@ -182,11 +182,6 @@ public final class BuildType {
}
@Override
- public LabelClass getLabelClass() {
- return LabelClass.FILESET_ENTRY;
- }
-
- @Override
public FilesetEntry getDefaultValue() {
return null;
}
@@ -200,12 +195,6 @@ public final class BuildType {
}
private static class LabelType extends Type<Label> {
- private final LabelClass labelClass;
-
- LabelType(LabelClass labelClass) {
- this.labelClass = labelClass;
- }
-
@Override
public Label cast(Object value) {
return (Label) value;
@@ -227,11 +216,6 @@ public final class BuildType {
}
@Override
- public LabelClass getLabelClass() {
- return labelClass;
- }
-
- @Override
public Label convert(Object x, Object what, Object context)
throws ConversionException {
if (x instanceof Label) {
@@ -343,11 +327,6 @@ public final class BuildType {
}
@Override
- public LabelClass getLabelClass() {
- return LabelClass.OUTPUT;
- }
-
- @Override
public String toString() {
return "output";
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/DependencyFilter.java b/src/main/java/com/google/devtools/build/lib/packages/DependencyFilter.java
index 88fe6d4157..a5d41ee631 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/DependencyFilter.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/DependencyFilter.java
@@ -15,7 +15,6 @@ package com.google.devtools.build.lib.packages;
import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition;
import com.google.devtools.build.lib.packages.DependencyFilter.AttributeInfoProvider;
-import com.google.devtools.build.lib.syntax.Type.LabelClass;
import com.google.devtools.build.lib.util.BinaryPredicate;
/**
@@ -39,8 +38,8 @@ public abstract class DependencyFilter
new DependencyFilter() {
@Override
public boolean apply(AttributeInfoProvider infoProvider, Attribute attribute) {
- // getConfigurationTransition() is only defined for labels which introduce a dependency.
- if (attribute.getType().getLabelClass() != LabelClass.DEPENDENCY) {
+ // isHostConfiguration() is only defined for labels and label lists.
+ if (attribute.getType() != BuildType.LABEL && attribute.getType() != BuildType.LABEL_LIST) {
return true;
}
@@ -63,7 +62,8 @@ public abstract class DependencyFilter
new DependencyFilter() {
@Override
public boolean apply(AttributeInfoProvider infoProvider, Attribute attribute) {
- return attribute.getType().getLabelClass() != LabelClass.NONDEP_REFERENCE;
+ return attribute.getType() != BuildType.NODEP_LABEL
+ && attribute.getType() != BuildType.NODEP_LABEL_LIST;
}
};
/**
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java
index 08113b6f20..abec031476 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkAttr.java
@@ -46,7 +46,6 @@ import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor;
import com.google.devtools.build.lib.syntax.SkylarkType;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.syntax.Type.ConversionException;
-import com.google.devtools.build.lib.syntax.Type.LabelClass;
import com.google.devtools.build.lib.syntax.UserDefinedFunction;
import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.util.FileTypeSet;
@@ -236,7 +235,7 @@ public final class SkylarkAttr {
Object fileTypesObj = arguments.get(ALLOW_SINGLE_FILE_ARG);
setAllowedFileTypes(ALLOW_SINGLE_FILE_ARG, fileTypesObj, ast, builder);
builder.setPropertyFlag("SINGLE_ARTIFACT");
- } else if (type.getLabelClass() == LabelClass.DEPENDENCY) {
+ } else if (type.equals(BuildType.LABEL) || type.equals(BuildType.LABEL_LIST)) {
builder.allowedFileTypes(FileTypeSet.NO_FILE);
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
index 76ee3c9253..7e7b69cda1 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
@@ -64,7 +64,6 @@ import com.google.devtools.build.lib.syntax.SkylarkDict;
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.syntax.SkylarkType;
import com.google.devtools.build.lib.syntax.Type;
-import com.google.devtools.build.lib.syntax.Type.LabelClass;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.ArrayList;
@@ -207,7 +206,7 @@ public final class SkylarkRuleContext {
for (Attribute a : attributes) {
String attrName = a.getName();
Type<?> type = a.getType();
- if (type.getLabelClass() != LabelClass.OUTPUT) {
+ if (type != BuildType.OUTPUT && type != BuildType.OUTPUT_LIST) {
continue;
}
ImmutableList.Builder<Artifact> artifactsBuilder = ImmutableList.builder();
@@ -291,7 +290,7 @@ public final class SkylarkRuleContext {
for (Attribute a : attributes) {
Type<?> type = a.getType();
Object val = attributeValueExtractor.apply(a);
- if (type.getLabelClass() != LabelClass.DEPENDENCY) {
+ if (type != BuildType.LABEL && type != BuildType.LABEL_LIST) {
attrBuilder.put(a.getPublicName(), val == null ? Runtime.NONE
// Attribute values should be type safe
: SkylarkType.convertToSkylark(val, null));
@@ -337,14 +336,10 @@ public final class SkylarkRuleContext {
prereq = Runtime.NONE;
}
attrBuilder.put(skyname, prereq);
- } else if (type == BuildType.LABEL_LIST
- || (type == BuildType.LABEL && a.hasSplitConfigurationTransition())) {
+ } else {
+ // Type.LABEL_LIST
List<?> allPrereq = ruleContext.getPrerequisites(a.getName(), Mode.DONT_CHECK);
attrBuilder.put(skyname, SkylarkList.createImmutable(allPrereq));
- } else {
- throw new IllegalArgumentException(
- "Can't transform attribute " + a.getName() + " of type " + type
- + " to a Skylark object");
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteRule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteRule.java
index 55244b470a..a08e6e0930 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteRule.java
@@ -22,7 +22,6 @@ import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder;
import com.google.devtools.build.lib.syntax.Type;
-import com.google.devtools.build.lib.util.FileTypeSet;
/**
* Definition of the {@code cc_toolchain_suite} rule.
@@ -35,7 +34,6 @@ public final class CcToolchainSuiteRule implements RuleDefinition {
.setUndocumented()
.add(attr("toolchains", BuildType.LABEL_DICT_UNARY)
.mandatory()
- .allowedFileTypes(FileTypeSet.NO_FILE)
.nonconfigurable("Used during configuration creation"))
.add(attr("proto", Type.STRING)
.nonconfigurable("Used during configuration creation"))
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeSuiteRule.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeSuiteRule.java
index 22de4df4a3..8b28e91c29 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeSuiteRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeSuiteRule.java
@@ -35,7 +35,7 @@ public final class JavaRuntimeSuiteRule implements RuleDefinition {
/* <!-- #BLAZE_RULE(java_runtime_suite).ATTRIBUTE(runtimes) -->
A map from each supported architecture to the corresponding <code>java_runtime</code>.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("runtimes", BuildType.LABEL_DICT_UNARY).allowedFileTypes(FileTypeSet.NO_FILE))
+ .add(attr("runtimes", BuildType.LABEL_DICT_UNARY))
/* <!-- #BLAZE_RULE(java_runtime_suite).ATTRIBUTE(default) -->
The default <code>java_runtime</code>, used if
<a href="${link java_runtime_suite.runtimes}"><code>runtimes</code></a>
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Type.java b/src/main/java/com/google/devtools/build/lib/syntax/Type.java
index 387794b40f..dbbfc79c42 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Type.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Type.java
@@ -15,7 +15,6 @@
package com.google.devtools.build.lib.syntax;
import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -140,31 +139,6 @@ public abstract class Type<T> {
*/
public abstract void visitLabels(LabelVisitor visitor, Object value) throws InterruptedException;
- /** Classifications of labels by their usage. */
- public enum LabelClass {
- /** Used for types which are not labels. */
- NONE,
- /** Used for types which use labels to declare a dependency. */
- DEPENDENCY,
- /**
- * Used for types which use labels to reference another target but do not declare a dependency,
- * in cases where doing so would cause a dependency cycle.
- */
- NONDEP_REFERENCE,
- /** Used for types which use labels to declare an output path. */
- OUTPUT,
- /**
- * Used for types which contain Fileset entries, which contain labels but do not produce
- * normal dependencies.
- */
- FILESET_ENTRY
- }
-
- /** Returns the class of labels contained by this type, if any. */
- public LabelClass getLabelClass() {
- return LabelClass.NONE;
- }
-
/**
* Implementation of concatenation for this type (e.g. "val1 + val2"). Returns null to
* indicate concatenation isn't supported.
@@ -449,8 +423,6 @@ public abstract class Type<T> {
private final Map<KeyT, ValueT> empty = ImmutableMap.of();
- private final LabelClass labelClass;
-
@Override
public void visitLabels(LabelVisitor visitor, Object value) throws InterruptedException {
for (Entry<KeyT, ValueT> entry : cast(value).entrySet()) {
@@ -461,24 +433,12 @@ public abstract class Type<T> {
public static <KEY, VALUE> DictType<KEY, VALUE> create(
Type<KEY> keyType, Type<VALUE> valueType) {
- LabelClass keyLabelClass = keyType.getLabelClass();
- LabelClass valueLabelClass = valueType.getLabelClass();
- Preconditions.checkArgument(
- keyLabelClass == LabelClass.NONE
- || valueLabelClass == LabelClass.NONE
- || keyLabelClass == valueLabelClass,
- "A DictType's keys and values must be the same class of label if both contain labels, "
- + "but the key type " + keyType + " contains " + keyLabelClass + " labels, while "
- + "the value type " + valueType + " contains " + valueLabelClass + " labels.");
- LabelClass labelClass = (keyLabelClass != LabelClass.NONE) ? keyLabelClass : valueLabelClass;
-
- return new DictType<>(keyType, valueType, labelClass);
+ return new DictType<>(keyType, valueType);
}
- private DictType(Type<KeyT> keyType, Type<ValueT> valueType, LabelClass labelClass) {
+ private DictType(Type<KeyT> keyType, Type<ValueT> valueType) {
this.keyType = keyType;
this.valueType = valueType;
- this.labelClass = labelClass;
}
public Type<KeyT> getKeyType() {
@@ -489,11 +449,6 @@ public abstract class Type<T> {
return valueType;
}
- @Override
- public LabelClass getLabelClass() {
- return labelClass;
- }
-
@SuppressWarnings("unchecked")
@Override
public Map<KeyT, ValueT> cast(Object value) {
@@ -556,11 +511,6 @@ public abstract class Type<T> {
}
@Override
- public LabelClass getLabelClass() {
- return elemType.getLabelClass();
- }
-
- @Override
public List<ElemT> getDefaultValue() {
return empty;
}
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java b/src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java
index e0e6b77407..7db103eba3 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java
@@ -20,8 +20,6 @@ import com.google.devtools.build.lib.packages.Attribute.AllowedValueSet;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.syntax.Type;
-import com.google.devtools.build.lib.syntax.Type.LabelClass;
-import com.google.devtools.build.lib.syntax.Type.ListType;
import com.google.devtools.build.lib.util.FileTypeSet;
import com.google.devtools.build.lib.util.Preconditions;
@@ -59,8 +57,8 @@ public class BuildRuleWithDefaultsBuilder extends BuildRuleBuilder {
*/
private String getDummyFileLabel(String rulePkg, String filePkg, String extension,
Type<?> attrType) {
- boolean isOutput = attrType.getLabelClass() == LabelClass.OUTPUT;
- String fileName = (isOutput ? "dummy_output" : "dummy_input") + extension;
+ boolean isInput = (attrType == BuildType.LABEL || attrType == BuildType.LABEL_LIST);
+ String fileName = (isInput ? "dummy_input" : "dummy_output") + extension;
generateFiles.add(filePkg + "/" + fileName);
if (rulePkg.equals(filePkg)) {
return ":" + fileName;
@@ -124,7 +122,7 @@ public class BuildRuleWithDefaultsBuilder extends BuildRuleBuilder {
}
}
if (label != null) {
- if (attrType instanceof ListType<?>) {
+ if (attrType == BuildType.LABEL_LIST || attrType == BuildType.OUTPUT_LIST) {
addMultiValueAttributes(attribute.getName(), label);
} else {
setSingleValueAttribute(attribute.getName(), label);
@@ -177,10 +175,17 @@ public class BuildRuleWithDefaultsBuilder extends BuildRuleBuilder {
public BuildRuleWithDefaultsBuilder populateAttributes(String rulePkg, boolean heuristics) {
for (Attribute attribute : ruleClass.getAttributes()) {
if (attribute.isMandatory()) {
- if (BuildType.isLabelType(attribute.getType())) {
- // TODO(bazel-team): actually an empty list would be fine in the case where
- // attribute instanceof ListType && !attribute.isNonEmpty(), but BuildRuleBuilder
- // doesn't support that, and it makes little sense anyway
+ if (attribute.getType() == BuildType.LABEL_LIST
+ || attribute.getType() == BuildType.OUTPUT_LIST) {
+ if (attribute.isNonEmpty()) {
+ populateLabelAttribute(rulePkg, attribute);
+ } else {
+ // TODO(bazel-team): actually here an empty list would be fine, but BuildRuleBuilder
+ // doesn't support that, and it makes little sense anyway
+ populateLabelAttribute(rulePkg, attribute);
+ }
+ } else if (attribute.getType() == BuildType.LABEL
+ || attribute.getType() == BuildType.OUTPUT) {
populateLabelAttribute(rulePkg, attribute);
} else {
// Non label type attributes