...
 
Commits (2)
......@@ -134,37 +134,52 @@ find_compilers() {
ls {cc,cpp,[gc]++,gcc}{,-*} 2>/dev/null || true
}
patch_scl_ccache() {
local name="$1"
local cache_path="$2"
echo "Ensuring SCL ${name} supports ccache..."
# This is the only good way to re-add ccache to top of PATH
# scl enable (inside icinga2.spec) will set its own path first
local enable_file="/opt/rh/${name}/enable"
local line="PATH=\"${cache_path}:\${PATH}\""
if ! grep -qF "${line}" "${enable_file}"; then
echo "Adding '${line}' to ${enable_file}"
sudo sh -ec "echo '${line}' >>'${enable_file}'"
fi
}
# repair/prepare ccache (needed on some distros like CentOS 5 + 6, SUSE, OpenSUSE)
preconfigure_ccache() {
CCACHE_LINKS="$(rpm -E %_libdir)"/ccache
IFS=" " read -r -a compilers <<< "$(find_compilers)"
if [ -e /opt/rh/devtoolset-2/enable ]; then
IFS=" " read -r -a extra_compilers <<< "$(find_compilers /opt/rh/devtoolset-2/root/usr/bin)"
compilers+=("${extra_compilers[@]}")
fi
sudo sh -ex <<CCACHEREPAIR
test -d ${CCACHE_LINKS} || mkdir ${CCACHE_LINKS}
cd ${CCACHE_LINKS}
echo 'Preparing/Repairing ccache symlinks...'
for comp in ${compilers[@]}; do
[ ! -e \${comp} ] || continue
ln -svf /usr/bin/ccache \${comp}
devtoolsets=''
if [ -d /opt/rh ]; then
devtoolsets="$(cd /opt/rh && ls -d devtoolset-*)"
for devtoolset in $devtoolsets; do
patch_scl_ccache "$devtoolset" "${CCACHE_LINKS}"
IFS=" " read -r -a extra_compilers <<< "$(find_compilers "/opt/rh/${devtoolset}/root/usr/bin")"
compilers+=("${extra_compilers[@]}")
done
CCACHEREPAIR
if [ -e /opt/rh/devtoolset-2/enable ]; then
echo "Patching devtoolset-2 to use ccache..."
# This is the only good way to re-add ccache to top of PATH
# scl enable (inside icinga2.spec) will set its own path first
sudo sh -ex <<SUDOSCRIPT
echo 'PATH="${CCACHE_LINKS}:\${PATH}" to /opt/rh/devtoolset-2/enable'
echo 'PATH="${CCACHE_LINKS}:\${PATH}"' >> /opt/rh/devtoolset-2/enable
SUDOSCRIPT
else
# Enable ccache as a default wrapper for compilers
PATH="${CCACHE_LINKS}:${PATH}"
fi
echo 'Preparing/Repairing ccache symlinks...'
(
set -e
test -d "${CCACHE_LINKS}" || sudo mkdir "${CCACHE_LINKS}"
cd "${CCACHE_LINKS}"
for comp in "${compilers[@]}"; do
[ ! -e "${comp}" ] || continue
sudo ln -svf /usr/bin/ccache "${comp}"
done
)
# Enable ccache as a default wrapper for compilers
PATH="${CCACHE_LINKS}:${PATH}"
}
: "${ICINGA_BUILD_PROJECT:="$(detect_project)"}"
......
......@@ -77,7 +77,7 @@ eval "$(get_rpmbuild --rebuild "${source_rpm}")"
# of the tools we build (happens with Icinga 2 and wxWidgets)
unset arch
if [ -e /opt/rh/devtoolset-2 ]; then
if [ -n "${ICINGA_BUILD_DEVTOOLSET_2:-}" ] && [ -e /opt/rh/devtoolset-2 ]; then
# Run in a newer compiler environment
# Environment needs to be set here for ccache to find the compiler to use...
scl enable devtoolset-2 -- "${RPMBUILD[@]}"
......