From ec4a6cbce7010c57ba79784c3df46c567138fbfd Mon Sep 17 00:00:00 2001 From: Matt Diephouse Date: Sat, 8 Nov 2014 08:41:22 -0500 Subject: [PATCH] Copy scripts from objective-git --- script/LICENSE.md | 18 ++++ script/README.md | 82 +++++++++++++++++++ script/bootstrap | 123 ++++++++++++++++++++++++++++ script/cibuild | 150 ++++++++++++++++++++++++++++++++++ script/ios_build_functions.sh | 95 +++++++++++++++++++++ script/schemes.awk | 10 +++ script/targets.awk | 12 +++ script/update_libgit2 | 34 ++++++++ script/update_libgit2_ios | 78 ++++++++++++++++++ script/update_libssh2_ios | 55 +++++++++++++ script/update_libssl_ios | 75 +++++++++++++++++ script/xcode_functions.sh | 30 +++++++ script/xcodebuild.awk | 35 ++++++++ script/xctool.awk | 25 ++++++ 14 files changed, 822 insertions(+) create mode 100644 script/LICENSE.md create mode 100644 script/README.md create mode 100755 script/bootstrap create mode 100755 script/cibuild create mode 100755 script/ios_build_functions.sh create mode 100644 script/schemes.awk create mode 100644 script/targets.awk create mode 100755 script/update_libgit2 create mode 100755 script/update_libgit2_ios create mode 100755 script/update_libssh2_ios create mode 100755 script/update_libssl_ios create mode 100755 script/xcode_functions.sh create mode 100644 script/xcodebuild.awk create mode 100644 script/xctool.awk diff --git a/script/LICENSE.md b/script/LICENSE.md new file mode 100644 index 0000000..8d92384 --- /dev/null +++ b/script/LICENSE.md @@ -0,0 +1,18 @@ +**Copyright (c) 2013 Justin Spahr-Summers** + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/script/README.md b/script/README.md new file mode 100644 index 0000000..f66206f --- /dev/null +++ b/script/README.md @@ -0,0 +1,82 @@ +# objc-build-scripts + +This project is a collection of scripts created with two goals: + + 1. To standardize how Objective-C projects are bootstrapped after cloning + 1. To easily build Objective-C projects on continuous integration servers + +## Scripts + +Right now, there are two important scripts: [`bootstrap`](#bootstrap) and +[`cibuild`](#cibuild). Both are Bash scripts, to maximize compatibility and +eliminate pesky system configuration issues (like setting up a working Ruby +environment). + +The structure of the scripts on disk is meant to follow that of a typical Ruby +project: + +``` +script/ + bootstrap + cibuild +``` + +### bootstrap + +This script is responsible for bootstrapping (initializing) your project after +it's been checked out. Here, you should install or clone any dependencies that +are required for a working build and development environment. + +By default, the script will verify that [xctool][] is installed, then initialize +and update submodules recursively. If any submodules contain `script/bootstrap`, +that will be run as well. + +To check that other tools are installed, you can set the `REQUIRED_TOOLS` +environment variable before running `script/bootstrap`, or edit it within the +script directly. Note that no installation is performed automatically, though +this can always be added within your specific project. + +### cibuild + +This script is responsible for building the project, as you would want it built +for continuous integration. This is preferable to putting the logic on the CI +server itself, since it ensures that any changes are versioned along with the +source. + +By default, the script will run [`bootstrap`](#bootstrap), look for any Xcode +workspace or project in the working directory, then build all targets/schemes +(as found by `xcodebuild -list`) using [xctool][]. + +You can also specify the schemes to build by passing them into the script: + +```sh +script/cibuild ReactiveCocoa-Mac ReactiveCocoa-iOS +``` + +As with the `bootstrap` script, there are several environment variables that can +be used to customize behavior. They can be set on the command line before +invoking the script, or the defaults changed within the script directly. + +## Getting Started + +To add the scripts to your project, read the contents of this repository into +a `script` folder: + +``` +$ git remote add objc-build-scripts https://github.com/jspahrsummers/objc-build-scripts.git +$ git fetch objc-build-scripts +$ git read-tree --prefix=script/ -u objc-build-scripts/master +``` + +Then commit the changes, to incorporate the scripts into your own repository's +history. You can also freely tweak the scripts for your specific project's +needs. + +To merge in upstream changes later: + +``` +$ git fetch -p objc-build-scripts +$ git merge --ff --squash -Xsubtree=script objc-build-scripts/master +``` + +[xctool]: https://github.com/facebook/xctool diff --git a/script/bootstrap b/script/bootstrap new file mode 100755 index 0000000..fa19a60 --- /dev/null +++ b/script/bootstrap @@ -0,0 +1,123 @@ +#!/bin/bash + +export SCRIPT_DIR=$(dirname "$0") + +## +## Configuration Variables +## + +config () +{ + # A whitespace-separated list of executables that must be present and locatable. + : ${REQUIRED_TOOLS="xctool cmake"} + + export REQUIRED_TOOLS +} + +## +## Bootstrap Process +## + +main () +{ + config + + if [ -n "$REQUIRED_TOOLS" ] + then + echo "*** Checking dependencies..." + check_deps + fi + + local submodules=$(git submodule status) + local result=$? + + if [ "$result" -ne "0" ] + then + exit $result + fi + + if [ -n "$submodules" ] + then + echo "*** Updating submodules..." + update_submodules + fi +} + +check_deps () +{ + for tool in $REQUIRED_TOOLS + do + which -s "$tool" + if [ "$?" -ne "0" ] + then + echo "*** Error: $tool not found. Please install it and bootstrap again." + exit 1 + fi + done + + # Ensure that we have libgit2's dependencies installed. + installed=`brew list` + libs="libssh2 libtool autoconf automake" + + for lib in $libs + do + # Skip packages that are already installed. + echo "$installed" | grep -q "$lib" && code=$? || code=$? + + if [ "$code" -eq "0" ] + then + continue + elif [ "$code" -ne "1" ] + then + exit $code + fi + + echo "*** Installing $lib with Homebrew..." + brew install "$lib" + done + + brew_prefix=`brew --prefix` + expected_prefix=/usr/local + + if [ "$brew_prefix" != "$expected_prefix" ] + then + echo "*** Adding soft links into $expected_prefix..." + + products=(lib/libssh2.a include/libssh2.h include/libssh2_sftp.h include/libssh2_publickey.h) + + for product in "${products[@]}" + do + destination="$expected_prefix/$product" + if [ -e "$destination" ] + then + continue + fi + + sudo mkdir -p "$(dirname "$destination")" + sudo ln -s "$brew_prefix/$product" "$destination" + done + fi +} + +bootstrap_submodule () +{ + local bootstrap="script/bootstrap" + + if [ -e "$bootstrap" ] + then + echo "*** Bootstrapping $name..." + "$bootstrap" >/dev/null + else + update_submodules + fi +} + +update_submodules () +{ + git submodule sync --quiet && git submodule update --init && git submodule foreach --quiet bootstrap_submodule +} + +export -f bootstrap_submodule +export -f update_submodules + +main diff --git a/script/cibuild b/script/cibuild new file mode 100755 index 0000000..bbc1112 --- /dev/null +++ b/script/cibuild @@ -0,0 +1,150 @@ +#!/bin/bash + +export SCRIPT_DIR=$(dirname "$0") + +## +## Configuration Variables +## + +SCHEMES="$@" + +config () +{ + # The workspace to build. + # + # If not set and no workspace is found, the -workspace flag will not be passed + # to `xctool`. + # + # Only one of `XCWORKSPACE` and `XCODEPROJ` needs to be set. The former will + # take precedence. + : ${XCWORKSPACE=$(find_pattern "*.xcworkspace")} + + # The project to build. + # + # If not set and no project is found, the -project flag will not be passed + # to `xctool`. + # + # Only one of `XCWORKSPACE` and `XCODEPROJ` needs to be set. The former will + # take precedence. + : ${XCODEPROJ=$(find_pattern "*.xcodeproj")} + + # A bootstrap script to run before building. + # + # If this file does not exist, it is not considered an error. + : ${BOOTSTRAP="$SCRIPT_DIR/bootstrap"} + + # Extra options to pass to xctool. + : ${XCTOOL_OPTIONS="RUN_CLANG_STATIC_ANALYZER=NO"} + + # A whitespace-separated list of default schemes to build. + # + # Individual names can be quoted to avoid word splitting. + : ${SCHEMES:=$(xcodebuild -list -project "$XCODEPROJ" 2>/dev/null | awk -f "$SCRIPT_DIR/schemes.awk")} + + export XCWORKSPACE + export XCODEPROJ + export BOOTSTRAP + export XCTOOL_OPTIONS + export SCHEMES +} + +## +## Build Process +## + +main () +{ + config + + if [ -f "$BOOTSTRAP" ] + then + echo "*** Bootstrapping..." + "$BOOTSTRAP" || exit $? + fi + + echo "*** The following schemes will be built:" + echo "$SCHEMES" | xargs -n 1 echo " " + echo + + echo "$SCHEMES" | xargs -n 1 | ( + local status=0 + + while read scheme + do + build_scheme "$scheme" || status=1 + done + + exit $status + ) +} + +find_pattern () +{ + ls -d $1 2>/dev/null | head -n 1 +} + +run_xctool () +{ + if [ -n "$XCWORKSPACE" ] + then + xctool -workspace "$XCWORKSPACE" $XCTOOL_OPTIONS "$@" 2>&1 + elif [ -n "$XCODEPROJ" ] + then + xctool -project "$XCODEPROJ" $XCTOOL_OPTIONS "$@" 2>&1 + else + echo "*** No workspace or project file found." + exit 1 + fi +} + +parse_build () +{ + awk -f "$SCRIPT_DIR/xctool.awk" 2>&1 >/dev/null +} + +build_scheme () +{ + local scheme=$1 + + echo "*** Building and testing $scheme..." + echo + + local sdkflag= + local action=test + + # Determine whether we can run unit tests for this target. + run_xctool -scheme "$scheme" run-tests | parse_build + + local awkstatus=$? + + if [ "$awkstatus" -eq "1" ] + then + # SDK not found, try for iphonesimulator. + sdkflag="-sdk iphonesimulator" + + # Determine whether the unit tests will run with iphonesimulator + run_xctool $sdkflag -scheme "$scheme" run-tests | parse_build + + awkstatus=$? + + if [ "$awkstatus" -ne "0" ] + then + # Unit tests will not run on iphonesimulator. + sdkflag="" + fi + fi + + if [ "$awkstatus" -ne "0" ] + then + # Unit tests aren't supported. + action=build + fi + + run_xctool $sdkflag -scheme "$scheme" $action +} + +export -f build_scheme +export -f run_xctool +export -f parse_build + +main diff --git a/script/ios_build_functions.sh b/script/ios_build_functions.sh new file mode 100755 index 0000000..36f5b14 --- /dev/null +++ b/script/ios_build_functions.sh @@ -0,0 +1,95 @@ +#!/bin/bash + +SCRIPT_DIR=$(dirname "$0") +source "${SCRIPT_DIR}/xcode_functions.sh" + +function setup_build_environment () +{ + # augment path to help it find cmake installed in /usr/local/bin, + # e.g. via brew. Xcode's Run Script phase doesn't seem to honor + # ~/.MacOSX/environment.plist + PATH="/usr/local/bin:/opt/boxen/homebrew/bin:$PATH" + + pushd "$SCRIPT_DIR/.." > /dev/null + ROOT_PATH="$PWD" + popd > /dev/null + + CLANG="/usr/bin/xcrun clang" + CC="${CLANG}" + CPP="${CLANG} -E" + + # We need to clear this so that cmake doesn't have a conniption + MACOSX_DEPLOYMENT_TARGET="" + + XCODE_MAJOR_VERSION=$(xcode_major_version) + + CAN_BUILD_64BIT="0" + + # If IPHONEOS_DEPLOYMENT_TARGET has not been specified + # setup reasonable defaults to allow running of a build script + # directly (ie not from an Xcode proj) + if [ -z "${IPHONEOS_DEPLOYMENT_TARGET}" ] + then + IPHONEOS_DEPLOYMENT_TARGET="6.0" + fi + + # Determine if we can be building 64-bit binaries + if [ "${XCODE_MAJOR_VERSION}" -ge "5" ] && [ $(echo ${IPHONEOS_DEPLOYMENT_TARGET} '>=' 6.0 | bc -l) == "1" ] + then + CAN_BUILD_64BIT="1" + fi + + ARCHS="i386 armv7 armv7s" + if [ "${CAN_BUILD_64BIT}" -eq "1" ] + then + # For some stupid reason cmake needs simulator + # builds to be first + ARCHS="x86_64 ${ARCHS} arm64" + fi +} + +function build_all_archs () +{ + setup_build_environment + + local setup=$1 + local build_arch=$2 + local finish_build=$3 + + # run the prepare function + eval $setup + + echo "Building for ${ARCHS}" + + for ARCH in ${ARCHS} + do + if [ "${ARCH}" == "i386" ] || [ "${ARCH}" == "x86_64" ] + then + PLATFORM="iphonesimulator" + else + PLATFORM="iphoneos" + fi + + SDKVERSION=$(ios_sdk_version) + + if [ "${ARCH}" == "arm64" ] + then + HOST="aarch64-apple-darwin" + else + HOST="${ARCH}-apple-darwin" + fi + + SDKNAME="${PLATFORM}${SDKVERSION}" + SDKROOT="$(ios_sdk_path ${SDKNAME})" + + echo "Building ${LIBRARY_NAME} for ${SDKNAME} ${ARCH}" + echo "Please stand by..." + + # run the per arch build command + eval $build_arch + done + + # finish the build (usually lipo) + eval $finish_build +} + diff --git a/script/schemes.awk b/script/schemes.awk new file mode 100644 index 0000000..4c94df9 --- /dev/null +++ b/script/schemes.awk @@ -0,0 +1,10 @@ +BEGIN { + FS = "\n"; +} + +/Schemes:/ { + while (getline && $0 != "") { + sub(/^ +/, ""); + print "'" $0 "'"; + } +} diff --git a/script/targets.awk b/script/targets.awk new file mode 100644 index 0000000..117660d --- /dev/null +++ b/script/targets.awk @@ -0,0 +1,12 @@ +BEGIN { + FS = "\n"; +} + +/Targets:/ { + while (getline && $0 != "") { + if ($0 ~ /Tests/) continue; + + sub(/^ +/, ""); + print "'" $0 "'"; + } +} diff --git a/script/update_libgit2 b/script/update_libgit2 new file mode 100755 index 0000000..1b87423 --- /dev/null +++ b/script/update_libgit2 @@ -0,0 +1,34 @@ +#!/bin/sh + +set -e + +# augment path to help it find cmake installed in /usr/local/bin, +# e.g. via brew. Xcode's Run Script phase doesn't seem to honor +# ~/.MacOSX/environment.plist +PATH="/usr/local/bin:$PATH" + +if [ "External/libgit2.a" -nt "External/libgit2" ] +then + echo "No update needed." + exit 0 +fi + +cd "External/libgit2" + +if [ -d "build" ]; then + rm -rf "build" +fi + +mkdir build +cd build + +cmake -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_CLAR:BOOL=OFF -DTHREADSAFE:BOOL=ON .. +cmake --build . + +product="libgit2.a" +install_path="../../${product}" +if [ "${product}" -nt "${install_path}" ]; then + cp -v "${product}" "${install_path}" +fi + +echo "libgit2 has been updated." diff --git a/script/update_libgit2_ios b/script/update_libgit2_ios new file mode 100755 index 0000000..dfebd3b --- /dev/null +++ b/script/update_libgit2_ios @@ -0,0 +1,78 @@ +#!/bin/bash + +set -e + +# source the common build functions +SCRIPT_DIR=$(dirname "$0") +source "${SCRIPT_DIR}/ios_build_functions.sh" + +function setup () +{ + if [ "${ROOT_PATH}/External/libgit2-ios/libgit2-ios.a" -nt "${ROOT_PATH}/External/libgit2" ] + then + echo "No update needed." + exit 0 + fi + + LIBRARY_NAME="libgit2" + LIB_PATH="${ROOT_PATH}/External/libgit2-ios" + rm -rf "${LIB_PATH}" + + pushd "${ROOT_PATH}/External/libgit2" > /dev/null +} + +function build_libgit2 () +{ + rm -rf "build" + mkdir "build" + + pushd "build" > /dev/null + + # LOL Cmake + if [ "${ARCH}" != "i386" ] && [ "${ARCH}" != "x86_64" ] + then + SYS_ROOT="-DCMAKE_OSX_SYSROOT=${SDKROOT}" + fi + + # install the each built arch somewhere sane + INSTALL_PREFIX="${LIB_PATH}/${SDKNAME}-${ARCH}.sdk" + + mkdir -p "${INSTALL_PREFIX}" + + LOG="${INSTALL_PREFIX}/build-libgit2.log" + echo "$LOG" + + cmake -DCMAKE_C_COMPILER=clang \ + -DCMAKE_C_COMPILER_WORKS:BOOL=ON \ + -DBUILD_SHARED_LIBS:BOOL=OFF \ + -DOPENSSL_INCLUDE_DIR:PATH=../../External/ios-openssl/include/ \ + -DCMAKE_LIBRARY_PATH:PATH=../../External/libssh2-ios/lib/ \ + -DCMAKE_INCLUDE_PATH:PATH=../../External/libssh2-ios/include/libssh2/ \ + -DOPENSSL_SSL_LIBRARY:FILEPATH=../../External/ios-openssl/lib/libssl.a \ + -DCMAKE_LIBRARY_PATH:PATH="${SDKROOT}/usr/lib/" \ + -DOPENSSL_CRYPTO_LIBRARY:FILEPATH=../../External/ios-openssl/lib/libcrypto.a \ + -DCMAKE_INSTALL_PREFIX:PATH="${INSTALL_PREFIX}/" \ + -DBUILD_CLAR:BOOL=OFF \ + -DTHREADSAFE:BOOL=ON \ + "${SYS_ROOT}" \ + -DCMAKE_OSX_ARCHITECTURES:STRING="${ARCH}" \ + .. >> "${LOG}" 2>&1 + cmake --build . --target install >> "${LOG}" 2>&1 + + # push the built library into the list + BUILT_LIB_PATHS+=("${INSTALL_PREFIX}/lib/libgit2.a") + popd > /dev/null +} + +function fat_binary () +{ + echo "Building fat binary..." + + lipo -create "${BUILT_LIB_PATHS[@]}" -output "${ROOT_PATH}/External/libgit2-ios/libgit2-ios.a" + + echo "Building done." + + popd > /dev/null +} + +build_all_archs setup build_libgit2 fat_binary diff --git a/script/update_libssh2_ios b/script/update_libssh2_ios new file mode 100755 index 0000000..18d8a9f --- /dev/null +++ b/script/update_libssh2_ios @@ -0,0 +1,55 @@ +#!/bin/bash + +set -e + +# source the common build functions +SCRIPT_DIR=$(dirname "$0") +source "${SCRIPT_DIR}/ios_build_functions.sh" + +function setup () +{ + if [ -f "${ROOT_PATH}/External/libssh2-ios/lib/libssh2-ios.a" ] + then + echo "No update needed." + exit 0 + fi + LIBRARY_NAME="libssh2" +} + +function build_ssh2 () +{ + mkdir -p "${ROOT_PATH}/External/libssh2-ios/lib" "${ROOT_PATH}/External/libssh2-ios/lib" "${ROOT_PATH}/External/libssh2-ios/src" + + rm -rf "${ROOT_PATH}/External/libssh2-ios/src/libssh2" + cp -R "${ROOT_PATH}/External/libssh2" "${ROOT_PATH}/External/libssh2-ios/src/" + pushd "${ROOT_PATH}/External/libssh2-ios/src/libssh2" > /dev/null + + export CFLAGS="-arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${SDKROOT} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET}" + export CPPFLAGS="-arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${SDKROOT} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET}" + + mkdir -p "${ROOT_PATH}/External/libssh2-ios/bin/${SDKNAME}-${ARCH}.sdk" + LOG="${ROOT_PATH}/External/libssh2-ios/bin/${SDKNAME}-${ARCH}.sdk/build-libssh2.log" + + echo "${LOG}" + + ./buildconf >> "${LOG}" 2>&1 + ./configure --host=${HOST} --prefix="${ROOT_PATH}/External/libssh2-ios/bin/${SDKNAME}-${ARCH}.sdk" --with-openssl --with-libssl-prefix="${ROOT_PATH}/External/ios-openssl" --disable-shared --enable-static >> "${LOG}" 2>&1 + make >> "${LOG}" 2>&1 + make install >> "${LOG}" 2>&1 + popd > /dev/null + + BUILT_LIBS+=("${ROOT_PATH}/External/libssh2-ios/bin/${SDKNAME}-${ARCH}.sdk/lib/libssh2.a") +} + +function fat_binary () +{ + echo "Building fat binary..." + + lipo -create "${BUILT_LIBS[@]}" -output "${ROOT_PATH}/External/libssh2-ios/lib/libssh2-ios.a" + mkdir -p "${ROOT_PATH}/External/libssh2-ios/include/libssh2" + cp -R "${ROOT_PATH}/External/libssh2-ios/bin/iphonesimulator${SDKVERSION}-i386.sdk/include/libssh2.h" "${ROOT_PATH}/External/libssh2-ios/include/libssh2/" + + echo "Building done." +} + +build_all_archs setup build_ssh2 fat_binary diff --git a/script/update_libssl_ios b/script/update_libssl_ios new file mode 100755 index 0000000..3d3a209 --- /dev/null +++ b/script/update_libssl_ios @@ -0,0 +1,75 @@ +#!/bin/bash + +# source the common build functions +SCRIPT_DIR=$(dirname "$0") +source "${SCRIPT_DIR}/ios_build_functions.sh" + +function setup () +{ + if [ -f "${ROOT_PATH}/External/ios-openssl/lib/libssl.a" ] && [ -f "${ROOT_PATH}/External/ios-openssl/lib/libcrypto.a" ] && [ -d "${ROOT_PATH}/External/ios-openssl/include" ] + then + echo "No update needed." + exit 0 + fi + + LIBRARY_NAME="OpenSSL" + + rm -rf "${ROOT_PATH}/External/ios-openssl/include" "External/ios-openssl/lib" +} + +function cleanup () +{ + rm -rf "/tmp/openssl" + rm -rf "/tmp/openssl-*.log" +} + +function build_ssl () +{ + rm -rf "/tmp/openssl" + cp -r "${ROOT_PATH}/External/openssl" "/tmp/" + pushd "/tmp/openssl" > /dev/null + + LOG="/tmp/openssl-${ARCH}.log" + + if [ "${ARCH}" == "arm64" ] || [ "${ARCH}" == "x86_64" ] + then + HOST="BSD-generic64" + CONFIG="no-gost no-asm enable-ec_nistp_64_gcc_128" + else + HOST="BSD-generic32" + CONFIG="no-gost no-asm" + perl -i -pe 's|static volatile sig_atomic_t intr_signal|static volatile int intr_signal|' crypto/ui/ui_openssl.c + fi + echo "$LOG" + + ./Configure ${HOST} ${CONFIG} --openssldir="/tmp/openssl-${ARCH}" >> "${LOG}" 2>&1 + perl -i -pe "s|^CC= gcc|CC= ${CLANG} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET} -arch ${ARCH} |g" Makefile >> "${LOG}" 2>&1 + perl -i -pe "s|^CFLAG= (.*)|CFLAG= -isysroot ${SDKROOT} \$1|g" Makefile >> "${LOG}" 2>&1 + make >> "${LOG}" 2>&1 + + make install_sw >> "${LOG}" 2>&1 + popd > /dev/null + rm -rf "/tmp/openssl" + + BUILT_CRYPTO_PATHS+=("/tmp/openssl-${ARCH}/lib/libcrypto.a") + BUILT_SSL_PATHS+=("/tmp/openssl-${ARCH}/lib/libssl.a") +} + +function fat_binary () +{ + echo "Building fat binary..." + + mkdir -p "${ROOT_PATH}/External/ios-openssl/include" + cp -r /tmp/openssl-i386/include/openssl "${ROOT_PATH}/External/ios-openssl/include/" + + mkdir -p "${ROOT_PATH}/External/ios-openssl/lib" + + lipo -create "${BUILT_CRYPTO_PATHS[@]}" -output "${ROOT_PATH}/External/ios-openssl/lib/libcrypto.a" + lipo -create "${BUILT_SSL_PATHS[@]}" -output "${ROOT_PATH}/External/ios-openssl/lib/libssl.a" + + echo "Building done." +} + +cleanup +build_all_archs setup build_ssl fat_binary +cleanup diff --git a/script/xcode_functions.sh b/script/xcode_functions.sh new file mode 100755 index 0000000..e87697c --- /dev/null +++ b/script/xcode_functions.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Returns the version # of xcodebuild +# eg. (4.6.3, 5.0, 5.0.1) +function xcode_version () +{ + /usr/bin/xcodebuild -version 2> /dev/null | head -n 1 | awk '{ print $2 }' +} + +# Returns the major version of xcodebuild +# eg. (4, 5, 6) +function xcode_major_version () +{ + xcode_version | awk -F '.' '{ print $1 }' +} + +# Returns the latest iOS SDK version available +# via xcodebuild +function ios_sdk_version () +{ + # This relies on the fact that the latest iPhone SDK + # is the last thing listed before the Xcode version. + /usr/bin/xcodebuild -version -sdk 2> /dev/null | grep SDKVersion | tail -n 1 | awk '{ print $2 }' +} + +# Returns the path to the specified iOS SDK name +function ios_sdk_path () +{ + /usr/bin/xcodebuild -version -sdk 2> /dev/null | grep -i $1 | grep 'Path:' | awk '{ print $2 }' +} diff --git a/script/xcodebuild.awk b/script/xcodebuild.awk new file mode 100644 index 0000000..c746b09 --- /dev/null +++ b/script/xcodebuild.awk @@ -0,0 +1,35 @@ +# Exit statuses: +# +# 0 - No errors found. +# 1 - Build or test failure. Errors will be logged automatically. +# 2 - Untestable target. Retry with the "build" action. + +BEGIN { + status = 0; +} + +{ + print; + fflush(stdout); +} + +/is not valid for Testing/ { + exit 2; +} + +/[0-9]+: (error|warning):/ { + errors = errors $0 "\n"; +} + +/(TEST|BUILD) FAILED/ { + status = 1; +} + +END { + if (length(errors) > 0) { + print "\n*** All errors:\n" errors; + } + + fflush(stdout); + exit status; +} diff --git a/script/xctool.awk b/script/xctool.awk new file mode 100644 index 0000000..f613258 --- /dev/null +++ b/script/xctool.awk @@ -0,0 +1,25 @@ +# Exit statuses: +# +# 0 - No errors found. +# 1 - Wrong SDK. Retry with SDK `iphonesimulator`. +# 2 - Missing target. + +BEGIN { + status = 0; +} + +{ + print; +} + +/Testing with the '(.+)' SDK is not yet supported/ { + status = 1; +} + +/does not contain a target named/ { + status = 2; +} + +END { + exit status; +}