-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wkdev-setup-default-clang script
This allows easily installing and switching between different clang toolchains
- Loading branch information
Showing
2 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2024 Igalia S.L. | ||
# SPDX-License: MIT | ||
|
||
if [ -f "${WKDEV_SDK}/.wkdev-sdk-root" ]; then | ||
source "${WKDEV_SDK}/utilities/application.sh" | ||
else | ||
echo "Please set \${WKDEV_SDK} to point to the root of the wkdev-sdk checkout." | ||
exit 1 | ||
fi | ||
|
||
init_application "${0}" "Installs and creates symlinks to set default clang executables" container-only | ||
|
||
argsparse_use_option "=version:" "The clang version" "mandatory" "type:uint" | ||
|
||
|
||
argsparse_usage_description="$(cat <<EOF | ||
<< Purpose >> | ||
Provides an easy way to install and switch between clang toolchains. | ||
<< Examples >> | ||
$ ${application_name} --version=17 | ||
EOF | ||
)" | ||
|
||
run() { | ||
|
||
argsparse_parse_options "${@}" | ||
local version="${program_options["version"]}" | ||
|
||
echo "" | ||
|
||
# Sanity check versions Ubuntu actually has. | ||
if (( $version < 14 )) || (( $version > 18)); then | ||
echo "$version is not a valid value (between 14-18)." | ||
exit 1 | ||
fi | ||
|
||
if [ ! -f "/usr/bin/clang-$version" ]; then | ||
echo "Installing clang toolchain version $version" | ||
echo "" | ||
if ! sudo apt-get install "clang-tools-$version" "clangd-$version" "clang-format-$version" "clang-tidy-$version" "lld-$version" "lldb-$version"; then | ||
echo "" | ||
echo "Failed to install clang toolchain" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
local output_path | ||
if [ "$EUID" -eq 0 ]; then | ||
output_path='/usr/local/bin' | ||
else | ||
output_path="$HOME/.local/bin" | ||
fi | ||
echo "Creating symlinks in $output_path" | ||
for binary in /usr/bin/*-"$version"; do | ||
local binary_name="$(basename $binary)" | ||
ln --symbolic --force "$binary" "${output_path}/${binary_name::-3}" | ||
done | ||
} | ||
|
||
run "${@}" |