From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH 2/8] llvm-utils.eclass: Split out PATH prepending logic
Date: Wed, 7 Feb 2024 21:11:37 +0100 [thread overview]
Message-ID: <20240207203515.17640-3-mgorny@gentoo.org> (raw)
In-Reply-To: <20240207203515.17640-1-mgorny@gentoo.org>
Split the logic prepending PATH from pkg_setup() into a dedicated
llvm_prepend_path() function.
Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
eclass/llvm-utils.eclass | 36 ++++++++++++++++++++++++++++++++++++
eclass/llvm.eclass | 25 +------------------------
eclass/tests/llvm-utils.sh | 24 ++++++++++++++++++++++++
3 files changed, 61 insertions(+), 24 deletions(-)
diff --git a/eclass/llvm-utils.eclass b/eclass/llvm-utils.eclass
index 43988f6f88c7..f308667e3dc2 100644
--- a/eclass/llvm-utils.eclass
+++ b/eclass/llvm-utils.eclass
@@ -112,4 +112,40 @@ llvm_fix_tool_path() {
${shopt_save}
}
+# @FUNCTION: llvm_prepend_path
+# @USAGE: <slot>
+# @DESCRIPTION:
+# Prepend the path to the specified LLVM slot to PATH variable,
+# and reexport it.
+llvm_prepend_path() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ${#} -ne 1 ]] && die "Usage: ${FUNCNAME} <slot>"
+ local slot=${1}
+
+ local llvm_path=${ESYSROOT}/usr/lib/llvm/${slot}/bin
+ local IFS=:
+ local split_path=( ${PATH} )
+ local new_path=()
+ local x added=
+
+ # prepend new path in front of the first LLVM version found
+ for x in "${split_path[@]}"; do
+ if [[ ${x} == */usr/lib/llvm/*/bin ]]; then
+ if [[ ${x} != ${llvm_path} ]]; then
+ new_path+=( "${llvm_path}" )
+ elif [[ ${added} && ${x} == ${llvm_path} ]]; then
+ # deduplicate
+ continue
+ fi
+ added=1
+ fi
+ new_path+=( "${x}" )
+ done
+ # ...or to the end of PATH
+ [[ ${added} ]] || new_path+=( "${llvm_path}" )
+
+ export PATH=${new_path[*]}
+}
+
fi
diff --git a/eclass/llvm.eclass b/eclass/llvm.eclass
index 05ffcfd7cc6d..e297fe992c9f 100644
--- a/eclass/llvm.eclass
+++ b/eclass/llvm.eclass
@@ -212,30 +212,7 @@ llvm_pkg_setup() {
llvm_fix_tool_path LLVM_CONFIG
fi
- local prefix=${ESYSROOT}
- local llvm_path=${prefix}/usr/lib/llvm/${LLVM_SLOT}/bin
- local IFS=:
- local split_path=( ${PATH} )
- local new_path=()
- local x added=
-
- # prepend new path before first LLVM version found
- for x in "${split_path[@]}"; do
- if [[ ${x} == */usr/lib/llvm/*/bin ]]; then
- if [[ ${x} != ${llvm_path} ]]; then
- new_path+=( "${llvm_path}" )
- elif [[ ${added} && ${x} == ${llvm_path} ]]; then
- # deduplicate
- continue
- fi
- added=1
- fi
- new_path+=( "${x}" )
- done
- # ...or to the end of PATH
- [[ ${added} ]] || new_path+=( "${llvm_path}" )
-
- export PATH=${new_path[*]}
+ llvm_prepend_path "${LLVM_SLOT}"
fi
}
diff --git a/eclass/tests/llvm-utils.sh b/eclass/tests/llvm-utils.sh
index 44ad1b4adc84..5a46b25b7ad6 100755
--- a/eclass/tests/llvm-utils.sh
+++ b/eclass/tests/llvm-utils.sh
@@ -66,6 +66,21 @@ test_fix_tool_path() {
tend ${?}
}
+test_prepend_path() {
+ local slot=${1}
+ local -x PATH=${2}
+ local expected=${3}
+
+ tbegin "llvm_prepend_path ${slot} to PATH=${PATH}"
+ llvm_prepend_path "${slot}"
+ if [[ ${PATH} != ${expected} ]]; then
+ eerror "llvm_prepend_path ${var}"
+ eerror " gave: ${PATH}"
+ 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
@@ -79,4 +94,13 @@ test_fix_tool_path RANLIB llvm-ranlib 1
test_fix_tool_path AR ar 1
test_fix_tool_path AR ar 0
+ESYSROOT=
+test_prepend_path 17 /usr/bin /usr/bin:/usr/lib/llvm/17/bin
+test_prepend_path 17 /usr/lib/llvm/17/bin:/usr/bin /usr/lib/llvm/17/bin:/usr/bin
+test_prepend_path 17 /usr/bin:/usr/lib/llvm/17/bin /usr/bin:/usr/lib/llvm/17/bin
+test_prepend_path 18 /usr/lib/llvm/17/bin:/usr/bin \
+ /usr/lib/llvm/18/bin:/usr/lib/llvm/17/bin:/usr/bin
+test_prepend_path 18 /usr/bin:/usr/lib/llvm/17/bin \
+ /usr/bin:/usr/lib/llvm/18/bin:/usr/lib/llvm/17/bin
+
texit
--
2.43.0
next prev parent reply other threads:[~2024-02-07 20:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-07 20:11 [gentoo-dev] [PATCH 0/8] llvm-r1.eclass + llvm-utils.eclass: new eclasses to sort out LLVM mess Michał Górny
2024-02-07 20:11 ` [gentoo-dev] [PATCH 1/8] llvm-utils.eclass: Introduce an eclass for common helpers Michał Górny
2024-02-07 20:11 ` Michał Górny [this message]
2024-02-07 20:11 ` [gentoo-dev] [PATCH 3/8] llvm-utils.eclass: Fix llvm_prepend_path to avoid duplicates Michał Górny
2024-02-08 19:06 ` [gentoo-dev] [PATCH] " Michał Górny
2024-02-07 20:11 ` [gentoo-dev] [PATCH 4/8] profiles: Introduce LLVM_SLOT USE_EXPAND variable Michał Górny
2024-02-07 20:11 ` [gentoo-dev] [PATCH 5/8] llvm-r1.eclass: Initial version Michał Górny
2024-02-08 19:07 ` [gentoo-dev] [PATCH v2] " Michał Górny
2024-02-09 16:59 ` [gentoo-dev] [PATCH v3] " Michał Górny
2024-02-09 23:49 ` Sam James
2024-02-07 20:11 ` [gentoo-dev] [PATCH 6/8] dev-util/intel_clc: Migrate to llvm-r1 Michał Górny
2024-02-08 7:00 ` Sam James
2024-02-08 12:35 ` Arsen Arsenović
2024-02-07 20:11 ` [gentoo-dev] [PATCH 7/8] media-libs/mesa: " Michał Górny
2024-02-07 20:11 ` [gentoo-dev] [PATCH 8/8] sys-devel/lld: Migrate to llvm-utils.eclass Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240207203515.17640-3-mgorny@gentoo.org \
--to=mgorny@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox