Created
April 23, 2018 21:11
-
-
Save hfossli/387d762b215e3b677d3cb66fe6b08027 to your computer and use it in GitHub Desktop.
Script for building dynamic framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BASEDIR="$( cd "$(dirname "$0/")" ; pwd -P )" | |
BUILD_DIR="$BASEDIR/Builds" | |
PROJECT_FILE="Butterfly.xcodeproj" | |
PRODUCT_NAME="Butterfly" | |
TARGET_NAME="Butterfly-iOS" | |
CONFIGURATION="Release" | |
CLEAR='\033[0m' | |
RED='\033[0;31m' | |
ORANGE='\033[38;5;208m' | |
GREEN='\033[0;32m' | |
GREY='\033[38;5;237m' | |
function welcome() { | |
if [ -z "$QUIET" ]; then | |
printf """$GREEN\ | |
__ __ __ ______ | |
/ /_ __ __/ /_/ /____ _____/ __/ /_ __ | |
/ __ \/ / / / __/ __/ _ \/ ___/ /_/ / / / / | |
/ /_/ / /_/ / /_/ /_/ __/ / / __/ / /_/ / | |
/_.___/\__,_/\__/\__/\___/_/ /_/ /_/\__, / | |
/____/ | |
$CLEAR""" | |
fi | |
} | |
function echo_start() { echo -ne "\r${GREY}[~] $@...${CLEAR}"; } | |
function echo_success() { echo -e "\r${GREEN}[+] $@ (SUCCESS)${CLEAR}"; } | |
function echo_warning() { echo -e "\r${ORANGE}[+] $@ (FINISHED WITH WARNINGS)${CLEAR}"; } | |
function echo_failed() { echo -e "\r${RED}[!] $@ (FAILED)${CLEAR}"; } | |
function perform_step() { | |
STEP=$1 | |
shift; | |
TEMP_OUT_FILE="$BUILD_DIR/out" | |
TEMP_ERR_FILE="$BUILD_DIR/err" | |
rm "$TEMP_OUT_FILE" 2> /dev/null | |
rm "$TEMP_ERR_FILE" 2> /dev/null | |
echo_start $STEP | |
# execute command | |
$@ > "$TEMP_OUT_FILE" 2> "$TEMP_ERR_FILE" | |
if [ -s "$TEMP_ERR_FILE" ] # stderr? | |
then | |
echo_failed $STEP | |
cat $TEMP_OUT_FILE | |
cat $TEMP_ERR_FILE | |
echo_failed $STEP | |
exit 1 | |
fi | |
if [ -s "$TEMP_OUT_FILE" ] # stdout? | |
then | |
echo_warning $STEP | |
cat $TEMP_OUT_FILE | |
else | |
echo_success $STEP | |
fi | |
} | |
function build() { | |
SDK="$1" | |
perform_step "Build $TARGET_NAME for $SDK" \ | |
xcodebuild -project "$PROJECT_FILE" \ | |
-target "$TARGET_NAME" \ | |
-sdk $SDK \ | |
-IDEBuildOperationMaxNumberOfConcurrentCompileTasks=`sysctl -n hw.ncpu` \ | |
-configuration ${CONFIGURATION} \ | |
-destination 'generic/platform=iOS' \ | |
-quiet \ | |
BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" ONLY_ACTIVE_ARCH=NO MODULE_CACHE_DIR="$BUILD_DIR/DerivedData/ModuleCache" OBJROOT="$BUILD_DIR/Intermediates" \ | |
SHARED_PRECOMPS_DIR="$BUILD_DIR/Intermediates/PrecompiledHeaders" SYMROOT="$BUILD_DIR/Products" CONFIGURATION_TEMP_DIR="$BUILD_DIR/Products" BUILD_DIR="$BUILD_DIR" BUILD_ROOT="$BUILD_DIR" \ | |
clean build | |
} | |
function join_frameworks() { | |
rm -r "$PRODUCT_NAME.framework" 2> /dev/null | |
cp -R "$BUILD_DIR/$CONFIGURATION-iphoneos/$PRODUCT_NAME.framework" "$PRODUCT_NAME.framework" | |
perform_step "Joining architectures" \ | |
lipo -create -output "$PRODUCT_NAME.framework/$PRODUCT_NAME" \ | |
"${BUILD_DIR}/$CONFIGURATION-iphonesimulator/$PRODUCT_NAME.framework/$PRODUCT_NAME" \ | |
"${BUILD_DIR}/$CONFIGURATION-iphoneos/$PRODUCT_NAME.framework/$PRODUCT_NAME" | |
} | |
# Step 0. Print purpose of script | |
welcome | |
# Step 1. Create build dir | |
rm -r $BUILD_DIR 2> /dev/null | |
mkdir -p $BUILD_DIR | |
# Step 2. Build Device and Simulator versions | |
build iphoneos | |
build iphonesimulator | |
# Step 3. Copy the framework and join for architectures | |
join_frameworks | |
# Step 4. Clean up | |
rm -r $BUILD_DIR 2> /dev/null | |
# Step 5. Locate the final product in Finder | |
open -R "$PRODUCT_NAME.framework" |
Author
hfossli
commented
Apr 23, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment