bazelbuild / bazelbuild/bazel

Feature request: download_and_extract(strip_prefix="*")

Open
#13,960 6 comments 0 reactions 0 assignees View on GitHub
P3 team-ExternalDeps type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the problem / feature request:

If (and only if) an archive only has one top-level directory, allow `strip_prefix="*"` to use that directory, rather than requiring the exact name to be specified.

If the archive has multiple top-level directories, error out.

### Feature requests: what underlying problem are you trying to solve with this feature?

Not all archives have top level directories that are named in a friendly manner.

For example, when downloading a tagged git archive:

- Github provides the useful format `[repo]-[tag]`
- Bitbucket provides the less useful format `[repo]-[hash]`, where `[hash]` is the first 12 characters of the commit that the tag reflects.

When first adding a http_archive (or alternative) to your workspace, it's easy enough to find what the top level directory is called. You'd often set the tag and URL to reflect the tag in github dependencies, but with many archives it requires a bit more effort.

When working with dependencies that change at a rapid pace (e.g. in early development of a polyrepo), this can get very tiresome.

My particular use case is a custom build definition that provides a simpler interface to private repositories in a polyrepo setup (managing auth, building URLs). With some providers, strip_prefix can be generated automatically. With others, it cannot. This complicates the interface of my build definition.

I don't know of any justification for requiring strip_prefix to be specified manually.

### Have you found anything relevant by searching the web?

I initially asked this question on the bazel slack, and it received a positive response. One responder did mention the Renovate project, but this doesn't work for all use cases (e.g. custom build defs).

Contributor guide

Open the contributing guide

Research direction

Start at the download_and_extract entry point and inspect how strip_prefix is handled for http_archive archives. Add coverage for an archive with one top-level directory and another with multiple top-level directories; done means the wildcard behavior is accepted only in the former case and errors in the latter.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.