Skip to content

Commit

Permalink
* Will use existing kerl from $PATH (like installed by Homebrew) or…
Browse files Browse the repository at this point in the history
… fetch specific version when setting `ASDF_KERL_VERSION`.

* Will use git to clone `kerl` quitly and checkout versioned tags instead of downloading from Github CDN.

* Enable shell docs out of the box by default and allow opt out using `KERL_BUILD_DOCS="no" - technically any value will opt out, kerl just checks if it's set, and not its value. Since we're opting in by default, we will check `!= "yes"` for opt out.

* Will come with out of the box settings for `KERL_CONFIGURE_OPTIONS` with additional settings for macOS that matches `Homebrew`
	* `--disable-debug`
	* `--disable-silent-rules`
	* `--enable-dynamic-ssl-lib`
	* `--enable-hipe`
	* `--enable-sctp`
	* `--enable-shared-zlib`
	* `--enable-smp-support`
	* `--enable-threads`
	* `--enable-wx`
	* `--without-javac`
	* macOS only:
		* `--with-ssl=$(brew --prefix openssl)`
		* `--enable-darwin-64bit`
		* `--enable-kernel-poll`
		* `--with-dynamic-trace=dtrace`

* macOS only: Unless custom `KERL_CONFIGURE_OPTIONS`, asdf-erlang will default to using Homebrew for following dependencies:
	- `autoconf`
 	- `libtool`
 	- `openssl`
 	- `wxmac`

This will allow `asdf-erlang` & `asdf-elixir` to be used out of the box and be much easier for majority of macOS users.
Avoiding using esotoric configuration and environment variables to keep track for various plugins should be a focus.
Allowing someone to just put a plugin in, and pick a version without sifting through massive documentation and configuration is beneficial.
  • Loading branch information
seivan committed Mar 14, 2021
1 parent 72d3187 commit c258e08
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 50 deletions.
64 changes: 62 additions & 2 deletions bin/install
Original file line number Diff line number Diff line change
@@ -1,12 +1,71 @@
#!/usr/bin/env bash

export KERL_BUILD_DOCS="${KERL_BUILD_DOCS:-yes}"

set -e

# shellcheck source=../bin/utils.sh
source "$(dirname "$0")/utils.sh"

# shellcheck source=../lib/utils.sh
source "$(dirname $0)/../lib/utils.sh"

install_erlang() {
ensure_kerl_setup


if [ -z "$KERL_CONFIGURE_OPTIONS" ]; then
echo "KERL_CONFIGURE_OPTIONS is not set, will use default settings."

export KERL_CONFIGURE_OPTIONS="--disable-debug --disable-silent-rules --enable-dynamic-ssl-lib"
export KERL_CONFIGURE_OPTIONS="$KERL_CONFIGURE_OPTIONS --enable-hipe --enable-sctp --enable-shared-zlib --enable-smp-support"
export KERL_CONFIGURE_OPTIONS="$KERL_CONFIGURE_OPTIONS --enable-threads --enable-wx --without-javac"

if [ "$(uname -s)" = "Darwin" ]; then
echo "Using Homebrew for dependencies."
if [ -x "$(command -v brew)" ]; then
if [ ! -d "$(brew --prefix autoconf)" ]; then
echo "Missing autoconf from Homebrew"
echo "brew install autoconf"
exit 1
fi
if [ ! -d "$(brew --prefix libtool)" ]; then
echo "Missing libtool from Homebrew"
echo "brew install libtool"
exit 1
fi
if [ ! -d "$(brew --prefix openssl)" ]; then
echo "Missing openssl from Homebrew"
echo "brew install openssl"
exit 1
fi
if [ ! -d "$(brew --prefix wxmac)" ]; then
echo "Missing wxmac from Homebrew"
echo "brew install wxmac"
exit 1
fi
export KERL_CONFIGURE_OPTIONS="$KERL_CONFIGURE_OPTIONS --with-ssl=$(brew --prefix openssl) --enable-darwin-64bit --enable-kernel-poll --with-dynamic-trace=dtrace"
else
echo "Homebrew is not installed or in PATH"
echo "To install without Homebrew, set your own KERL_CONFIGURE_OPTIONS"
fi
fi
fi






echo "Installing Erlang $ASDF_INSTALL_VERSION"
if [ "$KERL_BUILD_DOCS" != "yes" ]; then
unset KERL_BUILD_DOCS
echo "without documentation"
else
echo "with documentation"
fi
echo "With KERL_CONFIGURE_OPTIONS set to: "
echo "$KERL_CONFIGURE_OPTIONS"
echo "---"

local asdf_activation_version
local build_name

Expand All @@ -17,6 +76,7 @@ install_erlang() {
$(kerl_path) delete installation "$build_name" || true
$(kerl_path) delete build "$build_name" || true


if [ "$ASDF_INSTALL_TYPE" = "ref" ]; then
asdf_activation_version="$ASDF_INSTALL_TYPE:$ASDF_INSTALL_VERSION"
$(kerl_path) build git "${OTP_GITHUB_URL:-https://github.com/erlang/otp.git}" "$ASDF_INSTALL_VERSION" "$build_name"
Expand Down
5 changes: 3 additions & 2 deletions bin/list-all
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env bash

source "$(dirname $0)/utils.sh"
# shellcheck source=../lib/utils.sh
source "$(dirname $0)/../lib/utils.sh"


list_all() {
ensure_kerl_setup

echo "$("$(kerl_path)" list releases | sed -e 's:Run.*::' | tr '\n' ' ')"
}

Expand Down
3 changes: 2 additions & 1 deletion bin/uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

set -e

source "$(dirname $0)/utils.sh"
# shellcheck source=../lib/utils.sh
source "$(dirname $0)/../lib/utils.sh"

ensure_kerl_setup

Expand Down
45 changes: 0 additions & 45 deletions bin/utils.sh

This file was deleted.

74 changes: 74 additions & 0 deletions lib/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
KERL_VERSION="${ASDF_KERL_VERSION:-2.1.0}"


echoerr() {
>&2 echo -e "\033[0;31m$1\033[0m"
}

ensure_kerl_setup() {
export KERL_BASE_DIR="$(kerl_dir)"
export KERL_CONFIG="$(kerl_dir)/kerlrc"
#export KERL_BUILD_BACKEND="git"
ensure_kerl_installed
}

ensure_kerl_installed() {
# If kerl exists
if [ -x "$(kerl_path)" ]; then
# But was passed an expected version
if [ -n "${ASDF_KERL_VERSION:-}" ]; then
current_kerl_version="$("$(kerl_path)" version)"
# Check if expected version matches current version
if [ "$current_kerl_version" != "$KERL_VERSION" ]; then
# If not, reinstall with ASDF_KERL_VERSION
download_kerl
fi
fi
else
# kerl does not exist, so install using default value in KERL_VERSION
download_kerl
fi
}



download_kerl() {
# Remove directory in case it still exists from last download
rm -rf "$(kerl_source_dir)"
rm -rf "$(kerl_dir)"

# Print to stderr so asdf doesn't assume this string is a list of versions
echoerr "Downloading kerl $KERL_INSTALL_VERSION"

# Clone down and checkout the correct kerl version
git clone https://github.com/kerl/kerl.git "$(kerl_source_dir)" --quiet
(cd "$(kerl_source_dir)"; git checkout $KERL_INSTALL_VERSION --quiet;)

mkdir -p "$(kerl_dir)/bin"
mv "$(kerl_source_dir)/kerl" "$(kerl_path)"
chmod +x "$(kerl_path)"

rm -rf "$(kerl_source_dir)"
}

asdf_erlang_plugin_path() {
echo "$(dirname "$(dirname "$0")")"
}

kerl_dir() {
echo "$(asdf_erlang_plugin_path)/kerl"
}

kerl_source_dir() {
echo "$(asdf_erlang_plugin_path)/kerl-install-source"
}


kerl_path() {
#Check if kerl exists without an expected version
if [ -x "$(command -v kerl)" ] && [ -z "${ASDF_KERL_VERSION:-}" ]; then
echo "$(command -v kerl)"
else
echo "$(kerl_dir)/bin/kerl"
fi
}

0 comments on commit c258e08

Please sign in to comment.