Skip to content

Commit

Permalink
Check for null build file returned from getBuildFileForPackage.
Browse files Browse the repository at this point in the history
This can occur in genqueries when a referenced package isn't in the scope.

PiperOrigin-RevId: 178038701
  • Loading branch information
katre authored and Copybara-Service committed Dec 6, 2017
1 parent 21fdc48 commit a2d2615
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,18 +416,21 @@ public ThreadSafeMutableSet<Target> getBuildFiles(
Path buildFileForSubinclude =
packageProvider.getBuildFileForPackage(
subincludeTarget.getLabel().getLabel().getPackageIdentifier());
Label buildFileLabel =
Label.createUnvalidated(
subincludeTarget.getLabel().getLabel().getPackageIdentifier(),
buildFileForSubinclude.getBaseName());
addIfUniqueLabel(
getNode(new FakeLoadTarget(buildFileLabel, pkg)), seenLabels, dependentFiles);
if (buildFileForSubinclude != null) {
Label buildFileLabel =
Label.createUnvalidated(
subincludeTarget.getLabel().getLabel().getPackageIdentifier(),
buildFileForSubinclude.getBaseName());
addIfUniqueLabel(
getNode(new FakeLoadTarget(buildFileLabel, pkg)), seenLabels, dependentFiles);
}
}
}
}
}
return dependentFiles;
}

@Override
protected void preloadOrThrow(QueryExpression caller, Collection<String> patterns)
throws TargetParsingException, InterruptedException {
Expand Down
24 changes: 24 additions & 0 deletions src/test/shell/integration/bazel_query_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,30 @@ EOF
expect_not_log "//foo:BUILD$"
}

function test_buildfile_in_genquery() {
mkdir -p papaya
cat > papaya/BUILD <<EOF
exports_files(['papaya.bzl'])
EOF
cat > papaya/papaya.bzl <<EOF
foo = 1
EOF
mkdir -p honeydew
cat > honeydew/BUILD <<EOF
load('//papaya:papaya.bzl', 'foo')
sh_library(name='honeydew', deps=[':pineapple'])
sh_library(name='pineapple')
genquery(name='q',
scope=[':honeydew'],
strict=0,
expression='buildfiles(//honeydew:all)')
EOF

bazel build //honeydew:q >& $TEST_log || fail "Expected success"
cat bazel-bin/honeydew/q > $TEST_log
expect_log_once "^//honeydew:BUILD$"
}

function tear_down() {
bazel shutdown
}
Expand Down

0 comments on commit a2d2615

Please sign in to comment.