Skip to content

Commit

Permalink
[7.4.0] cquery: Factor RepositoryName into fetching ignored packages (b…
Browse files Browse the repository at this point in the history
…azelbuild#23727)

Previously this code was assuming that all cquery target patterns should
use the root repository's .bazelignore contents which was incorrect.

Because the way this manifested itself was that when cquery drives
populating the graph and when it queries it, it would use different
keys, this led to misleading messages about packages not being in scope.

Closes bazelbuild#22142.

PiperOrigin-RevId: 628477138
Change-Id: I84e3381848b843ca9813acdd0762a3b3e4711a90
  • Loading branch information
illicitonion authored Sep 24, 2024
1 parent edd4aad commit 45df2a5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.cmdline.TargetPattern;
import com.google.devtools.build.lib.collect.compacthashset.CompactHashSet;
Expand Down Expand Up @@ -253,12 +254,12 @@ private boolean isAliasConfiguredTarget(ConfiguredTargetKey key) throws Interrup
((ConfiguredTargetValue) getConfiguredTargetValue(key)).getConfiguredTarget());
}

public InterruptibleSupplier<ImmutableSet<PathFragment>>
getIgnoredPackagePrefixesPathFragments() {
public InterruptibleSupplier<ImmutableSet<PathFragment>> getIgnoredPackagePrefixesPathFragments(
RepositoryName repositoryName) {
return () -> {
IgnoredPackagePrefixesValue ignoredPackagePrefixesValue =
(IgnoredPackagePrefixesValue)
walkableGraphSupplier.get().getValue(IgnoredPackagePrefixesValue.key());
walkableGraphSupplier.get().getValue(IgnoredPackagePrefixesValue.key(repositoryName));
return ignoredPackagePrefixesValue == null
? ImmutableSet.of()
: ignoredPackagePrefixesValue.getPatterns();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public QueryTaskFuture<Void> getTargetsMatchingPattern(
Futures.catchingAsync(
patternToEval.evalAdaptedForAsync(
resolver,
getIgnoredPackagePrefixesPathFragments(),
getIgnoredPackagePrefixesPathFragments(patternToEval.getRepository()),
/* excludedSubdirectories= */ ImmutableSet.of(),
(Callback<Target>)
partialResult -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public QueryTaskFuture<Void> getTargetsMatchingPattern(
Futures.catchingAsync(
patternToEval.evalAdaptedForAsync(
resolver,
getIgnoredPackagePrefixesPathFragments(),
getIgnoredPackagePrefixesPathFragments(patternToEval.getRepository()),
/* excludedSubdirectories= */ ImmutableSet.of(),
(Callback<Target>)
partialResult -> {
Expand Down
30 changes: 30 additions & 0 deletions src/test/shell/integration/configured_query_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,36 @@ EOF
expect_log "@repo//:japanese"
}

function test_external_repo_scope_with_bazelignore() {
if [ "${PRODUCT_NAME}" != "bazel" ]; then
# Tests of external repositories only work under bazel.
return 0
fi

local -r dir=$FUNCNAME

mkdir -p $dir/repo
touch $dir/repo/REPO.bazel
cat > $dir/repo/BUILD <<EOF
sh_library(name='maple', deps=[':japanese'])
sh_library(name='japanese')
EOF

mkdir -p $dir/main
write_default_lockfile $dir/main/MODULE.bazel.lock
cat > $dir/main/WORKSPACE <<EOF
local_repository(name = "repo", path = "../repo")
EOF
touch $dir/main/BUILD
echo does_not_exist > $dir/main/.bazelignore

cd $dir/main
bazel cquery @repo//... &>"$TEST_log" || fail "Unexpected failure"
expect_not_log "no targets found beneath"
expect_log "@repo//:maple"
expect_log "@repo//:japanese"
}

function test_test_arg_in_bazelrc() {
local -r pkg=$FUNCNAME
mkdir -p $pkg
Expand Down

0 comments on commit 45df2a5

Please sign in to comment.