Skip to content

Commit

Permalink
add toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
supperthomas committed Sep 13, 2024
1 parent 44189c3 commit d35a73c
Showing 1 changed file with 47 additions and 46 deletions.
93 changes: 47 additions & 46 deletions tools/ci/toolchain.sh
Original file line number Diff line number Diff line change
@@ -1,58 +1,59 @@
#!/bin/bash

# 定义从YML文件获取所有工具链链接的函数
get_all_toolchains() {
local script_dir="$(dirname "$(readlink -f "$0")")"
local yml_file="$script_dir/toolchain_bsp.yml"
if [ ! -f "$yml_file" ]; then
echo "YML file not found in the script's directory."
exit 1
fi
all_urls=$(grep 'http' "$yml_file" | sed 's/.*: //')
echo "$all_urls"
# 定义工具链下载链接
declare -A download_urls=(
["arm-none-eabi-gcc"]="https://github.com/RT-Thread/toolchains-ci/releases/download/v1.3/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2"
["mips-sde-elf-gcc"]="https://github.com/RT-Thread/toolchains-ci/releases/download/v1.6/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf.tar.xz"
["riscv64-unknown-elf-gcc"]="https://github.com/RT-Thread/toolchains-ci/releases/download/v1.4/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz"
["riscv32-unknown-elf-gcc"]="https://github.com/hpmicro/riscv-gnu-toolchain/releases/download/2022.05.15/riscv32-unknown-elf-newlib-multilib_2022.05.15_linux.tar.gz"
["llvm-arm"]="https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-16.0.0/LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64.tar.gz"
["riscv-none-embed-gcc"]="https://github.com/RT-Thread/toolchains-ci/releases/download/v1.5/xpack-riscv-none-embed-gcc-8.3.0-2.3-linux-x64.tar.gz"
["riscv32-esp-elf-gcc"]="https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz"
["clang"]="https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-16.0.0/LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64.tar.gz"

)

show_help() {
echo "Available toolchains:"
for key in "${!download_urls[@]}"; do
echo " - $key"
done
}

extract_file() {
local file_name=$1
local destination=${2:-/opt} # 默认解压到/opt目录
case "$file_name" in
*.tar.bz2) tar -xjf "$file_name" -C "$destination";;
*.tar.gz) tar -xzf "$file_name" -C "$destination";;
*.tar.xz) tar -xJf "$file_name" -C "$destination";;
*) echo "Unsupported file format: $file_name"; exit 1;;
esac
echo "Extracted to $destination"
}

get_download_url() {
install_toolchain() {
local toolchain_name=$1
local yml_file="$script_dir/toolchain_bsp.yml"
if [ ! -f "$yml_file" ]; then
echo "YML file not found in the script's directory."
local url="${download_urls[$toolchain_name]}"
if [ -z "$url" ]; then
echo "Toolchain not found."
exit 1
fi
# 查找特定工具链名称的下载链接
download_url=$(curl -s $yml_file | grep -A 1 "$toolchain_name" | grep 'http' | sed 's/.*: //')
echo $download_url
local file_name=$(basename "$url")
echo "Downloading $file_name..."
wget -q "$url"
echo "Extracting $file_name..."
extract_file "$file_name"
local extracted_dir="/opt/$(basename "$file_name" .tar.*)"
echo "Installed: $extracted_dir"
}

if [ $# -lt 1 ]; then
echo "Usage: $0 <toolchain_name | all>"
exit 1
fi

toolchain_name=$1

if [ "$toolchain_name" == "all" ]; then
urls=$(get_all_toolchains)
for url in $urls; do
file_name=$(basename $url)
echo "Downloading $file_name..."
wget -q $url
echo "Extracting $file_name..."
sudo tar xjf $file_name -C /opt
extracted_dir="/opt/$(basename $file_name .tar.bz2)"
echo "Installed: $extracted_dir"
if [[ "$1" == "help" ]]; then
show_help
elif [ "$1" == "all" ]; then
for toolchain in "${!download_urls[@]}"; do
install_toolchain "$toolchain"
done
else
# 单个工具链的安装
download_url=$(get_download_url $toolchain_name)
if [ -z "$download_url" ]; then
echo "Toolchain not found in yml file."
exit 1
fi
file_name=$(basename $download_url)
echo "Downloading $file_name..."
wget -q $download_url
echo "Extracting $file_name..."
sudo tar xjf $file_name -C /opt
extracted_dir="/opt/$(basename $file_name .tar.bz2)"
install_toolchain "$1"
fi

0 comments on commit d35a73c

Please sign in to comment.