|
| 1 | +def _ripunzip_archive_impl(repository_ctx): |
| 2 | + version = repository_ctx.attr.version |
| 3 | + url_prefix = "https://github.com/GoogleChrome/ripunzip/releases/download/v%s" % version |
| 4 | + build_file = Label("//misc/ripunzip:BUILD.ripunzip.bazel") |
| 5 | + if "linux" in repository_ctx.os.name: |
| 6 | + # ripunzip only provides a deb package for Linux: we fish the binary out of it |
| 7 | + # a deb archive contains a data.tar.xz one which contains the files to be installed under usr/bin |
| 8 | + repository_ctx.download_and_extract( |
| 9 | + url = "%s/ripunzip_%s-1_amd64.deb" % (url_prefix, version), |
| 10 | + sha256 = repository_ctx.attr.sha256_linux, |
| 11 | + canonical_id = "ripunzip-linux", |
| 12 | + output = "deb", |
| 13 | + ) |
| 14 | + repository_ctx.extract( |
| 15 | + "deb/data.tar.xz", |
| 16 | + strip_prefix = "usr/bin", |
| 17 | + output = "bin", |
| 18 | + ) |
| 19 | + elif "windows" in repository_ctx.os.name: |
| 20 | + repository_ctx.download_and_extract( |
| 21 | + url = "%s/ripunzip_v%s_x86_64-pc-windows-msvc.zip" % (url_prefix, version), |
| 22 | + canonical_id = "ripunzip-windows", |
| 23 | + sha256 = repository_ctx.attr.sha256_windows, |
| 24 | + output = "bin", |
| 25 | + ) |
| 26 | + elif "mac os" in repository_ctx.os.name: |
| 27 | + arch = repository_ctx.os.arch |
| 28 | + if arch == "x86_64": |
| 29 | + suffix = "x86_64-apple-darwin" |
| 30 | + sha256 = repository_ctx.attr.sha256_macos_intel |
| 31 | + canonical_id = "ripunzip-macos-intel" |
| 32 | + elif arch == "aarch64": |
| 33 | + suffix = "aarch64-apple-darwin" |
| 34 | + sha256 = repository_ctx.attr.sha256_macos_arm |
| 35 | + canonical_id = "ripunzip-macos-arm" |
| 36 | + else: |
| 37 | + fail("Unsupported macOS architecture: %s" % arch) |
| 38 | + repository_ctx.download_and_extract( |
| 39 | + url = "%s/ripunzip_v%s_%s.tar.gz" % (url_prefix, version, suffix), |
| 40 | + sha256 = sha256, |
| 41 | + canonical_id = canonical_id, |
| 42 | + output = "bin", |
| 43 | + ) |
| 44 | + else: |
| 45 | + fail("Unsupported OS: %s" % repository_ctx.os.name) |
| 46 | + repository_ctx.file("WORKSPACE.bazel") |
| 47 | + repository_ctx.symlink(build_file, "BUILD.bazel") |
| 48 | + |
| 49 | +ripunzip_archive = repository_rule( |
| 50 | + implementation = _ripunzip_archive_impl, |
| 51 | + doc = "Downloads a prebuilt ripunzip binary for the host platform from https://github.com/GoogleChrome/ripunzip/releases", |
| 52 | + attrs = { |
| 53 | + "version": attr.string(mandatory = True), |
| 54 | + "sha256_linux": attr.string(mandatory = True), |
| 55 | + "sha256_windows": attr.string(mandatory = True), |
| 56 | + "sha256_macos_intel": attr.string(mandatory = True), |
| 57 | + "sha256_macos_arm": attr.string(mandatory = True), |
| 58 | + }, |
| 59 | +) |
0 commit comments