Skip to content

Commit 19955f0

Browse files
authored
refactor: simplify launcher script logic for chdir (#2813)
The `js_binary()` and `js_run_binary()` rules provide a `chdir` option that you can use to indicate a directory to cd to before the main entry point is invoked. This turns into a `JS_BINARY__CHDIR` environment variable that the launcher script looks at to decide where to cd. The logic has a special case for when `JS_BINARY__CHDIR` begins with `external/`, in which case we call `resolve_execroot_bin_path` to canonicalize the path. This special casing seems to be unnecessary, and `resolve_execroot_bin_path` also contains more logic than we need. I therefore replaced all this with a one-liner that cds to the correct absolute path. The motivation for this is that in another PR I am going to change the behavior of `resolve_execroot_bin_path` so that it always refers to the exec platform bin directory, but this is not something we want to affect `chdir`. --- ### Changes are visible to end-users: no ### Test plan - Covered by existing test cases
1 parent 7d28f8e commit 19955f0

2 files changed

Lines changed: 2 additions & 8 deletions

File tree

js/private/js_binary.sh.tpl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,7 @@ fi
328328
# Change directory to user specified package if set
329329
if [ "${JS_BINARY__CHDIR:-}" ]; then
330330
logf_debug "changing directory to user specified package %s" "$JS_BINARY__CHDIR"
331-
case "$JS_BINARY__CHDIR" in
332-
external/*) cd "$(resolve_execroot_bin_path "$JS_BINARY__CHDIR")" ;;
333-
*) cd "$JS_BINARY__CHDIR" ;;
334-
esac
331+
cd "$JS_BINARY__EXECROOT/${BAZEL_BINDIR:-$JS_BINARY__BINDIR}/$JS_BINARY__CHDIR"
335332
fi
336333

337334
# Gather node options

js/private/test/snapshots/launcher.sh

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)