Skip to content

Querying "//..." fails if a top-level target exists and any external dependency can't be fetched #12497

@jmillikin-stripe

Description

@jmillikin-stripe

Description of the problem / feature request:

If a workspace contains an external dependency that can't be fetched (upstream 404, shasum mismatch, whatever) then the presence of a build target in the top-level package will cause bazel query on //... to fail.

This happens regardless of whether the external dependency is in the transitive closure of the top-level target. As long as there is any top-level target, and in the workspace there is any target depending on the broken external dependency, then the query fails.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Given the following workspace:

# WORKSPACE
workspace(name = "bazeltest_query_toplevel")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "example_com_noexist",
    urls = ["https://example.com/noexist.tar.gz"],
    sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
)
# BUILD
genrule(
    name = "gen_toplevel",
    outs = ["gen_toplevel.txt"],
    cmd = "touch $@",
)
# subpkg/BUILD
genrule(
    name = "gen_subpkg",
    srcs = ["@example_com_noexist//:noexist.txt"],
    outs = ["gen_subpkg.txt"],
    cmd = "touch $@",
)

bazel query fails:

$ bazel query 'kind("my_query_target", //...)'
[...]
Error in download_and_extract: java.io.IOException: Error downloading [https://example.com/noexist.tar.gz] to /private/var/tmp/_bazel_jmillikin/1d615cc9026acc39a3353897884f7725/external/example_com_noexist/temp2794112296295295544/noexist.tar.gz: GET returned 404 Not Found
ERROR: Evaluation of query "kind('my_query_target', //...)" failed due to BUILD file errors
Loading: 2 packages loaded

Removing the gen_toplevel target -- which has no relation to the failing dependency -- fixes the error, and lets bazel query successfully return an empty result set:

$ cat BUILD 
#genrule(
#    name = "gen_toplevel",
#    outs = ["gen_toplevel.txt"],
#    cmd = "touch $@",
#)
$ bazel query 'kind("my_query_target", //...)'
INFO: Empty results
Loading: 1 packages loaded
$

What operating system are you running Bazel on?

macOS, but I believe this bug is not platform-specific.

What's the output of bazel info release?

Successfully reproduced with:

  • release 3.7.0
  • release 3.4.1

I have not yet tried reproducing at HEAD, or with an older release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3We're not considering working on this, but happy to review a PR. (No assignee)team-PerformanceIssues for Performance teamstype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions