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 bazelbuild#13092.

Thanks for your consideration!
Chris

Closes bazelbuild#13098.

PiperOrigin-RevId: 387384152
  • Loading branch information
cpsauer committed Jul 28, 2021
1 parent 7efabba commit afb8196
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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 @@ -111,8 +114,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,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 @@ -340,8 +340,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 afb8196

Please sign in to comment.