diff --git a/.editorconfig b/.editorconfig index 1923d41..8ce7973 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,7 +1,7 @@ root = true -[*] -indent_style = space +[bin/*] +indent_style = tab indent_size = 2 charset = utf-8 trim_trailing_whitespace = true diff --git a/README.md b/README.md index 6c5fcb2..b499fe0 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ # Install -> asdf-janet will automatically install JPM from master branch. You disable JPM installation by setting environment variable `JPM_TAG` to empty string. +> asdf-janet will automatically install JPM from master branch. You disable JPM installation by setting environment variable `JPM_REF` to space(`JPM_REF=""`). Plugin: diff --git a/bin/download b/bin/download index 80abb60..b47c82e 100755 --- a/bin/download +++ b/bin/download @@ -2,21 +2,25 @@ set -euo pipefail -current_script_path=${BASH_SOURCE[0]} -plugin_dir=$(dirname "$(dirname "$current_script_path")") - -# shellcheck source=../lib/utils.bash -source "${plugin_dir}/lib/utils.bash" - -mkdir -p "$ASDF_DOWNLOAD_PATH" - -release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz" - -# Download tar.gz file to the download directory -download_release "$ASDF_INSTALL_VERSION" "$release_file" - -# Extract contents of tar.gz file into the download directory -tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file" - -# Remove the tar.gz file since we don't need to keep it -rm "$release_file" +declare \ + janet_repo="https://github.com/janet-lang/janet" \ + janet_version=$ASDF_INSTALL_VERSION \ + jpm_repo="https://github.com/janet-lang/jpm" +declare -a curl_opts=(-fsSL) + +if [ -n "${GITHUB_API_TOKEN:-}" ]; then + curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN") +fi +if [ "$ASDF_INSTALL_TYPE" = "version" ]; then + janet_version="v${janet_version}" +fi +if [ ! -d "${ASDF_DOWNLOAD_PATH}/janet" ]; then + mkdir -p "${ASDF_DOWNLOAD_PATH}/janet" + curl "${curl_opts[@]}" "${janet_repo}/archive/${janet_version}.tar.gz" | + tar -C "${ASDF_DOWNLOAD_PATH}/janet" --strip-components=1 -xzf - +fi +if [ "${JPM_REF:-"master"}" != " " ] && [ ! -d "${ASDF_DOWNLOAD_PATH}/jpm" ]; then + mkdir -p "${ASDF_DOWNLOAD_PATH}/jpm" + curl "${curl_opts[@]}" "${jpm_repo}/archive/${JPM_REF:-"master"}.tar.gz" | + tar -C "${ASDF_DOWNLOAD_PATH}/jpm" --strip-components=1 -xzf - +fi diff --git a/bin/exec-env b/bin/exec-env new file mode 100755 index 0000000..f1ef286 --- /dev/null +++ b/bin/exec-env @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if [ -v LD_LIBRARY_PATH ]; then + export LD_LIBRARY_PATH="${ASDF_INSTALL_PATH}/bin:${LD_LIBRARY_PATH}/lib" +else + export LD_LIBRARY_PATH="${ASDF_INSTALL_PATH}/lib" +fi diff --git a/bin/install b/bin/install index 9737a63..03bb437 100755 --- a/bin/install +++ b/bin/install @@ -2,10 +2,35 @@ set -euo pipefail -current_script_path=${BASH_SOURCE[0]} -plugin_dir=$(dirname "$(dirname "$current_script_path")") +declare git_hash -# shellcheck source=../lib/utils.bash -source "${plugin_dir}/lib/utils.bash" +if [ "$ASDF_INSTALL_TYPE" = "version" ]; then + git_hash="meson" +else + git_hash="$ASDF_INSTALL_VERSION" +fi -install_version "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH" +if [ -v LD_LIBRARY_PATH ]; then + export LD_LIBRARY_PATH="${ASDF_INSTALL_PATH}/bin:${LD_LIBRARY_PATH}/lib" +else + export LD_LIBRARY_PATH="${ASDF_INSTALL_PATH}/lib" +fi + +mkdir -p "$ASDF_INSTALL_PATH" +pushd "${ASDF_DOWNLOAD_PATH}/janet" >/dev/null +meson setup build \ + --buildtype release \ + --optimization 2 \ + --prefix "$ASDF_INSTALL_PATH" \ + --libdir "${ASDF_INSTALL_PATH}/lib" \ + -Dgit_hash="$git_hash" +ninja -C build -j "${ASDF_CONCURRENCY:-1}" +ninja -C build install -j "${ASDF_CONCURRENCY:-1}" +popd >/dev/null +[ -x "${ASDF_INSTALL_PATH}/bin/janet" ] +if [ "${JPM_REF:-"master"}" != " " ]; then + pushd "${ASDF_DOWNLOAD_PATH}/jpm" >/dev/null + PREFIX="$ASDF_INSTALL_PATH" "${ASDF_INSTALL_PATH}/bin/janet" bootstrap.janet + popd >/dev/null + [ -x "${ASDF_INSTALL_PATH}/bin/jpm" ] +fi diff --git a/bin/list-all b/bin/list-all index 943371e..23fa2d2 100755 --- a/bin/list-all +++ b/bin/list-all @@ -2,10 +2,12 @@ set -euo pipefail -current_script_path=${BASH_SOURCE[0]} -plugin_dir=$(dirname "$(dirname "$current_script_path")") - -# shellcheck source=../lib/utils.bash -source "${plugin_dir}/lib/utils.bash" - -list_all_versions | sort_versions | xargs echo +declare janet_repo="https://github.com/janet-lang/janet" +git ls-remote --tags --refs "$janet_repo" | + grep -o 'refs/tags/.*' | + cut -d/ -f3- | + sed 's/^v//' | + sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | + LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | + awk '{print $2}' | + xargs printf "%s " diff --git a/lib/utils.bash b/lib/utils.bash deleted file mode 100644 index 0ca9c3d..0000000 --- a/lib/utils.bash +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -GH_REPO="https://github.com/janet-lang/janet" -GH_REPO_JPM="https://github.com/janet-lang/jpm" -TOOL_NAME="janet" -TOOL_TEST="janet -v" -JPM_TAG=${JPM_TAG:-master} - -fail() { - echo -e "asdf-$TOOL_NAME: $*" - exit 1 -} - -curl_opts=(-fsSL) - -# NOTE: You might want to remove this if janet is not hosted on GitHub releases. -if [ -n "${GITHUB_API_TOKEN:-}" ]; then - curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN") -fi - -sort_versions() { - sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | - LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' -} - -list_github_tags() { - git ls-remote --tags --refs "$GH_REPO" | - grep -o 'refs/tags/.*' | cut -d/ -f3- | - sed 's/^v//' # NOTE: You might want to adapt this sed to remove non-version strings from tags -} - -list_all_versions() { - list_github_tags -} - -download_release() { - local version filename url - version="$1" - filename="$2" - if [ "$ASDF_INSTALL_TYPE" = "version" ]; then - version="v${version}" - fi - - url="$GH_REPO/archive/${version}.tar.gz" - - echo "* Downloading $TOOL_NAME $version..." - curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url" -} - -install_version() { - local install_type="$1" - local version="$2" - local install_path="$3" - local tool_cmd - tool_cmd="${install_path}/bin/$(echo "$TOOL_TEST" | cut -d' ' -f1)" - local git_hash - if [ "$ASDF_INSTALL_TYPE" = "version" ]; then - git_hash="meson" - else - git_hash="$ASDF_INSTALL_VERSION" - fi - - ( - mkdir -p "$install_path" - pushd "$ASDF_DOWNLOAD_PATH" - meson setup build \ - --buildtype release \ - --optimization 2 \ - --prefix "$install_path" \ - --libdir "${install_path}/lib" \ - -Dgit_hash="$git_hash" - ninja -C build - ninja -C build install - if [ -n "$JPM_TAG" ]; then - local jpm_url="${GH_REPO_JPM}/archive/${JPM_TAG}.tar.gz" - mkdir "${ASDF_DOWNLOAD_PATH}/jpm" - curl "${curl_opts[@]}" "$jpm_url" | tar -C "${ASDF_DOWNLOAD_PATH}/jpm" -xzf - --strip-components=1 || - fail "Could not extract JPM archive" - pushd "${ASDF_DOWNLOAD_PATH}/jpm" - PREFIX="$install_path" "$tool_cmd" bootstrap.janet - popd - fi - popd - - test -x "$tool_cmd" || fail "Expected $tool_cmd to be executable." - - echo "$TOOL_NAME $version installation was successful!" - ) || ( - rm -rf "$install_path" - fail "An error ocurred while installing $TOOL_NAME $version." - ) -} diff --git a/scripts/shellcheck.bash b/scripts/shellcheck.bash index 6d28a72..7e35d19 100755 --- a/scripts/shellcheck.bash +++ b/scripts/shellcheck.bash @@ -1,4 +1,4 @@ #!/usr/bin/env bash exec shellcheck -s bash -x \ - bin/* -P lib/ + bin/* -P lib/