From f90877ca92aee143cd79ce6b91531410660ee693 Mon Sep 17 00:00:00 2001 From: Gabriel Wong Date: Mon, 6 Nov 2017 10:23:35 +0700 Subject: [PATCH] Update build script of samples --- ios/samples/KMSample1/build.sh | 117 +---------------------------- ios/samples/KMSample2/build.sh | 117 +---------------------------- ios/samples/build_common.sh | 130 +++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 230 deletions(-) create mode 100644 ios/samples/build_common.sh diff --git a/ios/samples/KMSample1/build.sh b/ios/samples/KMSample1/build.sh index 72ec3ed1cd..8e92903642 100755 --- a/ios/samples/KMSample1/build.sh +++ b/ios/samples/KMSample1/build.sh @@ -1,117 +1,4 @@ #!/bin/sh -# Please note that this build script (understandably) assumes that it is running on Mac OS X. -if [[ "${OSTYPE}" == *"darwin" ]]; then - echo "This build script will only run in a Mac environment." - exit 1 -fi - -display_usage ( ) { - echo "build.sh [-no-update] | [-lib-build] | [-lib-ignore] | [-clean]" - echo - echo " -clean Removes all previously-existing build products for this project before building." - echo " -no-update If an in-place copy of libKeyman exists, does not seek out an updated copy." - echo " -lib-build Actively rebuilds KMEI before copying its build products to project resources." - echo " -lib-nobuild Prevents the build script from building libKeyman under any circumstances." - echo " -no-codesign Performs the build without code signing." - echo - echo " If no settings are specified this script will grab a copy of the most recent build of libKeyman," - echo " performing an initial build of it if necessary." - exit 1 -} - -assert ( ) { - if ! [ -f $1 ]; then - echo "Build failed: missing $1" - exit 1 - fi -} - -verify_KMEI ( ) { - KMEI_BUILD_EXISTS=true - [ -d "$LIB_KEYMAN_SRC" ] || KMEI_BUILD_EXISTS=false -} - -LIB_KEYMAN_SRC=../../engine/KMEI/build/Debug-universal/KeymanEngine.framework -LIB_KEYMAN_DEST_DIR=./ - -KMEI_BUILD_DIR="../../" -KMEI_BUILD="./build.sh -libKeyman" - -BUILD_FOLDER=build - -do_clean ( ) { - rm -rf $BUILD_FOLDER -} - -### START OF THE BUILD ### - -DO_UPDATE=true -FORCE_KMEI_BUILD=false -ALLOW_KMEI_BUILD=true -CODE_SIGN=true - -while [[ $# -gt 0 ]] ; do - key="$1" - case $key in - -no-update) - DO_UPDATE=false - ALLOW_KMEI_BUILD=false - ;; - -lib-build) - FORCE_KMEI_BUILD=true - ;; - -lib-nobuild) - ALLOW_KMEI_BUILD=false - ;; - -no-codesign) - CODE_SIGN=false - ;; - -h|-?) - display_usage - ;; - -clean) - do_clean - ;; - esac - shift -done - -if [ $DO_UPDATE = true ]; then - # Does a prior build of KMEI exist? - verify_KMEI - - if [ $ALLOW_KMEI_BUILD = true ] && [ $FORCE_KMEI_BUILD = false ] && [ $KMEI_BUILD_EXISTS = false ]; then - echo "Previous libKeyman build information is unavailable." - FORCE_KMEI_BUILD=true - fi - - if [ $FORCE_KMEI_BUILD = true ]; then - echo "Building libKeyman..." - base_dir="$(pwd)" - - cd $KMEI_BUILD_DIR - $KMEI_BUILD - cd $base_dir - fi - - verify_KMEI - - if ! [ $KMEI_BUILD_EXISTS ]; then - echo "Build failed: could not build required libKeyman resources." - exit 1 - fi - - # Copy resources. - cp -Rf "$LIB_KEYMAN_SRC" "$LIB_KEYMAN_DEST_DIR" -fi - -if [ $CODE_SIGN = true ]; then - xcodebuild -quiet -target KMSample1 -else - xcodebuild -quiet CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -target KMSample1 -fi - -if [ $? = 0 ]; then - echo "Build complete." -fi +TARGET=KMSample1 +source ../build_common.sh diff --git a/ios/samples/KMSample2/build.sh b/ios/samples/KMSample2/build.sh index 13fcba5d90..0b0f57227a 100755 --- a/ios/samples/KMSample2/build.sh +++ b/ios/samples/KMSample2/build.sh @@ -1,117 +1,4 @@ #!/bin/sh -# Please note that this build script (understandably) assumes that it is running on Mac OS X. -if [[ "${OSTYPE}" == *"darwin" ]]; then - echo "This build script will only run in a Mac environment." - exit 1 -fi - -display_usage ( ) { - echo "build.sh [-no-update] | [-lib-build] | [-lib-ignore] | [-clean]" - echo - echo " -clean Removes all previously-existing build products for this project before building." - echo " -no-update If an in-place copy of libKeyman exists, does not seek out an updated copy." - echo " -lib-build Actively rebuilds KMEI before copying its build products to project resources." - echo " -lib-nobuild Prevents the build script from building libKeyman under any circumstances." - echo " -no-codesign Performs the build without code signing." - echo - echo " If no settings are specified this script will grab a copy of the most recent build of libKeyman," - echo " performing an initial build of it if necessary." - exit 1 -} - -assert ( ) { - if ! [ -f $1 ]; then - echo "Build failed: missing $1" - exit 1 - fi -} - -verify_KMEI ( ) { - KMEI_BUILD_EXISTS=true - [ -d "$LIB_KEYMAN_SRC" ] || KMEI_BUILD_EXISTS=false -} - -LIB_KEYMAN_SRC=../../engine/KMEI/build/Debug-universal/KeymanEngine.framework -LIB_KEYMAN_DEST_DIR=./ - -KMEI_BUILD_DIR="../../" -KMEI_BUILD="./build.sh -libKeyman" - -BUILD_FOLDER=build - -do_clean ( ) { - rm -rf $BUILD_FOLDER -} - -### START OF THE BUILD ### - -DO_UPDATE=true -FORCE_KMEI_BUILD=false -ALLOW_KMEI_BUILD=true -CODE_SIGN=true - -while [[ $# -gt 0 ]] ; do - key="$1" - case $key in - -no-update) - DO_UPDATE=false - ALLOW_KMEI_BUILD=false - ;; - -lib-build) - FORCE_KMEI_BUILD=true - ;; - -lib-nobuild) - ALLOW_KMEI_BUILD=false - ;; - -no-codesign) - CODE_SIGN=false - ;; - -h|-?) - display_usage - ;; - -clean) - do_clean - ;; - esac - shift -done - -if [ $DO_UPDATE = true ]; then - # Does a prior build of KMEI exist? - verify_KMEI - - if [ $ALLOW_KMEI_BUILD = true ] && [ $FORCE_KMEI_BUILD = false ] && [ $KMEI_BUILD_EXISTS = false ]; then - echo "Previous libKeyman build information is unavailable." - FORCE_KMEI_BUILD=true - fi - - if [ $FORCE_KMEI_BUILD = true ]; then - echo "Building libKeyman..." - base_dir="$(pwd)" - - cd $KMEI_BUILD_DIR - $KMEI_BUILD - cd $base_dir - fi - - verify_KMEI - - if ! [ $KMEI_BUILD_EXISTS ]; then - echo "Build failed: could not build required libKeyman resources." - exit 1 - fi - - # Copy resources. - cp -Rf "$LIB_KEYMAN_SRC" "$LIB_KEYMAN_DEST" -fi - -if [ $CODE_SIGN = true ]; then - xcodebuild -quiet -target KMSample2 -else - xcodebuild -quiet CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -target KMSample2 -fi - -if [ $? = 0 ]; then - echo "Build complete." -fi +TARGET=KMSample2 +source ../build_common.sh diff --git a/ios/samples/build_common.sh b/ios/samples/build_common.sh new file mode 100644 index 0000000000..d757c2df3f --- /dev/null +++ b/ios/samples/build_common.sh @@ -0,0 +1,130 @@ +#!/bin/sh + +# Please note that this build script (understandably) assumes that it is running on Mac OS X. +if [[ "${OSTYPE}" == *"darwin" ]]; then + echo "This build script will only run in a Mac environment." + exit 1 +fi + +if [ -z "$TARGET" ]; then + exit 1 +fi + +display_usage ( ) { + echo "build.sh [-no-update] | [-lib-build] | [-lib-ignore] | [-clean]" + echo + echo " -clean Removes all previously-existing build products for this project before building." + echo " -no-update If an in-place copy of libKeyman exists, does not seek out an updated copy." + echo " -lib-build Actively rebuilds KMEI before copying its build products to project resources." + echo " -lib-nobuild Prevents the build script from building libKeyman under any circumstances." + echo " -no-codesign Performs the build without code signing." + echo " -debug Sets the configuration to debug mode instead of release." + echo + echo " If no settings are specified this script will grab a copy of the most recent build of libKeyman," + echo " performing an initial build of it if necessary." + exit 1 +} + +assert ( ) { + if ! [ -f $1 ]; then + echo "Build failed: missing $1" + exit 1 + fi +} + +verify_KMEI ( ) { + KMEI_BUILD_EXISTS=true + [ -d "$KEYMAN_ENGINE_FRAMEWORK_SRC" ] || KMEI_BUILD_EXISTS=false +} + +KMEI_BUILD_DIR="../../" + +BUILD_FOLDER=build + +do_clean ( ) { + rm -rf $BUILD_FOLDER +} + +### START OF THE BUILD ### + +DO_UPDATE=true +FORCE_KMEI_BUILD=false +ALLOW_KMEI_BUILD=true +CODE_SIGN=true +CONFIG=Release +KMEI_FLAGS= + +while [[ $# -gt 0 ]] ; do + key="$1" + case $key in + -no-update) + DO_UPDATE=false + ALLOW_KMEI_BUILD=false + ;; + -lib-build) + FORCE_KMEI_BUILD=true + ;; + -lib-nobuild) + ALLOW_KMEI_BUILD=false + ;; + -no-codesign) + CODE_SIGN=false + KMEI_FLAGS="$KMEI_FLAGS -no-codesign" + ;; + -h|-?) + display_usage + ;; + -clean) + do_clean + KMEI_FLAGS="$KMEI_FLAGS -clean" + FORCE_KMEI_BUILD=true + ;; + -debug) + CONFIG=Debug + KMEI_FLAGS="$KMEI_FLAGS -debug" + ;; + esac + shift +done + +KEYMAN_ENGINE_FRAMEWORK_SRC="../../engine/KMEI/build/$CONFIG-universal/KeymanEngine.framework" +KEYMAN_ENGINE_FRAMEWORK_DST=./ + +if [ $DO_UPDATE = true ]; then + # Does a prior build of KMEI exist? + verify_KMEI + + if [ $ALLOW_KMEI_BUILD = true ] && [ $FORCE_KMEI_BUILD = false ] && [ $KMEI_BUILD_EXISTS = false ]; then + echo "Previous libKeyman build information is unavailable." + FORCE_KMEI_BUILD=true + fi + + if [ $FORCE_KMEI_BUILD = true ]; then + echo "Building libKeyman..." + base_dir="$(pwd)" + + cd $KMEI_BUILD_DIR + ./build.sh -libKeyman $KMEI_FLAGS + cd $base_dir + fi + + verify_KMEI + + if ! [ $KMEI_BUILD_EXISTS ]; then + echo "Build failed: could not build required libKeyman resources." + exit 1 + fi + + # Copy resources. + cp -Rf "$KEYMAN_ENGINE_FRAMEWORK_SRC" "$KEYMAN_ENGINE_FRAMEWORK_DST" +fi + +if [ $CODE_SIGN = true ]; then + xcodebuild -quiet -target "$TARGET" -config "$CONFIG" +else + xcodebuild -quiet CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -target "$TARGET" -config "$CONFIG" +fi + +if [ $? = 0 ]; then + echo "Build complete." +fi