Skip to content

Commit

Permalink
Makefile: support changing the current crystal via env var and argume…
Browse files Browse the repository at this point in the history
…nt (crystal-lang#9471)

* Makefile: support changing the current crystal via env var and argument

Allow bin/crystal and makefile to not require installed crystal in path by reading CRYSTAL env var or makefile argument

make CRYSTAL=path/to/previous/compiler

* Propagate CRYSTAL env variable

NB: .build/crystal still has precedence
  • Loading branch information
Brian J. Cardiff authored Jun 23, 2020
1 parent 4d7e585 commit 0618737
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
## Run all specs in verbose mode
## $ make spec verbose=1

LLVM_CONFIG ?= ## llvm-config command path to use
CRYSTAL ?= crystal ## which previous crystal compiler use
LLVM_CONFIG ?= ## llvm-config command path to use

release ?= ## Compile in release mode
stats ?= ## Enable statistics output
Expand Down
10 changes: 6 additions & 4 deletions bin/crystal
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ CRYSTAL_DIR="$CRYSTAL_ROOT/.build"
export CRYSTAL_PATH=lib:$CRYSTAL_ROOT/src
export CRYSTAL_HAS_WRAPPER=true

export CRYSTAL="${CRYSTAL:-"crystal"}"

if [ -z "$CRYSTAL_CONFIG_LIBRARY_PATH" ]; then
export CRYSTAL_CONFIG_LIBRARY_PATH="$(
export PATH="$(remove_path_item "$(remove_path_item "$PATH" "$SCRIPT_ROOT")" "bin")"
Expand All @@ -151,12 +153,12 @@ fi
if [ -x "$CRYSTAL_DIR/crystal" ]; then
__warning_msg "Using compiled compiler at ${CRYSTAL_DIR#"$PWD/"}/crystal"
exec "$CRYSTAL_DIR/crystal" "$@"
elif ! command -v crystal > /dev/null; then
__error_msg 'You need to have a crystal executable in your path!'
elif ! command -v $CRYSTAL > /dev/null; then
__error_msg 'You need to have a crystal executable in your path! or set CRYSTAL env variable'
exit 1
elif [ "$(command -v crystal)" = "$SCRIPT_PATH" ] || [ "$(command -v crystal)" = "bin/crystal" ]; then
elif [ "$(command -v $CRYSTAL)" = "$SCRIPT_PATH" ] || [ "$(command -v $CRYSTAL)" = "bin/crystal" ]; then
export PATH="$(remove_path_item "$(remove_path_item "$PATH" "$SCRIPT_ROOT")" "bin")"
exec "$SCRIPT_PATH" "$@"
else
exec crystal "$@"
exec $CRYSTAL "$@"
fi

0 comments on commit 0618737

Please sign in to comment.