Skip to content

Commit

Permalink
Patch RuleContext for android_binary.deps to restore legacy behavior.
Browse files Browse the repository at this point in the history
This should be fixed once android_binary is cleaned up.

PiperOrigin-RevId: 330981388
  • Loading branch information
katre authored and laurentlb committed Oct 2, 2020
1 parent aa0d97c commit 32c88da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1021,9 +1021,27 @@ ImmutableListMultimap<BuildConfiguration, C> getPrerequisitesByConfiguration(
* specified attribute.
*/
public List<? extends TransitiveInfoCollection> getPrerequisites(String attributeName) {
if (!attributes().has(attributeName)) {
return ImmutableList.of();
}

List<ConfiguredTargetAndData> prerequisiteConfiguredTargets;
if (getRule().getRuleClass().equals("android_binary")
&& attributeName.equals("deps")
&& attributes().getAttributeDefinition(attributeName).getTransitionFactory().isSplit()) {
// TODO(b/168038145): Restore legacy behavior of returning the prerequisites from the first
// portion of the split transition.
// Callers should be identified, cleaned up, and this check removed.
Map<Optional<String>, List<ConfiguredTargetAndData>> map =
getSplitPrerequisiteConfiguredTargetAndTargets(attributeName);
prerequisiteConfiguredTargets =
map.isEmpty() ? ImmutableList.of() : map.entrySet().iterator().next().getValue();
} else {
prerequisiteConfiguredTargets = getPrerequisiteConfiguredTargets(attributeName);
}

return Lists.transform(
getPrerequisiteConfiguredTargets(attributeName),
ConfiguredTargetAndData::getConfiguredTarget);
prerequisiteConfiguredTargets, ConfiguredTargetAndData::getConfiguredTarget);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ListMultimap;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.cmdline.Label;
Expand Down Expand Up @@ -121,6 +119,8 @@ public void testAndroidSplitTransition() throws Exception {

// The regular ctx.attr.deps should be a single list with all the branches of the split merged
// together (i.e. for aspects).
// TODO(b/168049724): Due to b/168038145, this is now only a single split. Revert when fixed.
/*
@SuppressWarnings("unchecked")
List<ConfiguredTarget> attrDeps = (List<ConfiguredTarget>) myInfo.getValue("attr_deps");
assertThat(attrDeps).hasSize(4);
Expand All @@ -130,9 +130,12 @@ public void testAndroidSplitTransition() throws Exception {
}
assertThat(attrDepsMap).valuesForKey("k8").hasSize(2);
assertThat(attrDepsMap).valuesForKey("armeabi-v7a").hasSize(2);
*/

// Check that even though my_rule.dep is defined as a single label, ctx.attr.dep is still a list
// with multiple ConfiguredTarget objects because of the two different CPUs.
// TODO(b/168049724): Due to b/168038145, this is now only a single split. Revert when fixed.
/*
@SuppressWarnings("unchecked")
List<ConfiguredTarget> attrDep = (List<ConfiguredTarget>) myInfo.getValue("attr_dep");
assertThat(attrDep).hasSize(2);
Expand All @@ -142,6 +145,7 @@ public void testAndroidSplitTransition() throws Exception {
}
assertThat(attrDepMap).valuesForKey("k8").hasSize(1);
assertThat(attrDepMap).valuesForKey("armeabi-v7a").hasSize(1);
*/

// Check that the deps were correctly accessed from within Starlark.
@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 32c88da

Please sign in to comment.