aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java
diff options
context:
space:
mode:
authorGravatar Michael Staib <mstaib@google.com>2017-02-10 19:08:13 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2017-02-13 11:31:30 +0000
commitcdbad585187dfe7bbb4d69ad68a1baf852beb691 (patch)
tree7b128ea723235d76a162cf71df012314b2cb2f66 /src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java
parentaa1d31da27793d4c29bfa4dec12d1ae9ab20426b (diff)
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 exotic things based on the type. But most sites can avoid having to enumerate all the types they work with explicitly. This causes LABEL_DICT_UNARY to start being treated like the other label types, which means that CcToolchainSuiteRule and JavaRuntimeSuiteRule need to include a set of allowed file types (none, in their case). -- PiperOrigin-RevId: 147175424 MOS_MIGRATED_REVID=147175424
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java23
1 files changed, 9 insertions, 14 deletions
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 7db103eba3..e0e6b77407 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,6 +20,8 @@ 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;
@@ -57,8 +59,8 @@ public class BuildRuleWithDefaultsBuilder extends BuildRuleBuilder {
*/
private String getDummyFileLabel(String rulePkg, String filePkg, String extension,
Type<?> attrType) {
- boolean isInput = (attrType == BuildType.LABEL || attrType == BuildType.LABEL_LIST);
- String fileName = (isInput ? "dummy_input" : "dummy_output") + extension;
+ boolean isOutput = attrType.getLabelClass() == LabelClass.OUTPUT;
+ String fileName = (isOutput ? "dummy_output" : "dummy_input") + extension;
generateFiles.add(filePkg + "/" + fileName);
if (rulePkg.equals(filePkg)) {
return ":" + fileName;
@@ -122,7 +124,7 @@ public class BuildRuleWithDefaultsBuilder extends BuildRuleBuilder {
}
}
if (label != null) {
- if (attrType == BuildType.LABEL_LIST || attrType == BuildType.OUTPUT_LIST) {
+ if (attrType instanceof ListType<?>) {
addMultiValueAttributes(attribute.getName(), label);
} else {
setSingleValueAttribute(attribute.getName(), label);
@@ -175,17 +177,10 @@ public class BuildRuleWithDefaultsBuilder extends BuildRuleBuilder {
public BuildRuleWithDefaultsBuilder populateAttributes(String rulePkg, boolean heuristics) {
for (Attribute attribute : ruleClass.getAttributes()) {
if (attribute.isMandatory()) {
- 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) {
+ 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
populateLabelAttribute(rulePkg, attribute);
} else {
// Non label type attributes