Skip to content

Commit

Permalink
Fix the classic query package-loading cutoff optimization with extern…
Browse files Browse the repository at this point in the history
…al workspaces.

A package's path fragment is not unambiguous when external workspaces are involved.

Fixes bazelbuild#12497.

Closes bazelbuild#12595.

PiperOrigin-RevId: 346048937
  • Loading branch information
benjaminp authored and copybara-github committed Dec 7, 2020
1 parent 81e570c commit 8555789
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ private void getTargetsMatchingPatternImpl(String pattern, Callback<Target> call
}
}

Set<PathFragment> packages = CompactHashSet.create();
Set<PackageIdentifier> packages = CompactHashSet.create();
for (Target target : targets) {
packages.add(target.getLabel().getPackageFragment());
packages.add(target.getLabel().getPackageIdentifier());
}

for (Target target : targets) {
Expand All @@ -205,7 +205,7 @@ private void getTargetsMatchingPatternImpl(String pattern, Callback<Target> call
} else if (target instanceof Rule) {
Rule rule = (Rule) target;
for (Label label : rule.getLabels(dependencyFilter)) {
if (!packages.contains(label.getPackageFragment())) {
if (!packages.contains(label.getPackageIdentifier())) {
continue; // don't cause additional package loading
}
try {
Expand Down
16 changes: 16 additions & 0 deletions src/test/shell/integration/bazel_query_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -853,4 +853,20 @@ function test_query_failure_exit_code_behavior() {
assert_equals 7 "$exit_code"
}

function test_unnecessary_external_workspaces_not_loaded() {
cat > WORKSPACE <<'EOF'
local_repository(
name = "notthere",
path = "/nope",
)
EOF
cat > BUILD <<'EOF'
filegroup(
name = "something",
srcs = ["@notthere"],
)
EOF
bazel query '//:*' || fail "Expected success"
}

run_suite "${PRODUCT_NAME} query tests"

0 comments on commit 8555789

Please sign in to comment.