From d84e745ce9bc457ac7ed4afaa1403afbd277bcd4 Mon Sep 17 00:00:00 2001 From: Cornelius Riemenschneider Date: Fri, 23 Aug 2024 14:24:51 +0200 Subject: [PATCH 1/2] Make ripunzip installer accessible from outside this repo. * The relative path to misc doesn't work when running from another repo * The buildifier dependency is not available from other repos, therefore we can't pull in //misc/bazel without further refactoring. Therefore, inline the runfiles snippet here. --- misc/ripunzip/BUILD.bazel | 2 +- misc/ripunzip/install.sh | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/misc/ripunzip/BUILD.bazel b/misc/ripunzip/BUILD.bazel index ea21e6b1c948..83317a74e011 100644 --- a/misc/ripunzip/BUILD.bazel +++ b/misc/ripunzip/BUILD.bazel @@ -9,5 +9,5 @@ sh_binary( srcs = ["install.sh"], args = ["$(rlocationpath :ripunzip)"], data = [":ripunzip"], - deps = ["//misc/bazel:sh_runfiles"], + deps = ["@bazel_tools//tools/bash/runfiles"], ) diff --git a/misc/ripunzip/install.sh b/misc/ripunzip/install.sh index 2fb4d48ed6c0..45b69f84f785 100755 --- a/misc/ripunzip/install.sh +++ b/misc/ripunzip/install.sh @@ -2,7 +2,16 @@ set -eu -. misc/bazel/runfiles.sh +# --- 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 --- dest="${2:-$HOME/.local/bin}" From 3ac8108c4a4d2d3627b47cd2a0f685173413e539 Mon Sep 17 00:00:00 2001 From: Cornelius Riemenschneider Date: Fri, 23 Aug 2024 17:26:05 +0200 Subject: [PATCH 2/2] Address review. --- .github/workflows/buildifier.yml | 2 +- .pre-commit-config.yaml | 2 +- misc/bazel/BUILD.bazel | 10 ---------- misc/bazel/buildifier/BUILD.bazel | 9 +++++++++ misc/ripunzip/BUILD.bazel | 2 +- misc/ripunzip/install.sh | 11 +---------- 6 files changed, 13 insertions(+), 23 deletions(-) create mode 100644 misc/bazel/buildifier/BUILD.bazel diff --git a/.github/workflows/buildifier.yml b/.github/workflows/buildifier.yml index b5d1e2244d5c..f3fbf97854ce 100644 --- a/.github/workflows/buildifier.yml +++ b/.github/workflows/buildifier.yml @@ -24,5 +24,5 @@ jobs: extra_args: > buildifier --all-files 2>&1 || ( - echo -e "In order to format all bazel files, please run:\n bazel run //misc/bazel:buildifier"; exit 1 + echo -e "In order to format all bazel files, please run:\n bazel run //misc/bazel/buildifier"; exit 1 ) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 62ac0d95779b..45935401beeb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,7 +26,7 @@ repos: name: Format bazel files files: \.(bazel|bzl) language: system - entry: bazel run //misc/bazel:buildifier + entry: bazel run //misc/bazel/buildifier pass_filenames: false # DISABLED: can be enabled by copying this config and installing `pre-commit` with `--config` on the copy diff --git a/misc/bazel/BUILD.bazel b/misc/bazel/BUILD.bazel index d5c157439037..c3670b75c94a 100644 --- a/misc/bazel/BUILD.bazel +++ b/misc/bazel/BUILD.bazel @@ -1,13 +1,3 @@ -load("@buildifier_prebuilt//:rules.bzl", "buildifier") - -buildifier( - name = "buildifier", - exclude_patterns = [ - "./.git/*", - ], - lint_mode = "fix", -) - sh_library( name = "sh_runfiles", srcs = ["runfiles.sh"], diff --git a/misc/bazel/buildifier/BUILD.bazel b/misc/bazel/buildifier/BUILD.bazel new file mode 100644 index 000000000000..3ccdcda5f129 --- /dev/null +++ b/misc/bazel/buildifier/BUILD.bazel @@ -0,0 +1,9 @@ +load("@buildifier_prebuilt//:rules.bzl", "buildifier") + +buildifier( + name = "buildifier", + exclude_patterns = [ + "./.git/*", + ], + lint_mode = "fix", +) diff --git a/misc/ripunzip/BUILD.bazel b/misc/ripunzip/BUILD.bazel index 83317a74e011..ea21e6b1c948 100644 --- a/misc/ripunzip/BUILD.bazel +++ b/misc/ripunzip/BUILD.bazel @@ -9,5 +9,5 @@ sh_binary( srcs = ["install.sh"], args = ["$(rlocationpath :ripunzip)"], data = [":ripunzip"], - deps = ["@bazel_tools//tools/bash/runfiles"], + deps = ["//misc/bazel:sh_runfiles"], ) diff --git a/misc/ripunzip/install.sh b/misc/ripunzip/install.sh index 45b69f84f785..d9ee6dda1cb6 100755 --- a/misc/ripunzip/install.sh +++ b/misc/ripunzip/install.sh @@ -2,16 +2,7 @@ set -eu -# --- 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 --- +source misc/bazel/runfiles.sh 2>/dev/null || source external/ql~/misc/bazel/runfiles.sh dest="${2:-$HOME/.local/bin}"