Skip to content

Commit

Permalink
refactor: use BASH_RLOCATION_FUNCTION from @aspect_bazel_lib in examp…
Browse files Browse the repository at this point in the history
…les/js_binary/BUILD.bazel (#1707)
  • Loading branch information
gregmagolan authored May 7, 2024
1 parent 465a19a commit bad68d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
8 changes: 4 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ load("//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "register_coreutils_toolchains", "register_jq_toolchains")
load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains", "register_expand_template_toolchains", "register_jq_toolchains")

aspect_bazel_lib_dependencies()
register_coreutils_toolchains()

register_jq_toolchains()
register_expand_template_toolchains()

register_coreutils_toolchains()
register_jq_toolchains()

load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")

Expand Down
26 changes: 12 additions & 14 deletions examples/js_binary/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Simple examples of running JS programs in node with js_binary, js_run_binary, an

load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
load("@aspect_bazel_lib//lib:paths.bzl", "BASH_RLOCATION_FUNCTION")
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary", "js_test")
load("@aspect_bazel_lib//lib:diff_test.bzl", "diff_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
Expand Down Expand Up @@ -457,22 +459,18 @@ js_binary(
entry_point = "case10.js",
)

write_file(
expand_template(
name = "write10_launch_sh",
out = "launch_case10.sh",
content = ["""\
# --- begin runfiles.bash initialization v2 ---
set -uo pipefail; 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 v2 ---
$(rlocation aspect_rules_js/examples/js_binary/bin10-js_binary.sh) "$@"
"""],
data = [":bin10-js_binary"],
is_executable = True,
substitutions = {
"{rlocationpath}": "$(rlocationpath :bin10-js_binary)",
},
template = [
BASH_RLOCATION_FUNCTION,
"$(rlocation {rlocationpath}) \"$@\"",
],
)

# NB: https://github.com/aspect-build/rules_js/issues/285 is only reproducable
Expand Down

0 comments on commit bad68d5

Please sign in to comment.