aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar janakr <janakr@google.com>2018-03-10 19:10:00 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-10 19:11:58 -0800
commit27bb6dda6051aa5253488497053f18a0c37dc645 (patch)
tree4e61b3795ce6d01fa8d25f1416f1a0d0601dae3a /src/main
parent12b78feca3d131f3d76226deb694535357230bdd (diff)
Add RuleContext#getPrerequisiteConfiguredTargetAndTarget and use it in GoTest to avoid calling ConfiguredTarget#getConfiguration.
PiperOrigin-RevId: 188623273
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java17
1 files changed, 12 insertions, 5 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 ab0bb5e183..1ae324663e 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
@@ -375,10 +375,6 @@ public final class RuleContext extends TargetContext
return Multimaps.transformValues(targetMap, ConfiguredTargetAndData::getConfiguredTarget);
}
- private List<? extends TransitiveInfoCollection> getDeps(String key) {
- return Lists.transform(targetMap.get(key), ConfiguredTargetAndData::getConfiguredTarget);
- }
-
private List<ConfiguredTargetAndData> getConfiguredTargetAndTargetDeps(String key) {
return targetMap.get(key);
}
@@ -852,8 +848,19 @@ public final class RuleContext extends TargetContext
* assertion will be raised. Returns null if the attribute is empty.
*/
public TransitiveInfoCollection getPrerequisite(String attributeName, Mode mode) {
+ ConfiguredTargetAndData result = getPrerequisiteConfiguredTargetAndData(attributeName, mode);
+ return result == null ? null : result.getConfiguredTarget();
+ }
+
+ /**
+ * Returns the {@link ConfiguredTargetAndData} that feeds ino this target through the specified
+ * attribute. Note that you need to specify the correct mode for the attribute, otherwise an
+ * assertion will be raised. Returns null if the attribute is empty.
+ */
+ public ConfiguredTargetAndData getPrerequisiteConfiguredTargetAndData(
+ String attributeName, Mode mode) {
checkAttribute(attributeName, mode);
- List<? extends TransitiveInfoCollection> elements = getDeps(attributeName);
+ List<ConfiguredTargetAndData> elements = getConfiguredTargetAndTargetDeps(attributeName);
if (elements.size() > 1) {
throw new IllegalStateException(getRuleClassNameForLogging() + " attribute " + attributeName
+ " produces more than one prerequisite");