Skip to content

Commit 706218d

Browse files
committed
Support sourcing the Spin environment file from a Bash script
At Shopify we want to use TruffleRuby inside other Spin projects, so it’s important that `source /path/to/truffleruby/.spin/bin/env` works from those projects’ Bash scripts as well as directly from the command line. When the environment file is sourced by another script, `$0` is the name of the main script being executed rather than the environment file itself, so `dirname "$0"` will return the (probably incorrect) directory containing the main script rather than `/path/to/truffleruby/.spin/bin` as expected. In Bash, `$BASH_SOURCE` is an array containing the source filenames of all currently-executing shell functions [0], of which the first is always the most recent [1], so we can use `$BASH_SOURCE[0]` to directly ask for the filename of the environment file instead of assuming that `$0` will contain it. This change makes `source` work correctly at the cost of relying on a Bash-specific feature. We also need to support zsh, so support for that will be added in the next commit. [0] https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fSOURCE [1] https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-FUNCNAME
1 parent 8c1ecfd commit 706218d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

.spin/bin/env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
SCRIPT_PATH=$(dirname "$0")
3+
SCRIPT_PATH=$(dirname "$BASH_SOURCE[0]")
44
SCRIPT_PATH=$(cd "$SCRIPT_PATH" && pwd)
55
TRUFFLERUBY_DIR=$SCRIPT_PATH/../..
66
export JT_ENV=jvm-ce

0 commit comments

Comments
 (0)