Skip to content

Commit

Permalink
Support extracting aar files.
Browse files Browse the repository at this point in the history
Hey awesome Bazel team,

Would you consider allowing extract, download_and_extract, and http_archive to decompress .aar android archives? Figured I'd just toss up a PR to ask because it was such an easy addition; aars are just zip files under the hood, totally parallel to the jar/war cases already in the codebase.

The motivation is that you'll need this basic functionality to be able to depend on the native interface of an aar, which Android Studio & co are working on in [prefabs](https://developer.android.com/studio/build/native-dependencies). I ran into the lack of support while trying to hack myself support for #13092.

Thanks for your consideration!
Chris

Closes #13098.

PiperOrigin-RevId: 387384152
  • Loading branch information
cpsauer authored and Copybara-Service committed Jul 28, 2021
1 parent 0428828 commit 9055c67
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Expand Up @@ -92,7 +92,10 @@ public int hashCode() {
static Decompressor getDecompressor(Path archivePath)
throws RepositoryFunctionException {
String baseName = archivePath.getBaseName();
if (baseName.endsWith(".zip") || baseName.endsWith(".jar") || baseName.endsWith(".war")) {
if (baseName.endsWith(".zip")
|| baseName.endsWith(".jar")
|| baseName.endsWith(".war")
|| baseName.endsWith(".aar")) {
return ZipDecompressor.INSTANCE;
} else if (baseName.endsWith(".tar")) {
return TarFunction.INSTANCE;
Expand All @@ -105,8 +108,8 @@ static Decompressor getDecompressor(Path archivePath)
} else {
throw new RepositoryFunctionException(
Starlark.errorf(
"Expected a file with a .zip, .jar, .war, .tar, .tar.gz, .tgz, .tar.xz, .txz, or "
+ ".tar.bz2 suffix (got %s)",
"Expected a file with a .zip, .jar, .war, .aar, .tar, .tar.gz, .tgz, .tar.xz, .txz, "
+ "or .tar.bz2 suffix (got %s)",
archivePath),
Transience.PERSISTENT);
}
Expand Down
Expand Up @@ -502,7 +502,8 @@ void extract(Object archive, Object output, String stripPrefix, StarlarkThread t
+ " By default, the archive type is determined from the file extension of"
+ " the URL."
+ " If the file has no extension, you can explicitly specify either \"zip\","
+ " \"jar\", \"war\", \"tar.gz\", \"tgz\", \"tar.bz2\", or \"tar.xz\" here."),
+ " \"jar\", \"war\", \"aar\", \"tar.gz\", \"tgz\", \"tar.bz2\", or \"tar.xz\""
+ " here."),
@Param(
name = "stripPrefix",
defaultValue = "''",
Expand Down
6 changes: 3 additions & 3 deletions tools/build_defs/repo/http.bzl
Expand Up @@ -278,7 +278,7 @@ match a directory in the archive, Bazel will return an error.""",
By default, the archive type is determined from the file extension of the
URL. If the file has no extension, you can explicitly specify one of the
following: `"zip"`, `"jar"`, `"war"`, `"tar"`, `"tar.gz"`, `"tgz"`,
following: `"zip"`, `"jar"`, `"war"`, `"aar"`, `"tar"`, `"tar.gz"`, `"tgz"`,
`"tar.xz"`, or `tar.bz2`.""",
),
"patches": attr.label_list(
Expand Down Expand Up @@ -367,8 +367,8 @@ http_archive = repository_rule(
"""Downloads a Bazel repository as a compressed archive file, decompresses it,
and makes its targets available for binding.
It supports the following file extensions: `"zip"`, `"jar"`, `"war"`, `"tar"`,
`"tar.gz"`, `"tgz"`, `"tar.xz"`, and `tar.bz2`.
It supports the following file extensions: `"zip"`, `"jar"`, `"war"`, `"aar"`,
`"tar"`, `"tar.gz"`, `"tgz"`, `"tar.xz"`, and `tar.bz2`.
Examples:
Suppose the current repository contains the source code for a chat program,
Expand Down

0 comments on commit 9055c67

Please sign in to comment.