Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the classic query package-loading cutoff optimization with external workspaces. #12595

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"