Skip to content

Commit

Permalink
Refactor and add LD_LIBRARY_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakski committed Jan 10, 2024
1 parent 3eefdfa commit 864dd90
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 128 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
@@ -1,7 +1,7 @@
root = true

[*]
indent_style = space
[bin/*]
indent_style = tab
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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 empty string.
Plugin:

Expand Down
40 changes: 22 additions & 18 deletions bin/download
Expand Up @@ -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
9 changes: 9 additions & 0 deletions 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
35 changes: 30 additions & 5 deletions bin/install
Expand Up @@ -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
16 changes: 9 additions & 7 deletions bin/list-all
Expand Up @@ -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 "
94 changes: 0 additions & 94 deletions lib/utils.bash

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/shellcheck.bash
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

exec shellcheck -s bash -x \
bin/* -P lib/
bin/* -P lib/

0 comments on commit 864dd90

Please sign in to comment.