diff options
author | 2017-02-13 21:25:25 +0000 | |
---|---|---|
committer | 2017-02-14 14:21:53 +0000 | |
commit | 57a8e6674e5bd5abc3a54a7771f09322f19413c7 (patch) | |
tree | 048d4aa8d1ff2ff54aeca4b3166ee48abf88cfa1 /src/test/java/com | |
parent | b6d1123f2320bc60d1e620f00cade48d980d39ee (diff) |
Rollback of commit cdbad585187dfe7bbb4d69ad68a1baf852beb691.
*** 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/test/java/com')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/testutil/BuildRuleWithDefaultsBuilder.java | 23 |
1 files changed, 14 insertions, 9 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 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 |