mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This creates a nice stub for further sorts of lit based build system unit tests, such as for making sure that debug info is emitted in the correct places.
121 lines
3.2 KiB
Bash
Executable File
121 lines
3.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# This test makes sure that if lto is enabled and that all host libraries
|
|
# contain only bitcode.
|
|
#
|
|
# *NOTE* This will not trigger for embedded bitcode sections since to file those
|
|
# are still mach-o files and come up as such.
|
|
|
|
set -e
|
|
set -u
|
|
|
|
# REQUIRES: lto
|
|
# REQUIRES: OS=macosx
|
|
# RUN: %s %swift_obj_root %t
|
|
|
|
function check_thin_archive_for_bitcode() {
|
|
set -e
|
|
set -u
|
|
set -o pipefail
|
|
|
|
pushd . 1>/dev/null
|
|
|
|
local BASE_TEMPDIR=$1
|
|
local ARCHIVE=$2
|
|
|
|
local LIB_NAME=$(basename ${ARCHIVE})
|
|
local LIB_ARCH=$(basename $(dirname ${ARCHIVE}))
|
|
local LIB_PLATFORM=$(basename $(dirname $(dirname ${ARCHIVE})))
|
|
|
|
LIB_TEMP_DIR="${BASE_TEMPDIR}/${LIB_PLATFORM}-${LIB_ARCH}-${LIB_NAME}"
|
|
mkdir -p "${LIB_TEMP_DIR}"
|
|
cd "${LIB_TEMP_DIR}"
|
|
ar -x ${ARCHIVE}
|
|
if [[ -n "$(find ./ -iname '*.o' -exec file {} \; | grep -e bitcode -e bit-code)" ]]; then
|
|
echo "Found bitcode file in thin archive: ${ARCHIVE}"
|
|
else
|
|
echo "No bitcode in thin archive: ${ARCHIVE}"
|
|
exit 1
|
|
fi
|
|
popd 1>/dev/null
|
|
|
|
set +o pipefail
|
|
set +u
|
|
set +e
|
|
}
|
|
export -f check_thin_archive_for_bitcode
|
|
|
|
function check_thick_archive_for_bitcode() {
|
|
set -e
|
|
set -u
|
|
set -o pipefail
|
|
|
|
pushd . 1>/dev/null
|
|
|
|
local BASE_TEMPDIR=$1
|
|
local ARCHIVE=$2
|
|
|
|
local LIB_NAME=$(basename ${ARCHIVE})
|
|
local LIB_PLATFORM=$(basename $(dirname ${ARCHIVE}))
|
|
|
|
LIB_TEMP_DIR="${BASE_TEMPDIR}/${LIB_PLATFORM}-thick-${LIB_NAME}"
|
|
LIB_ARCHIVE_DIR="${LIB_TEMP_DIR}/archive"
|
|
LIB_OBJECT_DIR="${LIB_TEMP_DIR}/object"
|
|
|
|
mkdir -p "${LIB_TEMP_DIR}"
|
|
mkdir -p "${LIB_ARCHIVE_DIR}"
|
|
mkdir -p "${LIB_OBJECT_DIR}"
|
|
|
|
ARCHS=( $(lipo -info ${ARCHIVE} | cut -f 3 -d ":" ) )
|
|
cd ${LIB_OBJECT_DIR}
|
|
for arch in "${ARCHS[@]}"; do
|
|
pushd . 1>/dev/null
|
|
local THIN_ARCHIVE="${LIB_NAME}.${arch}"
|
|
lipo -thin "${arch}" -output "${LIB_ARCHIVE_DIR}/${THIN_ARCHIVE}" "${ARCHIVE}"
|
|
mkdir ${arch}
|
|
cd ${arch}
|
|
ar -x "${LIB_ARCHIVE_DIR}/${THIN_ARCHIVE}"
|
|
|
|
if [[ -n "$(find ./ -iname '*.o' -exec file {} \; | grep -e bitcode -e bit-code)" ]]; then
|
|
echo "Found bitcode file in thin archive: ${THIN_ARCHIVE}. Taken from thick archive: ${ARCHIVE}"
|
|
else
|
|
echo "No bitcode in thin archive: ${THIN_ARCHIVE}. Taken from thick archive: ${ARCHIVE}"
|
|
exit 1
|
|
fi
|
|
|
|
popd 1>/dev/null
|
|
done
|
|
popd 1>/dev/null
|
|
|
|
set +o pipefail
|
|
set +u
|
|
set +e
|
|
}
|
|
export -f check_thick_archive_for_bitcode
|
|
|
|
OBJROOT=$(cd ${1} && pwd)
|
|
TEMPDIR=${2}
|
|
|
|
rm -rf $TEMPDIR
|
|
mkdir -p $TEMPDIR
|
|
|
|
THIN_ARCHIVES=( \
|
|
$(find ${OBJROOT}/lib -depth 1 -iname '*.a' -exec lipo -info {} \; | grep "Non-fat file" | cut -f 3 -d " ") \
|
|
)
|
|
|
|
if [[ ${#THIN_ARCHIVES[@]} -gt 0 ]]; then
|
|
echo "${THIN_ARCHIVES[@]}" | xargs -n 1 -P 8 bash -c "check_thin_archive_for_bitcode \"${TEMPDIR}\" \${1}" --
|
|
fi
|
|
|
|
THICK_ARCHIVES=( \
|
|
$(find ${OBJROOT}/lib -depth 1 -iname '*.a' -exec lipo -info {} \; | grep "Architectures in the fat file" | cut -f 6 -d " ") \
|
|
)
|
|
|
|
if [[ ${#THICK_ARCHIVES[@]} -gt 0 ]]; then
|
|
echo "${THICK_ARCHIVES[@]}" | xargs -n 1 -P 8 bash -c "check_thick_archive_for_bitcode \"${TEMPDIR}\" \${1}" --
|
|
fi
|
|
|
|
set +o pipefail
|
|
set +u
|
|
set +e
|