Skip to content

Instantly share code, notes, and snippets.

@KyleLeneau
Created April 10, 2018 15:41
Show Gist options
  • Save KyleLeneau/480c9d0c16d35a313e61f76a0defa3e8 to your computer and use it in GitHub Desktop.
Save KyleLeneau/480c9d0c16d35a313e61f76a0defa3e8 to your computer and use it in GitHub Desktop.
Checks for required targets in static libraries and frameworks, also checks for Bitcode support for anything in the directory it's run from recursively.
#!/bin/bash
PATH=$(pwd)
REQUIRED_ARCHS="arm64 x86_64"
REPORT_FILE="${PATH}/x86-bitcode-support-report.txt"
function clean_report() {
/bin/rm -f "$REPORT_FILE"
}
function check_dependencies() {
# Find static libraries or frameworks
/usr/bin/find "$PATH" -name 'lib*.a' -o -name '*.framework' -type d > "$PATH"/.dependencies
while read -r DEPENDENCY
do
ARCHIVE=""
ARCHIVE_TYPE=""
# Figure out what type of dependency this is
if [[ "$DEPENDENCY" =~ .*\.a$ ]]; then
# Static library
ARCHIVE=$DEPENDENCY
ARCHIVE_TYPE="static"
elif [[ "$DEPENDENCY" =~ .*\.framework$ ]]; then
info_plist="$DEPENDENCY/Info.plist"
if [ -e $info_plist ]; then
# Standard framework
name=$(/usr/bin/defaults read "$info_plist" CFBundleExecutable)
ARCHIVE="${DEPENDENCY}/$name"
ARCHIVE_TYPE="framework"
else
# Static framework (static lib packaged as framework)
name=$(echo "$DEPENDENCY" | /usr/bin/rev | /usr/bin/cut -d"/" -f1 | /usr/bin/cut -d"." -f2 | /usr/bin/rev)
ARCHIVE="${DEPENDENCY}/$name"
ARCHIVE_TYPE="static_framework"
fi
fi
# Perform the checks
echo "Checking Architectures: ${DEPENDENCY/$PATH/}" >> $REPORT_FILE
archs=$(/usr/bin/lipo -info $ARCHIVE | /usr/bin/sed 's/.*are: //g')
echo "Found Architectures: $archs" >> $REPORT_FILE
# Check for required architectures
for ARCH in $REQUIRED_ARCHS
do
# Check for required architectures
echo "$ARCH: $(/usr/bin/grep -q "${ARCH}" <<< $archs && echo "TRUE" || echo "FALSE")" >> $REPORT_FILE
# Check for Bitcode Support
echo "$ARCH Bitcode: $(/usr/bin/otool -arch $ARCH -l $ARCHIVE | /usr/bin/grep -q __bitcode && echo "TRUE" || echo "FALSE")" >> $REPORT_FILE
done
echo "" >> $REPORT_FILE
done < "$PATH"/.dependencies
/bin/rm -rf "$PATH"/.dependencies
}
function main() {
clean_report
check_dependencies
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment