Remove special cases for "name" in implicit outputs code
fa97703c1edf ("allow skylark implicit output callbacks to use the rule
name") fixed a limitation of the skylark implicit outputs by adding a
special case for "name" to the implicit outputs code. Later,
015e5954157a ("Remove special handling of name attribute") fixed the
general problem of "name" being a special case in the attribute
map. Therefore, we can remove my original fix. We may also excise an
older special case in the implicit outputs templating code.
Change-Id: I606c9decd98a8df492d2359abe540d3263f99fe1
PiperOrigin-RevId: 152974774
diff --git a/src/main/java/com/google/devtools/build/lib/packages/ImplicitOutputsFunction.java b/src/main/java/com/google/devtools/build/lib/packages/ImplicitOutputsFunction.java
index 8d7ed33..9dea0b7 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/ImplicitOutputsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/ImplicitOutputsFunction.java
@@ -94,8 +94,6 @@
attrValues.put(attrName, value == null ? Runtime.NONE : value);
}
}
- // Add 'name' explicitly, since its value is not in the attribute map.
- attrValues.put("name", map.getName());
ClassObject attrs = NativeClassObjectConstructor.STRUCT.create(
attrValues,
"Attribute '%s' either doesn't exist "
@@ -297,10 +295,7 @@
* strings. Helper function for {@link #fromTemplates(Iterable)}.
*/
private static Set<String> attributeValues(AttributeMap rule, String attrName) {
- // Special case "name" since it's not treated as an attribute.
- if (attrName.equals("name")) {
- return singleton(rule.getName());
- } else if (attrName.equals("dirname")) {
+ if (attrName.equals("dirname")) {
PathFragment dir = PathFragment.create(rule.getName()).getParentDirectory();
return (dir.segmentCount() == 0) ? singleton("") : singleton(dir.getPathString() + "/");
} else if (attrName.equals("basename")) {
diff --git a/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java b/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java
index dab6130..b0a23b4 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java
@@ -437,10 +437,12 @@
ImmutableSet.<Class<?>>of(),
MissingFragmentPolicy.FAIL_ANALYSIS,
true,
+ attr("name", STRING).build(),
attr("outs", OUTPUT_LIST).build());
Map<String, Object> attributeValues = new HashMap<>();
attributeValues.put("outs", Collections.singletonList("explicit_out"));
+ attributeValues.put("name", "myrule");
Rule rule = createRule(ruleClassC, "myrule", attributeValues, testRuleLocation);
@@ -677,10 +679,12 @@
ImmutableSet.<Class<?>>of(),
MissingFragmentPolicy.FAIL_ANALYSIS,
true,
+ attr("name", STRING).build(),
attr("outs", OUTPUT_LIST).build());
Map<String, Object> attributeValues = new HashMap<>();
attributeValues.put("outs", ImmutableList.of("third", "fourth"));
+ attributeValues.put("name", "myrule");
Rule rule = createRule(ruleClassC, "myrule", attributeValues, testRuleLocation);