From 61847bc58b7c68a13eecea5f15661c74517e6111 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Wed, 5 Jun 2024 14:46:59 +0200 Subject: [PATCH] Ripunzip: provide installer --- .gitattributes | 2 +- MODULE.bazel | 6 ++--- misc/bazel/BUILD.bazel | 7 ++++++ misc/bazel/internal/ripunzip/BUILD.bazel | 8 ------- misc/bazel/internal/ripunzip/README.md | 2 -- misc/bazel/pkg.bzl | 4 ++-- misc/bazel/runfiles.sh | 10 ++++++++ misc/ripunzip/BUILD.bazel | 13 ++++++++++ .../{bazel/internal => }/ripunzip/LICENSE.txt | 0 misc/ripunzip/README.md | 11 +++++++++ misc/ripunzip/install.sh | 24 +++++++++++++++++++ .../internal => }/ripunzip/ripunzip-linux | 0 .../internal => }/ripunzip/ripunzip-macos | 0 .../ripunzip/ripunzip-windows.exe | 0 swift/third_party/resource-dir/BUILD.bazel | 2 +- swift/third_party/resource-dir/update.sh | 11 +-------- 16 files changed, 73 insertions(+), 27 deletions(-) delete mode 100644 misc/bazel/internal/ripunzip/BUILD.bazel delete mode 100644 misc/bazel/internal/ripunzip/README.md create mode 100644 misc/bazel/runfiles.sh create mode 100644 misc/ripunzip/BUILD.bazel rename misc/{bazel/internal => }/ripunzip/LICENSE.txt (100%) create mode 100644 misc/ripunzip/README.md create mode 100755 misc/ripunzip/install.sh rename misc/{bazel/internal => }/ripunzip/ripunzip-linux (100%) rename misc/{bazel/internal => }/ripunzip/ripunzip-macos (100%) rename misc/{bazel/internal => }/ripunzip/ripunzip-windows.exe (100%) mode change 100755 => 100644 swift/third_party/resource-dir/update.sh diff --git a/.gitattributes b/.gitattributes index e56d96bac78d..215fe0b81e18 100644 --- a/.gitattributes +++ b/.gitattributes @@ -83,7 +83,7 @@ /csharp/paket.main_extension.bzl linguist-generated=true # ripunzip tool -/misc/bazel/internal/ripunzip/ripunzip-* filter=lfs diff=lfs merge=lfs -text +/misc/ripunzip/ripunzip-* filter=lfs diff=lfs merge=lfs -text # swift prebuilt resources /swift/third_party/resource-dir/*.zip filter=lfs diff=lfs merge=lfs -text diff --git a/MODULE.bazel b/MODULE.bazel index ef35eb32580b..49f19cb1e009 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -118,19 +118,19 @@ lfs_files = use_repo_rule("//misc/bazel:lfs.bzl", "lfs_files") lfs_files( name = "ripunzip-linux", - srcs = ["//misc/bazel/internal/ripunzip:ripunzip-linux"], + srcs = ["//misc/ripunzip:ripunzip-linux"], executable = True, ) lfs_files( name = "ripunzip-windows", - srcs = ["//misc/bazel/internal/ripunzip:ripunzip-windows.exe"], + srcs = ["//misc/ripunzip:ripunzip-windows.exe"], executable = True, ) lfs_files( name = "ripunzip-macos", - srcs = ["//misc/bazel/internal/ripunzip:ripunzip-macos"], + srcs = ["//misc/ripunzip:ripunzip-macos"], executable = True, ) diff --git a/misc/bazel/BUILD.bazel b/misc/bazel/BUILD.bazel index 3ccdcda5f129..d5c157439037 100644 --- a/misc/bazel/BUILD.bazel +++ b/misc/bazel/BUILD.bazel @@ -7,3 +7,10 @@ buildifier( ], lint_mode = "fix", ) + +sh_library( + name = "sh_runfiles", + srcs = ["runfiles.sh"], + visibility = ["//visibility:public"], + deps = ["@bazel_tools//tools/bash/runfiles"], +) diff --git a/misc/bazel/internal/ripunzip/BUILD.bazel b/misc/bazel/internal/ripunzip/BUILD.bazel deleted file mode 100644 index 74ec7a86e8d5..000000000000 --- a/misc/bazel/internal/ripunzip/BUILD.bazel +++ /dev/null @@ -1,8 +0,0 @@ -load("@bazel_skylib//rules:native_binary.bzl", "native_binary") - -native_binary( - name = "ripunzip", - src = select({"@platforms//os:" + os: "@ripunzip-" + os for os in ("linux", "windows", "macos")}), - out = "ripunzip.exe", - visibility = ["//visibility:public"], -) diff --git a/misc/bazel/internal/ripunzip/README.md b/misc/bazel/internal/ripunzip/README.md deleted file mode 100644 index 4312f00a9b0b..000000000000 --- a/misc/bazel/internal/ripunzip/README.md +++ /dev/null @@ -1,2 +0,0 @@ -These LFS files are distributions of [ripunzip](https://github.com/google/ripunzip), compiled with this [workflow](https://github.com/github/codeql/actions/workflows/build-ripunzip.yml). -A [copy](./LICENSE.txt) of the ripunzip license is included. diff --git a/misc/bazel/pkg.bzl b/misc/bazel/pkg.bzl index af6cc331b6fa..1e004a78234a 100644 --- a/misc/bazel/pkg.bzl +++ b/misc/bazel/pkg.bzl @@ -364,7 +364,7 @@ def codeql_pack( internal("script"), ] + ([ internal("zip-manifest"), - Label("//misc/bazel/internal/ripunzip"), + Label("//misc/ripunzip"), ] if zips else []), deps = ["@rules_python//python/runfiles"], args = [ @@ -373,7 +373,7 @@ def codeql_pack( "--destdir", install_dest, ] + ([ - "--ripunzip=$(rlocationpath %s)" % Label("//misc/bazel/internal/ripunzip"), + "--ripunzip=$(rlocationpath %s)" % Label("//misc/ripunzip"), "--zip-manifest=$(rlocationpath %s)" % internal("zip-manifest"), ] if zips else []), visibility = visibility, diff --git a/misc/bazel/runfiles.sh b/misc/bazel/runfiles.sh new file mode 100644 index 000000000000..4ddb5489d7bf --- /dev/null +++ b/misc/bazel/runfiles.sh @@ -0,0 +1,10 @@ +# --- begin runfiles.bash initialization v3 --- +# Copy-pasted from the Bazel Bash runfiles library v3. +set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash +source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ + source "$0.runfiles/$f" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ + source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ + { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e +# --- end runfiles.bash initialization v3 --- diff --git a/misc/ripunzip/BUILD.bazel b/misc/ripunzip/BUILD.bazel new file mode 100644 index 000000000000..ea21e6b1c948 --- /dev/null +++ b/misc/ripunzip/BUILD.bazel @@ -0,0 +1,13 @@ +alias( + name = "ripunzip", + actual = select({"@platforms//os:" + os: "@ripunzip-" + os for os in ("linux", "windows", "macos")}), + visibility = ["//visibility:public"], +) + +sh_binary( + name = "install", + srcs = ["install.sh"], + args = ["$(rlocationpath :ripunzip)"], + data = [":ripunzip"], + deps = ["//misc/bazel:sh_runfiles"], +) diff --git a/misc/bazel/internal/ripunzip/LICENSE.txt b/misc/ripunzip/LICENSE.txt similarity index 100% rename from misc/bazel/internal/ripunzip/LICENSE.txt rename to misc/ripunzip/LICENSE.txt diff --git a/misc/ripunzip/README.md b/misc/ripunzip/README.md new file mode 100644 index 000000000000..4c74f49ae91c --- /dev/null +++ b/misc/ripunzip/README.md @@ -0,0 +1,11 @@ +These LFS files are distributions of [ripunzip](https://github.com/google/ripunzip), compiled with this [workflow](https://github.com/github/codeql/actions/workflows/build-ripunzip.yml). +A [copy](./LICENSE.txt) of the ripunzip license is included. + +`ripunzip` can easily be made available on the system by running +```bash +bazel run //misc/ripunzip:install +``` +By default, it will be installed in `~/.local/bin`. The target can be changed with +```bash +bazel run //misc/ripunzip:install -- /path/to/installation/dir +``` diff --git a/misc/ripunzip/install.sh b/misc/ripunzip/install.sh new file mode 100755 index 000000000000..2fb4d48ed6c0 --- /dev/null +++ b/misc/ripunzip/install.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -eu + +. misc/bazel/runfiles.sh + +dest="${2:-$HOME/.local/bin}" + +if [ ! -d "$dest" ]; then + echo "$dest: not a directory. Provide a valid installation target." >&2 + exit 1 +fi + +source="$(rlocation "$1")" + +dest+="/ripunzip" + +if [[ "$source" = *.exe ]]; then + dest+=".exe" +fi + +cp "$source" "$dest" + +echo "installed $("$dest" --version) in $(dirname "$dest")" diff --git a/misc/bazel/internal/ripunzip/ripunzip-linux b/misc/ripunzip/ripunzip-linux similarity index 100% rename from misc/bazel/internal/ripunzip/ripunzip-linux rename to misc/ripunzip/ripunzip-linux diff --git a/misc/bazel/internal/ripunzip/ripunzip-macos b/misc/ripunzip/ripunzip-macos similarity index 100% rename from misc/bazel/internal/ripunzip/ripunzip-macos rename to misc/ripunzip/ripunzip-macos diff --git a/misc/bazel/internal/ripunzip/ripunzip-windows.exe b/misc/ripunzip/ripunzip-windows.exe similarity index 100% rename from misc/bazel/internal/ripunzip/ripunzip-windows.exe rename to misc/ripunzip/ripunzip-windows.exe diff --git a/swift/third_party/resource-dir/BUILD.bazel b/swift/third_party/resource-dir/BUILD.bazel index 0b4fdbf24df6..f7e2ba39dfb0 100644 --- a/swift/third_party/resource-dir/BUILD.bazel +++ b/swift/third_party/resource-dir/BUILD.bazel @@ -21,7 +21,7 @@ alias( "@swift_toolchain_" + os, ], target_compatible_with = ["@platforms//os:" + os], - deps = ["@bazel_tools//tools/bash/runfiles"], + deps = ["//misc/bazel:sh_runfiles"], ) for os in ("linux", "macos") ] diff --git a/swift/third_party/resource-dir/update.sh b/swift/third_party/resource-dir/update.sh old mode 100755 new mode 100644 index dee216a61d67..423969922a8d --- a/swift/third_party/resource-dir/update.sh +++ b/swift/third_party/resource-dir/update.sh @@ -1,12 +1,3 @@ -# --- begin runfiles.bash initialization v3 --- -# Copy-pasted from the Bazel Bash runfiles library v3. -set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash -source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ - source "$0.runfiles/$f" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ - { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e -# --- end runfiles.bash initialization v3 --- +. misc/bazel/runfiles.sh cp "$(rlocation "$1")" "$(rlocation "$2")"