bazelbuild / bazelbuild/bazel

Have repository_ctx.download tell name of downloaded file

Open
#26,268 1 comment 0 reactions 0 assignees View on GitHub
help wanted P2 team-ExternalDeps type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 16h
Merged PRs (30d)
72

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` ?

```text

```

### 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

Open the contributing guide

Research direction

Start by reading the repository_ctx.download API and its documentation, then trace how its result is currently represented. Define how the local filename should be exposed across multiple URLs, URL-encoded names, and response headers; done means callers can use the returned filename directly and the behavior is documented.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.