Skip to content

Commit

Permalink
llvm.eclass: Fix prepending LLVM path before system paths
Browse files Browse the repository at this point in the history
Do not prepend LLVM path before system path, in particular before
ccache/distcc paths.  Instead, prepend it before the first LLVM version
found in PATH, or append to the end if no LLVM is found in PATH.

Closes: https://bugs.gentoo.org/627726
Signed-off-by: Michał Górny <[email protected]>
  • Loading branch information
mgorny committed May 28, 2020
1 parent 2f90db9 commit f1e8874
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
25 changes: 23 additions & 2 deletions eclass/llvm.eclass
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,29 @@ llvm_pkg_setup() {
debug-print-function ${FUNCNAME} "${@}"

if [[ ${MERGE_TYPE} != binary ]]; then
local llvm_prefix=$(get_llvm_prefix "${LLVM_MAX_SLOT}")
export PATH=${llvm_prefix}/bin:${PATH}
local llvm_path=$(get_llvm_prefix "${LLVM_MAX_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[*]}
fi
}

Expand Down
16 changes: 8 additions & 8 deletions eclass/tests/llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,48 +91,48 @@ eindent
LLVM_MAX_SLOT=11 \
LLVM_INSTALLED_SLOT=1* \
PATH=${BASEPATH}:/usr/lib/llvm/11/bin \
check_setup_path "/usr/lib/llvm/11/bin:${BASEPATH}:/usr/lib/llvm/11/bin"
check_setup_path "${BASEPATH}:/usr/lib/llvm/11/bin"

LLVM_MAX_SLOT=10 \
LLVM_INSTALLED_SLOT=1* \
PATH=${BASEPATH}:/usr/lib/llvm/11/bin:/usr/lib/llvm/10/bin \
check_setup_path "/usr/lib/llvm/10/bin:${BASEPATH}:/usr/lib/llvm/11/bin:/usr/lib/llvm/10/bin"
check_setup_path "${BASEPATH}:/usr/lib/llvm/10/bin:/usr/lib/llvm/11/bin"

LLVM_MAX_SLOT=11 \
LLVM_INSTALLED_SLOT=10 \
PATH=${BASEPATH}:/usr/lib/llvm/10/bin \
check_setup_path "/usr/lib/llvm/10/bin:${BASEPATH}:/usr/lib/llvm/10/bin"
check_setup_path "${BASEPATH}:/usr/lib/llvm/10/bin"
eoutdent

ebegin "Testing pkg_setup with the other LLVM version in PATH"
eindent
LLVM_MAX_SLOT=11 \
LLVM_INSTALLED_SLOT=1* \
PATH=${BASEPATH}:/usr/lib/llvm/10/bin \
check_setup_path "/usr/lib/llvm/11/bin:${BASEPATH}:/usr/lib/llvm/10/bin"
check_setup_path "${BASEPATH}:/usr/lib/llvm/11/bin:/usr/lib/llvm/10/bin"

LLVM_MAX_SLOT=10 \
LLVM_INSTALLED_SLOT=1* \
PATH=${BASEPATH}:/usr/lib/llvm/11/bin \
check_setup_path "/usr/lib/llvm/10/bin:${BASEPATH}:/usr/lib/llvm/11/bin"
check_setup_path "${BASEPATH}:/usr/lib/llvm/10/bin:/usr/lib/llvm/11/bin"
eoutdent

ebegin "Testing pkg_setup with LLVM missing from PATH"
eindent
LLVM_MAX_SLOT=11 \
LLVM_INSTALLED_SLOT=1* \
PATH=${BASEPATH} \
check_setup_path "/usr/lib/llvm/11/bin:${BASEPATH}"
check_setup_path "${BASEPATH}:/usr/lib/llvm/11/bin"

LLVM_MAX_SLOT=10 \
LLVM_INSTALLED_SLOT=1* \
PATH=${BASEPATH} \
check_setup_path "/usr/lib/llvm/10/bin:${BASEPATH}"
check_setup_path "${BASEPATH}:/usr/lib/llvm/10/bin"

LLVM_MAX_SLOT=11 \
LLVM_INSTALLED_SLOT=10 \
PATH=${BASEPATH} \
check_setup_path "/usr/lib/llvm/10/bin:${BASEPATH}"
check_setup_path "${BASEPATH}:/usr/lib/llvm/10/bin"
eoutdent

texit

0 comments on commit f1e8874

Please sign in to comment.