From e015f55f875789ba256f5d2a2e25f1ad42af4f92 Mon Sep 17 00:00:00 2001 From: Noah Betzen Date: Fri, 17 Nov 2023 11:19:21 -0800 Subject: [PATCH 1/2] Do not ignore stderr output from kerl build Should fix https://github.com/asdf-vm/asdf-erlang/issues/288 while still ignoring stdout as originally desired --- bin/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install b/bin/install index a54afac..87d0235 100755 --- a/bin/install +++ b/bin/install @@ -29,7 +29,7 @@ install_erlang() { # We hide all output from this command so the # "You can activate this installation running the following command:" # that doesn't apply is hidden - $(kerl_path) install "$build_name" "$ASDF_INSTALL_PATH" >/dev/null 2>&1 + $(kerl_path) install "$build_name" "$ASDF_INSTALL_PATH" >/dev/null $(kerl_path) cleanup "$ASDF_INSTALL_VERSION" link_app_executables "$ASDF_INSTALL_PATH" From 7a9ea9cbf50f7c09d698869caf86f85414ea4b12 Mon Sep 17 00:00:00 2001 From: Noah Betzen Date: Sun, 19 Nov 2023 21:06:30 -0800 Subject: [PATCH 2/2] Refactor to allow local kerl --- README.md | 7 ++++++ bin/install | 24 +++++++++----------- bin/list-all | 8 +++---- bin/uninstall | 12 +++++----- lib/utils.sh | 62 +++++++++++++++++++++++++++++++++++---------------- 5 files changed, 71 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index e2534d2..562581a 100644 --- a/README.md +++ b/README.md @@ -306,3 +306,10 @@ Overriding the default kerl version shouldn't ever be necessary, but if you want ```shell export ASDF_KERL_VERSION="2.1.1" ``` + +If you'd prefer to have `asdf-erlang` use an existing local version of `kerl`, you can set: + +```shell +# Must point to the executable, not its parent directory +export ASDF_KERL_PATH="~/Git/kerl/kerl" +``` diff --git a/bin/install b/bin/install index 87d0235..0a76041 100755 --- a/bin/install +++ b/bin/install @@ -3,11 +3,11 @@ # Unoffical Bash "strict mode" # http://redsymbol.net/articles/unofficial-bash-strict-mode/ set -euo pipefail -#ORIGINAL_IFS=$IFS IFS=$'\t\n' # Stricter IFS settings -# shellcheck source=lib/utils.sh -source "$(dirname "$0")/../lib/utils.sh" +asdf_bin_dir=$(dirname "$0") +# shellcheck source=../lib/utils.sh +source "$asdf_bin_dir/../lib/utils.sh" install_erlang() { ensure_kerl_setup @@ -17,21 +17,19 @@ install_erlang() { export MAKEFLAGS="-j$ASDF_CONCURRENCY" - $(kerl_path) delete installation "$build_name" || true - $(kerl_path) delete build "$build_name" || true + "$KERL_PATH" delete installation "$build_name" || true + "$KERL_PATH" delete build "$build_name" || true if [ "$ASDF_INSTALL_TYPE" = "ref" ]; then - $(kerl_path) build git "${OTP_GITHUB_URL:-https://github.com/erlang/otp.git}" "$ASDF_INSTALL_VERSION" "$build_name" + "$KERL_PATH" build git "${OTP_GITHUB_URL:-https://github.com/erlang/otp.git}" "$ASDF_INSTALL_VERSION" "$build_name" else - $(kerl_path) build "$ASDF_INSTALL_VERSION" "$build_name" + "$KERL_PATH" build "$ASDF_INSTALL_VERSION" "$build_name" fi - # We hide all output from this command so the - # "You can activate this installation running the following command:" - # that doesn't apply is hidden - $(kerl_path) install "$build_name" "$ASDF_INSTALL_PATH" >/dev/null - $(kerl_path) cleanup "$ASDF_INSTALL_VERSION" - + # We filter the output of the install command to hide irrelevant messages: + # "You can activate/leave this installation running the following command" + "$KERL_PATH" install 2>&1 | grep -v 'activate|leave' + "$KERL_PATH" cleanup "$ASDF_INSTALL_VERSION" link_app_executables "$ASDF_INSTALL_PATH" } diff --git a/bin/list-all b/bin/list-all index ed65492..8a549ab 100755 --- a/bin/list-all +++ b/bin/list-all @@ -3,16 +3,16 @@ # Unoffical Bash "strict mode" # http://redsymbol.net/articles/unofficial-bash-strict-mode/ set -euo pipefail -#ORIGINAL_IFS=$IFS IFS=$'\t\n' # Stricter IFS settings -# shellcheck source=lib/utils.sh -source "$(dirname "$0")/../lib/utils.sh" +asdf_bin_dir=$(dirname "$0") +# shellcheck source=../lib/utils.sh +source "$asdf_bin_dir/../lib/utils.sh" list_all() { ensure_kerl_setup - "$(kerl_path)" list releases | sed -e 's:Run.*::' | tr '\n' ' ' + "$KERL_PATH" list releases | sed -e 's:Run.*::' | tr '\n' ' ' } list_all diff --git a/bin/uninstall b/bin/uninstall index 87a46fa..2b205e8 100755 --- a/bin/uninstall +++ b/bin/uninstall @@ -3,11 +3,11 @@ # Unoffical Bash "strict mode" # http://redsymbol.net/articles/unofficial-bash-strict-mode/ set -euo pipefail -#ORIGINAL_IFS=$IFS IFS=$'\t\n' # Stricter IFS settings -# shellcheck source=lib/utils.sh -source "$(dirname "$0")/../lib/utils.sh" +asdf_bin_dir=$(dirname "$0") +# shellcheck source=../lib/utils.sh +source "$asdf_bin_dir/../lib/utils.sh" ensure_kerl_setup @@ -17,9 +17,9 @@ if [ "$ASDF_INSTALL_VERSION" == "" ]; then fi # Remove the installation and build if the installation was done by kerl -if $(kerl_path) list installations | grep "$ASDF_INSTALL_PATH"; then - $(kerl_path) delete build "asdf_$ASDF_INSTALL_VERSION" || true - $(kerl_path) delete installation "$ASDF_INSTALL_PATH" || true +if "$KERL_PATH" list installations | grep "$ASDF_INSTALL_PATH"; then + "$KERL_PATH" delete build "asdf_$ASDF_INSTALL_VERSION" || true + "$KERL_PATH" delete installation "$ASDF_INSTALL_PATH" || true fi # Finally make sure the directory is actually removed regardless of what the diff --git a/lib/utils.sh b/lib/utils.sh index 2fb6ce9..1495e06 100755 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -1,4 +1,4 @@ -export KERL_VERSION="${ASDF_KERL_VERSION:-2.6.0}" +#!/usr/bin/env bash handle_failure() { function=$1 @@ -18,39 +18,63 @@ ensure_kerl_setup() { handle_failure update_available_versions 'Failed to update available versions' } +get_parent_dir() { + local asdf_script + local asdf_bin_dir + asdf_script=$(realpath "$0") + asdf_bin_dir=$(dirname "$asdf_script") + + # A height of 0 represents the asdf script's directory + local height="${1}" + + for ((i = 0; i < height; i++)); do + asdf_bin_dir=$(dirname "$asdf_bin_dir") + done + + printf "%s\\n" "$asdf_bin_dir" +} + ensure_kerl_installed() { - if [ ! -f "$(kerl_path)" ]; then + if [ -z "$KERL_PATH" ]; then + export KERL_PATH + KERL_PATH="$(get_parent_dir 1)/kerl" + fi + + local installed_kerl_version + installed_kerl_version=$($KERL_PATH version) + + if [ ! -f "$KERL_PATH" ]; then + # Print to stderr so asdf doesn't assume this string is a list of versions + printf "%s\\n" "Kerl not found at expected path ($KERL_PATH), downloading version $KERL_VERSION...\n" >&2 download_kerl - elif [ "$("$(kerl_path)" version)" != "$KERL_VERSION" ]; then - # If the kerl file already exists and the version does not match, remove - # it and download the correct version - rm "$(kerl_path)" + elif [ "$($KERL_PATH version)" != "$KERL_VERSION" ]; then + printf "%s\\n" "Found Kerl at expected path ($KERL_PATH), but installed version ($installed_kerl_version) differs from requested version ($KERL_VERSION), redownloading...\n" >&2 + # If the kerl file already exists and the version does not match, remove it and download the correct version + rm "$KERL_PATH" download_kerl + else + printf "%s\\n" "Using installed kerl version ($installed_kerl_version) at path: $KERL_PATH\n" >&2 fi } download_kerl() { - # Print to stderr so asdf doesn't assume this string is a list of versions - printf "Downloading kerl...\\n" >&2 + local kerl_url="https://raw.githubusercontent.com/kerl/kerl/$KERL_VERSION/kerl" - local kerl_url="https://raw.githubusercontent.com/kerl/kerl/${KERL_VERSION}/kerl" - - curl -Lo "$(kerl_path)" "$kerl_url" - chmod +x "$(kerl_path)" -} - -kerl_path() { - printf "%s\\n" "$(dirname "$(dirname "$0")")/kerl" + curl -Lo "$KERL_PATH" "$kerl_url" + chmod +x "$KERL_PATH" } set_kerl_env() { + export KERL_VERSION="${ASDF_KERL_VERSION:-2.6.0}" + export KERL_PATH="${ASDF_KERL_PATH:-}" + export KERL_DOWNLOAD_DIR="${ASDF_DOWNLOAD_PATH:-}" + export KERL_BUILD_BACKEND="git" + local kerl_home - kerl_home="$(dirname "$(dirname "$0")")/kerl-home" + kerl_home="$(get_parent_dir 1)/kerl-home" mkdir -p "$kerl_home" export KERL_BASE_DIR="$kerl_home" - export KERL_BUILD_BACKEND="git" export KERL_CONFIG="$kerl_home/.kerlrc" - export KERL_DOWNLOAD_DIR="${ASDF_DOWNLOAD_PATH:-}" } update_available_versions() {