Skip to content

Commit

Permalink
Ripunzip: provide installer
Browse files Browse the repository at this point in the history
  • Loading branch information
redsun82 committed Jun 5, 2024
1 parent 44a56c4 commit 61847bc
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
7 changes: 7 additions & 0 deletions misc/bazel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
8 changes: 0 additions & 8 deletions misc/bazel/internal/ripunzip/BUILD.bazel

This file was deleted.

2 changes: 0 additions & 2 deletions misc/bazel/internal/ripunzip/README.md

This file was deleted.

4 changes: 2 additions & 2 deletions misc/bazel/pkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions misc/bazel/runfiles.sh
Original file line number Diff line number Diff line change
@@ -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 ---
13 changes: 13 additions & 0 deletions misc/ripunzip/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
File renamed without changes.
11 changes: 11 additions & 0 deletions misc/ripunzip/README.md
Original file line number Diff line number Diff line change
@@ -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
```
24 changes: 24 additions & 0 deletions misc/ripunzip/install.sh
Original file line number Diff line number Diff line change
@@ -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")"
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion swift/third_party/resource-dir/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")
]
11 changes: 1 addition & 10 deletions swift/third_party/resource-dir/update.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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")"

0 comments on commit 61847bc

Please sign in to comment.