Move $XCODE_APP handling and versioned clang-search to common_install

When changing the XCODE_APP the requested compiler may become available
so that has to be done before checking the compiler version to avoid
failing if the current system compiler doesn't match.
This commit is contained in:
Alexander Grund
2025-10-15 12:52:37 +02:00
parent 6cf3d9d48b
commit 61e14cb9ac
2 changed files with 44 additions and 37 deletions

View File

@@ -34,6 +34,13 @@ function print_on_gha {
set -x
}
if [ -n "${XCODE_APP:-}" ]; then
if [[ $XCODE_APP =~ ^[0-9]+.[0-9]+$ ]]; then
XCODE_APP="/Applications/Xcode_${XCODE_APP}.app"
fi
sudo xcode-select -switch "${XCODE_APP}"
fi
# Setup ccache
if [ "${B2_USE_CCACHE:-}" == "1" ]; then
if ! "$CI_DIR"/setup_ccache.sh 2>&1; then
@@ -137,14 +144,46 @@ if [[ "${B2_TOOLSET:-}" == clang* ]]; then
ls -ls "/usr/lib/llvm-${ver}/bin" || true
hash -r || true
fi
elif [ -n "${XCODE_APP:-}" ]; then
if [[ $XCODE_APP =~ ^[0-9]+.[0-9]+$ ]]; then
XCODE_APP="/Applications/Xcode_${XCODE_APP}.app/Contents/Developer"
else
# On macOS GHA try to find right clang version if a versioned clang was requested
if [[ "${RUNNER_OS:-}" == "macOS" ]] && [[ "${B2_COMPILER:-}" =~ "clang-" ]] && ! command -v "$B2_COMPILER"; then
clang_version=${B2_COMPILER#clang-}
system_clang_version=$(clang --version)
{ set +x; } &> /dev/null
if [[ ${system_clang_version} == *"clang version ${clang_version}."* ]]; then
echo "Using system clang: $(command -v clang)"
B2_COMPILER=clang
else
# When the default clang doesn't match the requested version try using the brew installed one
if brew_clang_prefix=$(brew --prefix "llvm@$clang_version"); then
if [[ -f "$brew_clang_prefix/bin/clang" ]]; then
echo "$brew_clang_prefix/bin" >> "$GITHUB_PATH"
echo "Found Clangs in HomeBrew: " "$brew_clang_prefix/bin/"clang* /opt/homebrew/opt/llvm/bin/clang*
export PATH="$brew_clang_prefix/bin:$PATH"
echo "Clang to be used: $(command -v clang)"
B2_COMPILER=clang
else
echo "Failed to find Clang $clang_version as requested from B2_COMPILER=${B2_COMPILER} in system or $brew_clang_prefix"
if [[ -d $brew_clang_prefix ]]; then
echo "Available brew binaries: $(ls "$brew_clang_prefix/bin")"
else
echo "HomeBrew installation is missing"
fi
exit 1
fi
else
echo "Failed to find Clang $clang_version as requested from B2_COMPILER=${B2_COMPILER}"
exit 1
fi
fi
set -x
fi
sudo xcode-select -switch "${XCODE_APP}"
fi
command -v clang || true
command -v clang++ || true
if [ -n "${B2_COMPILER:-}" ]; then
command -v "${B2_COMPILER}" || true
fi
# Additionally, if B2_TOOLSET is clang variant but CXX is set to g++
# (it is on Linux images) then boost build silently ignores B2_TOOLSET and
@@ -159,6 +198,7 @@ fi
# Set up user-config to actually use B2_COMPILER if set
userConfigPath=$HOME/user-config.jam
if [ -n "${B2_COMPILER:-}" ]; then
# shellcheck disable=SC2016
echo '$B2_COMPILER set. Configuring user-config'
# Get C++ compiler

View File

@@ -37,39 +37,6 @@ if [[ "$B2_SANITIZE" == "yes" ]]; then
fi
fi
if [[ "$RUNNER_OS" == "macOS" ]] && [[ "${B2_COMPILER:-}" =~ "clang-" ]] && ! command -v "$B2_COMPILER"; then
system_clang_version=$(clang --version)
{ set +x; } &> /dev/null
clang_version=${B2_COMPILER#clang-}
if [[ ${system_clang_version} == *"clang version ${clang_version}."* ]]; then
echo "Using system clang: $(command -v clang)"
B2_COMPILER=clang
else
# When the default clang doesn't match the requested version try using the brew installed one
if brew_clang_prefix=$(brew --prefix "llvm@$clang_version"); then
if [[ -f "$brew_clang_prefix/bin/clang" ]]; then
echo "$brew_clang_prefix/bin" >> "$GITHUB_PATH"
echo "Found Clangs in HomeBrew: " "$brew_clang_prefix/bin/"clang* /opt/homebrew/opt/llvm/bin/clang*
export PATH="$brew_clang_prefix/bin:$PATH"
echo "Clang to be used: $(command -v clang)"
B2_COMPILER=clang
else
echo "Failed to find Clang $clang_version as requested from B2_COMPILER=${B2_COMPILER} in system or $brew_clang_prefix"
if [[ -d $brew_clang_prefix ]]; then
echo "Available brew binaries: $(ls "$brew_clang_prefix/bin")"
else
echo "HomeBrew installation is missing"
fi
exit 1
fi
else
echo "Failed to find Clang $clang_version as requested from B2_COMPILER=${B2_COMPILER}"
exit 1
fi
fi
set -x
fi
. "$(dirname "${BASH_SOURCE[0]}")"/../common_install.sh
# Persist the environment for all future steps