From 30c6452d99dec18c80570f963de53f9d008e42b2 Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Fri, 9 Dec 2016 13:26:57 -0800 Subject: [PATCH] Update scripts from Objective-Git, including commits: commit fbc6bb0c42c3f35725fbe98db4e537e22c9a3aed Author: Ben Chatelain Date: Mon Apr 11 09:40:00 2016 -0600 Add clean_externals script commit f250c3dd8330732d27b49af93a7defae6df0629e Author: Ben Chatelain Date: Mon Apr 4 22:32:04 2016 -0600 Enable pipefail commit 7813f12c75381d87d5ab345c591d00f7184ab150 Author: Ben Chatelain Date: Mon Apr 4 22:19:42 2016 -0600 Configure cibuild to echo commands and fail on first error commit 6f802a4b82c634f115b7f941d697ccee3f557a8b Author: Ben Chatelain Date: Sun Apr 3 13:01:45 2016 -0600 Overhaul cibuild - Replaced xctool with xcodebuild + xcpretty - Removed unused cruft and awk scripts commit 5978a65d53def353ab34d63f02553d7ff7622d1f Merge: 41d4e28 de7f644 Author: Ben Chatelain Date: Sun Feb 28 21:06:56 2016 -0700 Merge pull request #554 from libgit2/piet/travis-matrix Add matrix build for iOS and Mac commit 1e3f6c5bdf38c1da26c7cc2b5bd4f6b3098bca2e Author: Piet Brauer Date: Wed Feb 24 17:40:52 2016 +0800 Add matrix build for iOS and Mac commit 9c13681d06decdb8de327633dc80d9b742a54423 Author: Piet Brauer Date: Wed Feb 24 16:23:11 2016 +0800 Enable Bitcode --- script/LICENSE.md | 18 ---- script/README.md | 82 --------------- script/cibuild | 204 ++++++++++++-------------------------- script/clean_externals | 22 ++++ script/schemes.awk | 10 -- script/targets.awk | 12 --- script/update_libgit2_ios | 1 + script/update_libssh2_ios | 4 +- script/update_libssl_ios | 2 +- script/xcodebuild.awk | 35 ------- script/xctool.awk | 25 ----- 11 files changed, 87 insertions(+), 328 deletions(-) delete mode 100644 script/LICENSE.md delete mode 100644 script/README.md create mode 100755 script/clean_externals delete mode 100644 script/schemes.awk delete mode 100644 script/targets.awk delete mode 100644 script/xcodebuild.awk delete mode 100644 script/xctool.awk diff --git a/script/LICENSE.md b/script/LICENSE.md deleted file mode 100644 index 8d92384..0000000 --- a/script/LICENSE.md +++ /dev/null @@ -1,18 +0,0 @@ -**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 deleted file mode 100644 index f66206f..0000000 --- a/script/README.md +++ /dev/null @@ -1,82 +0,0 @@ -# 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/cibuild b/script/cibuild index b72816e..4f2a1a3 100755 --- a/script/cibuild +++ b/script/cibuild @@ -1,159 +1,77 @@ -#!/bin/bash +#!/bin/bash -ex +# +# script/cibuild +# ObjectiveGit +# +# Executes the build and runs tests for Mac and iOS. Designed to be invoked by +# Travis as a matrix build so that the two platform builds can run in parallel. +# +# Dependent tools & scripts: +# - script/bootstrap +# - script/update_libssl_ios +# - [xcodebuild](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html) +# - xcpretty (gem) +# - xcpretty-travis-formatter (gem) +# +# Environment Variables: +# - SCHEME: specifies which Xcode scheme to build. Set to one of the following: +# - ObjectiveGit Mac +# - ObjectiveGit iOS +# - TRAVIS: indicates when the build is being run by travis, used to invoke +# the xcpretty-travis-formatter gem for output. + +if [ -z "$SCHEME" ]; then + echo "The SCHEME environment variable is empty. Please set this to one of:" + echo "- ObjectiveGit Mac" + echo "- ObjectiveGit iOS" + exit 1 +fi -export SCRIPT_DIR=$(dirname "$0") ## ## Configuration Variables ## -SCHEMES="$@" +set -o pipefail +SCRIPT_DIR=$(dirname "$0") +XCWORKSPACE="ObjectiveGitFramework.xcworkspace" +XCODE_OPTIONS=$(RUN_CLANG_STATIC_ANALYZER=NO ONLY_ACTIVE_ARCH=NO CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO) -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 -} +if [ -n "$TRAVIS" ]; then + # Use a special formatter when running on TravisCI + XCPRETTY_FORMAT_OPTIONS="-f `xcpretty-travis-formatter`" +else + XCPRETTY_FORMAT_OPTIONS="--color" +fi ## ## Build Process ## -main () -{ - config +echo "*** Bootstrapping..." +"$SCRIPT_DIR/bootstrap" - if [ -f "$BOOTSTRAP" ] - then - echo "*** Bootstrapping..." - "$BOOTSTRAP" || exit $? - fi +if [ "$SCHEME" == "ObjectiveGit Mac" ]; then + echo "*** Building and testing $SCHEME..." + echo - echo "*** Prebuilding OpenSSL" - $SCRIPT_DIR/update_libssl_ios + xcodebuild -workspace "$XCWORKSPACE" \ + -scheme "$SCHEME" \ + ${XCODE_OPTIONS[*]} \ + build test \ + 2>&1 | xcpretty $XCPRETTY_FORMAT_OPTIONS +elif [ "$SCHEME" == "ObjectiveGit iOS" ]; then + echo "*** Prebuilding OpenSSL" + "$SCRIPT_DIR/update_libssl_ios" - echo "*** The following schemes will be built:" - echo "$SCHEMES" | xargs -n 1 echo " " - echo + echo "*** Building and testing $SCHEME..." + 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 "$@" \ - ONLY_ACTIVE_ARCH=NO \ - CODE_SIGN_IDENTITY="" \ - CODE_SIGNING_REQUIRED=NO 2>&1 - elif [ -n "$XCODEPROJ" ] - then - xctool -project "$XCODEPROJ" $XCTOOL_OPTIONS "$@" \ - ONLY_ACTIVE_ARCH=NO \ - CODE_SIGN_IDENTITY="" \ - CODE_SIGNING_REQUIRED=NO 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 sdkflags=() - 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. - sdkflags=(-sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 5") - - # Determine whether the unit tests will run with iphonesimulator - run_xctool "${sdkflags[@]}" -scheme "$scheme" run-tests | parse_build - - awkstatus=$? - - if [ "$awkstatus" -ne "0" ] - then - # Unit tests will not run on iphonesimulator. - sdkflags=() - fi - fi - - if [ "$awkstatus" -ne "0" ] - then - # Unit tests aren't supported. - action=build - fi - - run_xctool "${sdkflags[@]}" -scheme "$scheme" $action -} - -export -f build_scheme -export -f run_xctool -export -f parse_build - -main + xcodebuild -workspace "$XCWORKSPACE" \ + -scheme "$SCHEME" \ + -destination "platform=iOS Simulator,name=iPhone 5" \ + -sdk iphonesimulator \ + ${XCODE_OPTIONS[*]} \ + build test \ + 2>&1 | xcpretty $XCPRETTY_FORMAT_OPTIONS +fi diff --git a/script/clean_externals b/script/clean_externals new file mode 100755 index 0000000..a25b6c5 --- /dev/null +++ b/script/clean_externals @@ -0,0 +1,22 @@ +#!/bin/bash -ex + +# +# clean_externals +# ObjectiveGit +# +# Removes the outputs from the various static library targets. +# Necessary when switching platforms/architectures as Xcode does not clean +# these for you. +# + +# A list of external static libraries included in the SwiftGit2 framework +libraries=( + External/libgit2.a + External/libgit2-ios/libgit2-ios.a + External/libssh2-ios/lib/libssh2-ios.a + External/ios-openssl/lib/libssl.a + External/ios-openssl/lib/libcrypto.a + External/ios-openssl/include +) + +rm -vrf "${libraries[@]}" diff --git a/script/schemes.awk b/script/schemes.awk deleted file mode 100644 index 4c94df9..0000000 --- a/script/schemes.awk +++ /dev/null @@ -1,10 +0,0 @@ -BEGIN { - FS = "\n"; -} - -/Schemes:/ { - while (getline && $0 != "") { - sub(/^ +/, ""); - print "'" $0 "'"; - } -} diff --git a/script/targets.awk b/script/targets.awk deleted file mode 100644 index 117660d..0000000 --- a/script/targets.awk +++ /dev/null @@ -1,12 +0,0 @@ -BEGIN { - FS = "\n"; -} - -/Targets:/ { - while (getline && $0 != "") { - if ($0 ~ /Tests/) continue; - - sub(/^ +/, ""); - print "'" $0 "'"; - } -} diff --git a/script/update_libgit2_ios b/script/update_libgit2_ios index 46029cb..7732f32 100755 --- a/script/update_libgit2_ios +++ b/script/update_libgit2_ios @@ -51,6 +51,7 @@ function build_libgit2 () -DBUILD_CLAR:BOOL=OFF \ -DTHREADSAFE:BOOL=ON \ -DCURL:BOOL=OFF \ + -DCMAKE_C_FLAGS:STRING="-fembed-bitcode" \ "${SYS_ROOT}" \ -DCMAKE_OSX_ARCHITECTURES:STRING="${ARCH}" \ .. >> "${LOG}" 2>&1 diff --git a/script/update_libssh2_ios b/script/update_libssh2_ios index 18d8a9f..8dd89c5 100755 --- a/script/update_libssh2_ios +++ b/script/update_libssh2_ios @@ -24,8 +24,8 @@ function build_ssh2 () 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}" + export CFLAGS="-arch ${ARCH} -fembed-bitcode -pipe -no-cpp-precomp -isysroot ${SDKROOT} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET}" + export CPPFLAGS="-arch ${ARCH} -fembed-bitcode -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" diff --git a/script/update_libssl_ios b/script/update_libssl_ios index 3d3a209..54c0a9a 100755 --- a/script/update_libssl_ios +++ b/script/update_libssl_ios @@ -43,7 +43,7 @@ function build_ssl () 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|^CC= gcc|CC= ${CLANG} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET} -arch ${ARCH} -fembed-bitcode |g" Makefile >> "${LOG}" 2>&1 perl -i -pe "s|^CFLAG= (.*)|CFLAG= -isysroot ${SDKROOT} \$1|g" Makefile >> "${LOG}" 2>&1 make >> "${LOG}" 2>&1 diff --git a/script/xcodebuild.awk b/script/xcodebuild.awk deleted file mode 100644 index c746b09..0000000 --- a/script/xcodebuild.awk +++ /dev/null @@ -1,35 +0,0 @@ -# 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 deleted file mode 100644 index f613258..0000000 --- a/script/xctool.awk +++ /dev/null @@ -1,25 +0,0 @@ -# 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; -}