diff options
author | Michał Górny <mgorny@gentoo.org> | 2024-02-07 17:34:34 +0100 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2024-02-10 11:47:20 +0100 |
commit | 511ce42e90eccd89a8d0d2ccbc239578d6af11ea (patch) | |
tree | 365ed5513145bc74151ce3317f0cdf6c8b71dec8 /eclass/tests | |
parent | profiles.desc: Add ppc64(le) 23.0 profiles (diff) | |
download | gentoo-511ce42e90eccd89a8d0d2ccbc239578d6af11ea.tar.gz gentoo-511ce42e90eccd89a8d0d2ccbc239578d6af11ea.tar.bz2 gentoo-511ce42e90eccd89a8d0d2ccbc239578d6af11ea.zip |
llvm-utils.eclass: Introduce an eclass for common helpers
Move some reusable functions from llvm.eclass to llvm-utils.eclass.
This is with minimal modifications so far (only argument checks were
cleaned up).
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass/tests')
-rwxr-xr-x | eclass/tests/llvm-utils.sh | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/eclass/tests/llvm-utils.sh b/eclass/tests/llvm-utils.sh new file mode 100755 index 000000000000..44ad1b4adc84 --- /dev/null +++ b/eclass/tests/llvm-utils.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# Copyright 2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +source tests-common.sh || exit + +EAPI=8 + +inherit llvm-utils + +test_fix_clang_version() { + local var=${1} + local tool=${2} + local version=${3} + local expected=${4} + + eval "${tool}() { + cat <<-EOF + clang version ${version} + Target: x86_64-pc-linux-gnu + Thread model: posix + InstalledDir: /usr/lib/llvm/17/bin + Configuration file: /etc/clang/x86_64-pc-linux-gnu-clang.cfg + EOF + }" + + declare -g ${var}=${tool} + tbegin "llvm_fix_clang_version ${var}=${tool} for ${version}" + llvm_fix_clang_version "${var}" + if [[ ${!var} != ${expected} ]]; then + eerror "llvm_fix_clang_version ${var}" + eerror " gave: ${!var}" + eerror "expected: ${expected}" + fi + tend ${?} +} + +test_fix_tool_path() { + local var=${1} + local tool=${2} + local expected_subst=${3} + local expected=${tool} + + tbegin "llvm_fix_tool_path ${1}=${2} (from llvm? ${expected_subst})" + + local matches=( "${BROOT}"/usr/lib/llvm/*/bin/"${tool}" ) + if [[ ${expected_subst} == 1 ]]; then + if [[ ! -x ${matches[0]} ]]; then + ewarn "- skipping, test requires ${tool}" + return + fi + + expected=${matches[0]} + local -x PATH=${matches[0]%/*} + else + local -x PATH= + fi + + declare -g ${var}=${tool} + llvm_fix_tool_path "${var}" + if [[ ${!var} != ${expected} ]]; then + eerror "llvm_fix_tool_path ${var}" + eerror " gave: ${!var}" + eerror "expected: ${expected}" + fi + tend ${?} +} + +test_fix_clang_version CC clang 19.0.0git78b4e7c5 clang-19 +test_fix_clang_version CC clang 17.0.6 clang-17 +test_fix_clang_version CXX clang++ 17.0.6 clang++-17 +test_fix_clang_version CC x86_64-pc-linux-gnu-clang 17.0.6 \ + x86_64-pc-linux-gnu-clang-17 +test_fix_clang_version CC clang-17 n/a clang-17 +test_fix_clang_version CC gcc n/a gcc + +test_fix_tool_path AR llvm-ar 1 +test_fix_tool_path RANLIB llvm-ranlib 1 +test_fix_tool_path AR ar 1 +test_fix_tool_path AR ar 0 + +texit |