Skip to content

Commit 9055c67

Browse files
cpsauercopybara-github
authored andcommitted
Support extracting aar files.
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
1 parent 0428828 commit 9055c67

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/main/java/com/google/devtools/build/lib/bazel/repository/DecompressorValue.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ public int hashCode() {
9292
static Decompressor getDecompressor(Path archivePath)
9393
throws RepositoryFunctionException {
9494
String baseName = archivePath.getBaseName();
95-
if (baseName.endsWith(".zip") || baseName.endsWith(".jar") || baseName.endsWith(".war")) {
95+
if (baseName.endsWith(".zip")
96+
|| baseName.endsWith(".jar")
97+
|| baseName.endsWith(".war")
98+
|| baseName.endsWith(".aar")) {
9699
return ZipDecompressor.INSTANCE;
97100
} else if (baseName.endsWith(".tar")) {
98101
return TarFunction.INSTANCE;
@@ -105,8 +108,8 @@ static Decompressor getDecompressor(Path archivePath)
105108
} else {
106109
throw new RepositoryFunctionException(
107110
Starlark.errorf(
108-
"Expected a file with a .zip, .jar, .war, .tar, .tar.gz, .tgz, .tar.xz, .txz, or "
109-
+ ".tar.bz2 suffix (got %s)",
111+
"Expected a file with a .zip, .jar, .war, .aar, .tar, .tar.gz, .tgz, .tar.xz, .txz, "
112+
+ "or .tar.bz2 suffix (got %s)",
110113
archivePath),
111114
Transience.PERSISTENT);
112115
}

src/main/java/com/google/devtools/build/lib/starlarkbuildapi/repository/StarlarkRepositoryContextApi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ void extract(Object archive, Object output, String stripPrefix, StarlarkThread t
502502
+ " By default, the archive type is determined from the file extension of"
503503
+ " the URL."
504504
+ " If the file has no extension, you can explicitly specify either \"zip\","
505-
+ " \"jar\", \"war\", \"tar.gz\", \"tgz\", \"tar.bz2\", or \"tar.xz\" here."),
505+
+ " \"jar\", \"war\", \"aar\", \"tar.gz\", \"tgz\", \"tar.bz2\", or \"tar.xz\""
506+
+ " here."),
506507
@Param(
507508
name = "stripPrefix",
508509
defaultValue = "''",

tools/build_defs/repo/http.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ match a directory in the archive, Bazel will return an error.""",
278278
279279
By default, the archive type is determined from the file extension of the
280280
URL. If the file has no extension, you can explicitly specify one of the
281-
following: `"zip"`, `"jar"`, `"war"`, `"tar"`, `"tar.gz"`, `"tgz"`,
281+
following: `"zip"`, `"jar"`, `"war"`, `"aar"`, `"tar"`, `"tar.gz"`, `"tgz"`,
282282
`"tar.xz"`, or `tar.bz2`.""",
283283
),
284284
"patches": attr.label_list(
@@ -367,8 +367,8 @@ http_archive = repository_rule(
367367
"""Downloads a Bazel repository as a compressed archive file, decompresses it,
368368
and makes its targets available for binding.
369369
370-
It supports the following file extensions: `"zip"`, `"jar"`, `"war"`, `"tar"`,
371-
`"tar.gz"`, `"tgz"`, `"tar.xz"`, and `tar.bz2`.
370+
It supports the following file extensions: `"zip"`, `"jar"`, `"war"`, `"aar"`,
371+
`"tar"`, `"tar.gz"`, `"tgz"`, `"tar.xz"`, and `tar.bz2`.
372372
373373
Examples:
374374
Suppose the current repository contains the source code for a chat program,

0 commit comments

Comments
 (0)