|
1 | 1 | #!/bin/bash |
| 2 | +# |
| 3 | +# script/cibuild |
| 4 | +# ObjectiveGit |
| 5 | +# |
| 6 | +# Executes the build and runs tests for Mac and iOS. Designed to be invoked by |
| 7 | +# Travis as a matrix build so that the two platform builds can run in parallel. |
| 8 | +# |
| 9 | +# Dependent tools & scripts: |
| 10 | +# - script/bootstrap |
| 11 | +# - script/update_libssl_ios |
| 12 | +# - [xcodebuild](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html) |
| 13 | +# - xcpretty (gem) |
| 14 | +# - xcpretty-travis-formatter (gem) |
| 15 | +# |
| 16 | +# Environment Variables: |
| 17 | +# - SCHEME: specifies which Xcode scheme to build. Set to one of the following: |
| 18 | +# - ObjectiveGit Mac |
| 19 | +# - ObjectiveGit iOS |
| 20 | +# - TRAVIS: indicates when the build is being run by travis, used to invoke |
| 21 | +# the xcpretty-travis-formatter gem for output. |
| 22 | + |
| 23 | +if [ -z "$SCHEME" ]; then |
| 24 | + echo "The SCHEME environment variable is empty. Please set this to one of:" |
| 25 | + echo "- ObjectiveGit Mac" |
| 26 | + echo "- ObjectiveGit iOS" |
| 27 | + exit 1 |
| 28 | +fi |
2 | 29 |
|
3 | | -export SCRIPT_DIR=$(dirname "$0") |
4 | 30 |
|
5 | 31 | ## |
6 | 32 | ## Configuration Variables |
7 | 33 | ## |
8 | 34 |
|
9 | | -SCHEMES="$@" |
| 35 | +SCRIPT_DIR=$(dirname "$0") |
| 36 | +XCWORKSPACE="ObjectiveGitFramework.xcworkspace" |
| 37 | +XCODE_OPTIONS=$(RUN_CLANG_STATIC_ANALYZER=NO ONLY_ACTIVE_ARCH=NO CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO) |
10 | 38 |
|
11 | | -config () |
12 | | -{ |
13 | | - # The workspace to build. |
14 | | - # |
15 | | - # If not set and no workspace is found, the -workspace flag will not be passed |
16 | | - # to `xctool`. |
17 | | - # |
18 | | - # Only one of `XCWORKSPACE` and `XCODEPROJ` needs to be set. The former will |
19 | | - # take precedence. |
20 | | - : ${XCWORKSPACE=$(find_pattern "*.xcworkspace")} |
21 | | - |
22 | | - # The project to build. |
23 | | - # |
24 | | - # If not set and no project is found, the -project flag will not be passed |
25 | | - # to `xctool`. |
26 | | - # |
27 | | - # Only one of `XCWORKSPACE` and `XCODEPROJ` needs to be set. The former will |
28 | | - # take precedence. |
29 | | - : ${XCODEPROJ=$(find_pattern "*.xcodeproj")} |
30 | | - |
31 | | - # A bootstrap script to run before building. |
32 | | - # |
33 | | - # If this file does not exist, it is not considered an error. |
34 | | - : ${BOOTSTRAP="$SCRIPT_DIR/bootstrap"} |
35 | | - |
36 | | - # Extra options to pass to xctool. |
37 | | - : ${XCTOOL_OPTIONS="RUN_CLANG_STATIC_ANALYZER=NO"} |
38 | | - |
39 | | - # A whitespace-separated list of default schemes to build. |
40 | | - # |
41 | | - # Individual names can be quoted to avoid word splitting. |
42 | | - : ${SCHEMES:=$(xcodebuild -list -project "$XCODEPROJ" 2>/dev/null | awk -f "$SCRIPT_DIR/schemes.awk")} |
43 | | - |
44 | | - export XCWORKSPACE |
45 | | - export XCODEPROJ |
46 | | - export BOOTSTRAP |
47 | | - export XCTOOL_OPTIONS |
48 | | - export SCHEMES |
49 | | -} |
| 39 | +if [ -n "$TRAVIS" ]; then |
| 40 | + # Use a special formatter when running on TravisCI |
| 41 | + XCPRETTY_FORMAT_OPTIONS="-f `xcpretty-travis-formatter`" |
| 42 | +else |
| 43 | + XCPRETTY_FORMAT_OPTIONS="--color" |
| 44 | +fi |
50 | 45 |
|
51 | 46 | ## |
52 | 47 | ## Build Process |
53 | 48 | ## |
54 | 49 |
|
55 | | -main () |
56 | | -{ |
57 | | - config |
58 | | - |
59 | | - if [ -f "$BOOTSTRAP" ] |
60 | | - then |
61 | | - echo "*** Bootstrapping..." |
62 | | - "$BOOTSTRAP" || exit $? |
63 | | - fi |
64 | | - |
65 | | - if [ "$SCHEME" == "ObjectiveGit iOS" ] |
66 | | - then |
67 | | - echo "*** Prebuilding OpenSSL" |
68 | | - $SCRIPT_DIR/update_libssl_ios |
69 | | - fi |
70 | | - |
71 | | - if [ -z "${SCHEME+x}" ] && [ "${#SCHEME[@]}" = 0 ] |
72 | | - then |
73 | | - echo "*** The following schemes will be built:" |
74 | | - echo "$SCHEMES" | xargs -n 1 echo " " |
75 | | - echo |
76 | | - |
77 | | - echo "$SCHEMES" | xargs -n 1 | ( |
78 | | - local status=0 |
79 | | - |
80 | | - while read scheme |
81 | | - do |
82 | | - build_scheme "$scheme" || status=1 |
83 | | - done |
84 | | - |
85 | | - exit $status |
86 | | - ) |
87 | | - else |
88 | | - echo "*** The following scheme will be built $SCHEME" |
89 | | - local status=0 |
90 | | - build_scheme "$SCHEME" || status=1 |
91 | | - exit $status |
92 | | - fi |
93 | | -} |
94 | | - |
95 | | -find_pattern () |
96 | | -{ |
97 | | - ls -d $1 2>/dev/null | head -n 1 |
98 | | -} |
99 | | - |
100 | | -run_xctool () |
101 | | -{ |
102 | | - if [ -n "$XCWORKSPACE" ] |
103 | | - then |
104 | | - xctool -workspace "$XCWORKSPACE" $XCTOOL_OPTIONS "$@" \ |
105 | | - ONLY_ACTIVE_ARCH=NO \ |
106 | | - CODE_SIGN_IDENTITY="" \ |
107 | | - CODE_SIGNING_REQUIRED=NO 2>&1 |
108 | | - elif [ -n "$XCODEPROJ" ] |
109 | | - then |
110 | | - xctool -project "$XCODEPROJ" $XCTOOL_OPTIONS "$@" \ |
111 | | - ONLY_ACTIVE_ARCH=NO \ |
112 | | - CODE_SIGN_IDENTITY="" \ |
113 | | - CODE_SIGNING_REQUIRED=NO 2>&1 |
114 | | - else |
115 | | - echo "*** No workspace or project file found." |
116 | | - exit 1 |
117 | | - fi |
118 | | -} |
119 | | - |
120 | | -parse_build () |
121 | | -{ |
122 | | - awk -f "$SCRIPT_DIR/xctool.awk" 2>&1 >/dev/null |
123 | | -} |
124 | | - |
125 | | -build_scheme () |
126 | | -{ |
127 | | - local scheme=$1 |
128 | | - |
129 | | - echo "*** Building and testing $scheme..." |
130 | | - echo |
131 | | - |
132 | | - local sdkflags=() |
133 | | - local action=test |
134 | | - |
135 | | - # Determine whether we can run unit tests for this target. |
136 | | - run_xctool -scheme "$scheme" run-tests | parse_build |
137 | | - |
138 | | - local awkstatus=$? |
139 | | - |
140 | | - if [ "$awkstatus" -eq "1" ] |
141 | | - then |
142 | | - # SDK not found, try for iphonesimulator. |
143 | | - sdkflags=(-sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 5") |
144 | | - |
145 | | - # Determine whether the unit tests will run with iphonesimulator |
146 | | - run_xctool "${sdkflags[@]}" -scheme "$scheme" run-tests | parse_build |
147 | | - |
148 | | - awkstatus=$? |
149 | | - |
150 | | - if [ "$awkstatus" -ne "0" ] |
151 | | - then |
152 | | - # Unit tests will not run on iphonesimulator. |
153 | | - sdkflags=() |
154 | | - fi |
155 | | - fi |
156 | | - |
157 | | - if [ "$awkstatus" -ne "0" ] |
158 | | - then |
159 | | - # Unit tests aren't supported. |
160 | | - action=build |
161 | | - fi |
162 | | - |
163 | | - run_xctool "${sdkflags[@]}" -scheme "$scheme" $action |
164 | | -} |
165 | | - |
166 | | -export -f build_scheme |
167 | | -export -f run_xctool |
168 | | -export -f parse_build |
169 | | - |
170 | | -main |
| 50 | +echo "*** Bootstrapping..." |
| 51 | +"$SCRIPT_DIR/bootstrap" |
| 52 | + |
| 53 | +if [ "$SCHEME" == "ObjectiveGit Mac" ]; then |
| 54 | + echo "*** Building and testing $SCHEME..." |
| 55 | + echo |
| 56 | + |
| 57 | + xcodebuild -workspace "$XCWORKSPACE" \ |
| 58 | + -scheme "$SCHEME" \ |
| 59 | + ${XCODE_OPTIONS[*]} \ |
| 60 | + build test \ |
| 61 | + 2>&1 | xcpretty $XCPRETTY_FORMAT_OPTIONS |
| 62 | +elif [ "$SCHEME" == "ObjectiveGit iOS" ]; then |
| 63 | + echo "*** Prebuilding OpenSSL" |
| 64 | + "$SCRIPT_DIR/update_libssl_ios" |
| 65 | + |
| 66 | + echo "*** Building and testing $SCHEME..." |
| 67 | + echo |
| 68 | + |
| 69 | + xcodebuild -workspace "$XCWORKSPACE" \ |
| 70 | + -scheme "$SCHEME" \ |
| 71 | + -destination "platform=iOS Simulator,name=iPhone 5" \ |
| 72 | + -sdk iphonesimulator \ |
| 73 | + ${XCODE_OPTIONS[*]} \ |
| 74 | + build test \ |
| 75 | + 2>&1 | xcpretty $XCPRETTY_FORMAT_OPTIONS |
| 76 | +fi |
0 commit comments