Skip to content

Commit

Permalink
Allow decompression of nupkg
Browse files Browse the repository at this point in the history
In some (legacy) projects, nuget is used to handle C++ packages.
Nuget packages are working fine with WORKSPACE `http_archive` directives when explicitly specifying `type = "zip"`.

However, when migrating to bzlmod, we ran into issues when the url in source.json is a nupkg file.
This PR resolves that issue and allows consumption of nupkg archives as Bazel modules.

Closes bazelbuild#23645.

PiperOrigin-RevId: 680636414
Change-Id: Ia7fd3fc738a2dd68b1063dba0dc847c5b0668401
  • Loading branch information
dpvdberg authored and copybara-github committed Sep 30, 2024
1 parent e959d78 commit b387036
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ static Decompressor getDecompressor(Path archivePath) throws RepositoryFunctionE
if (baseName.endsWith(".zip")
|| baseName.endsWith(".jar")
|| baseName.endsWith(".war")
|| baseName.endsWith(".aar")) {
|| baseName.endsWith(".aar")
|| baseName.endsWith(".nupkg")) {
return ZipDecompressor.INSTANCE;
} else if (baseName.endsWith(".tar")) {
return TarFunction.INSTANCE;
Expand All @@ -119,8 +120,8 @@ static Decompressor getDecompressor(Path archivePath) throws RepositoryFunctionE
} else {
throw new RepositoryFunctionException(
Starlark.errorf(
"Expected a file with a .zip, .jar, .war, .aar, .tar, .tar.gz, .tgz, .tar.xz, .txz,"
+ " .tar.zst, .tzst, .tar.bz2, .tbz, .ar or .deb suffix (got %s)",
"Expected a file with a .zip, .jar, .war, .aar, .nupkg, .tar, .tar.gz, .tgz, .tar.xz,"
+ " , .tar.zst, .tzst, .tar.bz2, .tbz, .ar or .deb suffix (got %s)",
archivePath),
Transience.PERSISTENT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ public Object download(
The archive type of the downloaded file. 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", \
"aar", "tar", "tar.gz", "tgz", "tar.xz", "txz", ".tar.zst", \
"aar", "nupkg", "tar", "tar.gz", "tgz", "tar.xz", "txz", ".tar.zst", \
".tzst", "tar.bz2", ".tbz", ".ar", or ".deb" here.
"""),
@Param(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public void testKnownFileExtensionsDoNotThrow() throws Exception {
unused = DecompressorValue.getDecompressor(path);
path = fs.getPath("/foo/.external-repositories/some-repo/bar.baz.zip");
unused = DecompressorValue.getDecompressor(path);
path = fs.getPath("/foo/.external-repositories/some-repo/bar.baz.nupkg");
unused = DecompressorValue.getDecompressor(path);
path = fs.getPath("/foo/.external-repositories/some-repo/bar.baz.tar.gz");
unused = DecompressorValue.getDecompressor(path);
path = fs.getPath("/foo/.external-repositories/some-repo/bar.baz.tgz");
Expand Down

0 comments on commit b387036

Please sign in to comment.