Skip to content

Commit 2ffd018

Browse files
committed
wip
1 parent ac6384d commit 2ffd018

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

bin/install

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ set -euo pipefail
44

55
current_script_path=${BASH_SOURCE[0]}
66
plugin_dir=$(dirname "$(dirname "$current_script_path")")
7+
toolname=$(basename "$plugin_dir")
78

89
# shellcheck source=../lib/utils.bash
910
source "${plugin_dir}/lib/utils.bash"
1011

11-
install_version "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
12+
install_version "${toolname}" "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"

bin/list-all

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ set -euo pipefail
44

55
current_script_path=${BASH_SOURCE[0]}
66
plugin_dir=$(dirname "$(dirname "$current_script_path")")
7+
toolname=$(basename "$plugin_dir")
78

89
# shellcheck source=../lib/utils.bash
910
source "${plugin_dir}/lib/utils.bash"
1011

11-
list_all_versions | sort_versions | xargs echo
12+
list_all_versions "${toolname}" | sort_versions | xargs echo

lib/utils.bash

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
set -euo pipefail
44

55
# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for clang-tools-static.
6-
GH_REPO="https://github.com/amrox/clang-tools-static"
6+
GH_REPO="muttleyxd/clang-tools-static-binaries"
7+
GH_REPO_URL="https://github.com/${GH_REPO}"
78
TOOL_NAME="clang-tools-static"
89
TOOL_TEST="clang-format"
910

@@ -25,15 +26,67 @@ sort_versions() {
2526
}
2627

2728
list_github_tags() {
28-
git ls-remote --tags --refs "$GH_REPO" |
29+
git ls-remote --tags --refs "$GH_REPO_URL" |
2930
grep -o 'refs/tags/.*' | cut -d/ -f3- |
3031
sed 's/^v//' # NOTE: You might want to adapt this sed to remove non-version strings from tags
3132
}
3233

34+
fetch_all_assets() {
35+
curl -H "Accept: application/vnd.github.v3+json" \
36+
https://api.github.com/repos/${GH_REPO}/releases |
37+
jq -r '.[0].assets[] | "\(.name) \(.browser_download_url)"'
38+
}
39+
40+
get_kernel() {
41+
42+
local kernel
43+
kernel=$(uname -s)
44+
45+
case $kernel in
46+
Darwin)
47+
echo -n "macosx"
48+
;;
49+
Linux)
50+
echo -n "linux"
51+
;;
52+
esac
53+
54+
echo -n ""
55+
}
56+
57+
get_arch() {
58+
local arch
59+
arch=$(uname -m)
60+
61+
case $arch in
62+
x86_64)
63+
platform="amd64"
64+
;;
65+
*)
66+
fail "Unsupported arch $arch"
67+
exit 1
68+
;;
69+
esac
70+
71+
echo -n "$arch"
72+
73+
}
74+
3375
list_all_versions() {
34-
# TODO: Adapt this. By default we simply list the tag names from GitHub releases.
35-
# Change this function if clang-tools-static has other means of determining installable versions.
36-
list_github_tags
76+
77+
local toolname=$1
78+
79+
local platform arch
80+
platform=$(get_platform)
81+
arch=$(get_arch)
82+
83+
fetch_all_assets |
84+
grep "$toolname" |
85+
grep "$platform" |
86+
grep "$arch" |
87+
grep -v "sha" |
88+
awk '{print $1}' |
89+
sed "s/^${toolname}-\(.*\)_.*/\1/"
3790
}
3891

3992
download_release() {
@@ -42,7 +95,7 @@ download_release() {
4295
filename="$2"
4396

4497
# TODO: Adapt the release URL convention for clang-tools-static
45-
url="$GH_REPO/archive/v${version}.tar.gz"
98+
url="$GH_REPO_URL/archive/v${version}.tar.gz"
4699

47100
echo "* Downloading $TOOL_NAME release $version..."
48101
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"

0 commit comments

Comments
 (0)