Skip to content

Commit

Permalink
Fix cquery --transitions=lite crash
Browse files Browse the repository at this point in the history
The logic assumed all edges had attributes. Visibility edges
don't.

This only applies to targets that set visibility to a package group
(so there's technically an edge from the target to the package
group's label). Generic visibility like public, private doesn't trigger
this.

PiperOrigin-RevId: 462672353
Change-Id: I57173129dcf6f4ac6de617c5d61f5a7b3df05e63
  • Loading branch information
gregestren authored and copybara-github committed Jul 22, 2022
1 parent 73a55fd commit 3b1c8ce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.analysis.DependencyKey;
import com.google.devtools.build.lib.analysis.DependencyKind;
import com.google.devtools.build.lib.analysis.DependencyKind.NonAttributeDependencyKind;
import com.google.devtools.build.lib.analysis.DependencyKind.ToolchainDependencyKind;
import com.google.devtools.build.lib.analysis.DependencyResolver;
import com.google.devtools.build.lib.analysis.InconsistentAspectOrderException;
Expand Down Expand Up @@ -146,6 +147,11 @@ public ImmutableSet<ResolvedTransition> dependencies(KeyedConfiguredTarget keyed
for (Map.Entry<DependencyKind, DependencyKey> attributeAndDep : deps.entries()) {
DependencyKey dep = attributeAndDep.getValue();

if (attributeAndDep.getKey() instanceof NonAttributeDependencyKind) {
// No attribute edge to report.
continue;
}

String dependencyName;
if (DependencyKind.isToolchain(attributeAndDep.getKey())) {
ToolchainDependencyKind tdk = (ToolchainDependencyKind) attributeAndDep.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,33 @@ public void testTransitions_noTransitions() throws Exception {
+ " or 'full'");
}

@Test
public void nonAttributeDependencySkipped() throws Exception {
setUpRules();

// A visibility dependency on a package_group produces a
// DependencyKind.NonAttributeDependencyKind. This test checks that the existence of those
// attribute types doesn't crash cquery.

writeFile(
"test/BUILD",
"package_group(",
" name = 'custom_visibility',",
" packages = ['//test/...'],",
")",
"simple_rule(",
" name = 'child',",
")",
"simple_rule(",
" name = 'parent',",
" deps = [':child'],",
" visibility = [':custom_visibility'],",
")");

assertThat(getOutput("deps(//test:parent)", Transitions.LITE)).isNotNull();
assertThat(events).isEmpty();
}

private void setUpRules() throws Exception {
TransitionFactory<RuleTransitionData> infixTrimmingTransitionFactory =
(ruleData) -> {
Expand Down

0 comments on commit 3b1c8ce

Please sign in to comment.