Search code examples
bazelhttp-archive

How can I delete cached downloaded objects (e.g. from http_archive) in Bazel?


The CI build for my Bazel C++ project recently broke. The error indicates that the HTTPS download for a http_repository failed:

INFO: Repository eigen instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule http_archive defined at:
  /private/var/tmp/_bazel_kstaley/efca2582089f638162aa9f6ccfe4282e/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
WARNING: Download from https://gitlab.com/libeigen/eigen/-/archive/56b3e3f3f8ca9972ca390c8296fde363bdab271c/eigen-56b3e3f3f8ca9972ca390c8296fde363bdab271c.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 406 Not Acceptable
ERROR: An error occurred during the fetch of repository 'eigen':
   java.io.IOException: Error downloading [https://gitlab.com/libeigen/eigen/-/archive/56b3e3f3f8ca9972ca390c8296fde363bdab271c/eigen-56b3e3f3f8ca9972ca390c8296fde363bdab271c.tar.gz] to /private/var/tmp/_bazel_kstaley/efca2582089f638162aa9f6ccfe4282e/external/eigen/eigen-56b3e3f3f8ca9972ca390c8296fde363bdab271c.tar.gz: GET returned 406 Not Acceptable
ERROR: /Users/kstaley/src/myrepo/library/utilities/BUILD:58:11: //library/utilities:mylibrary depends on @eigen//:eigen in repository @eigen which failed to fetch. no such package '@eigen//': java.io.IOException: Error downloading [https://gitlab.com/libeigen/eigen/-/archive/56b3e3f3f8ca9972ca390c8296fde363bdab271c/eigen-56b3e3f3f8ca9972ca390c8296fde363bdab271c.tar.gz] to /private/var/tmp/_bazel_kstaley/efca2582089f638162aa9f6ccfe4282e/external/eigen/eigen-56b3e3f3f8ca9972ca390c8296fde363bdab271c.tar.gz: GET returned 406 Not Acceptable
ERROR: Analysis of target '//library/mypackage:mybinary' failed; build aborted: Analysis failed

I would like to reproduce this error locally, but I already have that file cached locally (the download error seems to be intermittent), so my local build succeeds.

How can I delete Bazel's cached copy of the .tar.gz file so that I can test whether the download succeeds locally? I've tried bazel clean --expunge but it does not seem to delete downloaded artifacts.


Solution

  • rm -r $(bazel info repository_cache) is the brute force solution. Passing --repository_cache= to commands should also disable it.

    There's more about the repository cache in the documentation.