Skip to content

Instantly share code, notes, and snippets.

@vikage
Created May 15, 2017 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vikage/a876295c144dde69bb1969cfee7a7177 to your computer and use it in GitHub Desktop.
Save vikage/a876295c144dde69bb1969cfee7a7177 to your computer and use it in GitHub Desktop.
xbuild script to build project iOS. Put it to /usr/bin and call from current project command line. xbuild -h for more.
#!/bin/bash
BUILD_CONFIG="Release"
SCHEME=""
FILENAME="xxx"
while getopts m:s:f:h aflag; do
case $aflag in
m) BUILD_CONFIG=$OPTARG;;
s) SCHEME=$OPTARG;;
f) FILENAME=$OPTARG;;
h) echo "How to use
-m Mode: Release|Debug|\"OtherConfig\" -> Default is Release
-s Scheme -> Require
-f Filename -> Default is xxx"
exit;;
esac
done
if [ ${#SCHEME} -eq 0 ]; then
echo "Script need \"-s options\" for scheme( EX: xbuild -s Demo). Using xcodebuild -list for get list scheme"
exit
fi
CURRENT_PATH=$PWD
WORKSPACE=$(find $CURRENT_PATH -name "*.xcworkspace" -maxdepth 1)
XCPROJ=$(find $CURRENT_PATH -name "*.xcodeproj" -maxdepth 1)
echo "Start build project with
Config:$BUILD_CONFIG
Scheme:$SCHEME"
if [ ${#WORKSPACE} -eq 0 ]; then
echo "Target:$(basename $XCPROJ)"
rm -rf "$FILENAME.xcarchive"
xcodebuild -project $XCPROJ -sdk iphoneos -configuration "$BUILD_CONFIG" archive -archivePath "$FILENAME.xcarchive" -scheme $SCHEME
rm -f "$FILENAME.ipa"
if [ ! -e "${FILENAME}.xcarchive" ]; then
echo "Archive fail"
exit
fi
xcodebuild -exportArchive -archivePath "$FILENAME.xcarchive" -exportPath "$FILENAME.ipa"
rm -rf "$FILENAME.xcarchive"
$(open .)
else
echo "Target: $(basename $WORKSPACE)"
rm -rf "$FILENAME.xcarchive"
xcodebuild -workspace $WORKSPACE -scheme $SCHEME -sdk iphoneos -configuration "$BUILD_CONFIG" archive -archivePath "$FILENAME.xcarchive"
rm -f "$FILENAME.ipa"
if [ ! -e "${FILENAME}.xcarchive" ]; then
echo "Archive fail"
exit
fi
xcodebuild -exportArchive -archivePath "$FILENAME.xcarchive" -exportPath "$FILENAME.ipa"
rm -rf "$FILENAME.xcarchive"
$(open .)
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment