bazelbuild/bazel

Have repository_ctx.download tell name of downloaded file

Open

#26,268 opened on Jun 11, 2025

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Java (25,384 stars) (4,465 forks)batch import
P2help wantedteam-ExternalDepstype: feature request

Description

Description of the feature request:

Have the return value of repository_ctx.download() directly tell the name of the downloaded file. This to handle some esoteric cases and make it more ergonomic and correct.

  • The list of URLs may have different base names
  • A URL is not required to have any particular structure or format
  • The "basename" of the URL could contain URL-encoded components.
  • HTTP allows for the downloaded filename to be set via response headers (Content-Disposition; though some quick searches indicate Bazel may not handle this header?)

The combination of these things means there's no strict relationship between the input strings and the resulting filename that content is downloaded into. e.g, these URLs could be entirely valid for serving content:

urls = [
  "example.com/v1.0/windows/x86-musl/download.zip"
  "mirror.example.com/windows-1.0-x86-musl.zip"
]

Is the local filename the first url or second? Does it depend on which is used? If there are URL-encoded parts (bla%20bla.txt), what shows up locally?

At the least, the docs should specify behavior.

While the output name can be explicitly specified with the output arg, this erases semantic meaning in filenames. It's common for a project's artifacts to follow a particular naming scheme that tell what platform, capabilities, etc are supported (Python wheels file names are such an example). Retaining this by parsing the url strings and the doing a rename is possible, but makes for an awkward API.

If the return value of download() told the local name directly, then all these hoops can be avoided, and code can simply be:

result = download(urls)
extract(result.filename)
symlink(result.filename, "elsewhere/bla")

Which category does this issue belong to?

External Dependency

What underlying problem are you trying to solve with this feature?

I have a repository rule that accepts URLs. The structure and format of these URLs isn't in my control, file names change regularly and have semantic meaning, but the repo rule needs to interact with the downloaded file in a few ways to extract and set up its content appropriately. They are potentially large (gigabytes), so want to avoid having to copy/rename them.

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

No response

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

Have you found anything relevant by searching the web?

Search bazel issues, didn't find anything relevant.

Any other information, logs, or outputs that you want to share?

No response

Contributor guide

Have repository_ctx.download tell name of downloaded file · bazelbuild/bazel#26268 | Good First Issue