Skip to content

Commit

Permalink
Add wkdev-setup-default-clang script
Browse files Browse the repository at this point in the history
This allows easily installing and switching between different clang toolchains
  • Loading branch information
TingPing committed Oct 24, 2024
1 parent 3532ae8 commit 6947e62
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
10 changes: 6 additions & 4 deletions images/wkdev_sdk/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ COPY /rootfs/usr/bin/podman-host /usr/bin/podman-host

COPY /rootfs/etc/ccache.conf /etc/ccache.conf

# Convenience symlink for clang tools, the VSCode extension doesn't find these by default.
RUN for command in clang clang++ clangd clang-format clang-tidy lld lldb lldb-server lldb-vscode; do \
ln -s "/usr/bin/${command}-18" "/usr/local/bin/${command}"; \
done && ln -s "/usr/bin/lld-18" "/usr/local/bin/ld.lld";
# Convenience symlinks for clang tools, the VSCode extension doesn't find these by default.
# FIXME: Reduce code duplication with `wkdev-set-default-clang`.
RUN for binary in /usr/bin/*-18; do \
local binary_name="$(basename $binary)" \
ln -s "$binary" "/usr/local/bin/${binary_name::-3}" \
done

# Fix Qt6 system packages - missing symlinks in the Ubuntu-provided packages.
RUN export QT_VERSION=$(qmake6 -query QT_VERSION) && \
Expand Down
64 changes: 64 additions & 0 deletions scripts/container-only/wkdev-setup-default-clang
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 "${@}"

0 comments on commit 6947e62

Please sign in to comment.