|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -SCRIPT_DIR=$(dirname "$0") |
4 |
| -cd "$SCRIPT_DIR/.." |
| 3 | +export SCRIPT_DIR=$(dirname "$0") |
5 | 4 |
|
6 | 5 | ##
|
7 | 6 | ## Configuration Variables
|
8 | 7 | ##
|
9 | 8 |
|
10 |
| -# The build configuration to use. |
11 |
| -if [ -z "$XCCONFIGURATION" ] |
12 |
| -then |
13 |
| - XCCONFIGURATION="Release" |
14 |
| -fi |
15 |
| - |
16 |
| -# The workspace to build. |
17 |
| -# |
18 |
| -# If not set and no workspace is found, the -workspace flag will not be passed |
19 |
| -# to xcodebuild. |
20 |
| -if [ -z "$XCWORKSPACE" ] |
21 |
| -then |
22 |
| - XCWORKSPACE=$(ls -d *.xcworkspace 2>/dev/null | head -n 1) |
23 |
| -fi |
24 |
| - |
25 |
| -# A bootstrap script to run before building. |
26 |
| -# |
27 |
| -# If this file does not exist, it is not considered an error. |
28 |
| -BOOTSTRAP="$SCRIPT_DIR/bootstrap" |
29 |
| - |
30 |
| -# A whitespace-separated list of default targets or schemes to build, if none |
31 |
| -# are specified on the command line. |
32 |
| -# |
33 |
| -# Individual names can be quoted to avoid word splitting. |
34 |
| -DEFAULT_TARGETS= |
35 |
| - |
36 |
| -# Extra build settings to pass to xcodebuild. |
37 |
| -XCODEBUILD_SETTINGS="TEST_AFTER_BUILD=YES" |
| 9 | +SCHEMES="$@" |
| 10 | + |
| 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 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 | +} |
38 | 50 |
|
39 | 51 | ##
|
40 | 52 | ## Build Process
|
41 | 53 | ##
|
42 | 54 |
|
43 |
| -if [ -z "$*" ] |
44 |
| -then |
45 |
| - # lol recursive shell script |
46 |
| - if [ -n "$DEFAULT_TARGETS" ] |
| 55 | +main () |
| 56 | +{ |
| 57 | + config |
| 58 | + |
| 59 | + if [ -f "$BOOTSTRAP" ] |
47 | 60 | then
|
48 |
| - echo "$DEFAULT_TARGETS" | xargs "$SCRIPT_DIR/cibuild" |
49 |
| - else |
50 |
| - xcodebuild -list | awk -f "$SCRIPT_DIR/targets.awk" | xargs "$SCRIPT_DIR/cibuild" |
| 61 | + echo "*** Bootstrapping..." |
| 62 | + "$BOOTSTRAP" || exit $? |
51 | 63 | fi
|
52 | 64 |
|
53 |
| - exit $? |
54 |
| -fi |
55 |
| - |
56 |
| -if [ -f "$BOOTSTRAP" ] |
57 |
| -then |
58 |
| - echo "*** Bootstrapping..." |
59 |
| - bash "$BOOTSTRAP" || exit $? |
60 |
| -fi |
| 65 | + echo "*** The following schemes will be built:" |
| 66 | + echo "$SCHEMES" | xargs -n 1 echo " " |
| 67 | + echo |
61 | 68 |
|
62 |
| -echo "*** The following targets will be built:" |
| 69 | + echo "$SCHEMES" | xargs -n 1 | ( |
| 70 | + local status=0 |
63 | 71 |
|
64 |
| -for target in "$@" |
65 |
| -do |
66 |
| - echo "$target" |
67 |
| -done |
| 72 | + while read scheme |
| 73 | + do |
| 74 | + build_scheme "$scheme" || status=1 |
| 75 | + done |
68 | 76 |
|
69 |
| -echo "*** Cleaning all targets..." |
70 |
| -xcodebuild -alltargets clean OBJROOT="$PWD/build" SYMROOT="$PWD/build" $XCODEBUILD_SETTINGS |
| 77 | + exit $status |
| 78 | + ) |
| 79 | +} |
71 | 80 |
|
72 |
| -run_xcodebuild () |
| 81 | +find_pattern () |
73 | 82 | {
|
74 |
| - local scheme=$1 |
| 83 | + ls -d $1 2>/dev/null | head -n 1 |
| 84 | +} |
75 | 85 |
|
| 86 | +run_xctool () |
| 87 | +{ |
76 | 88 | if [ -n "$XCWORKSPACE" ]
|
77 | 89 | then
|
78 |
| - xcodebuild -workspace "$XCWORKSPACE" -scheme "$scheme" -configuration "$XCCONFIGURATION" build OBJROOT="$PWD/build" SYMROOT="$PWD/build" $XCODEBUILD_SETTINGS |
| 90 | + xctool -workspace "$XCWORKSPACE" $XCTOOL_OPTIONS "$@" 2>&1 |
| 91 | + elif [ -n "$XCODEPROJ" ] |
| 92 | + then |
| 93 | + xctool -project "$XCODEPROJ" $XCTOOL_OPTIONS "$@" 2>&1 |
79 | 94 | else
|
80 |
| - xcodebuild -scheme "$scheme" -configuration "$XCCONFIGURATION" build OBJROOT="$PWD/build" SYMROOT="$PWD/build" $XCODEBUILD_SETTINGS |
| 95 | + echo "*** No workspace or project file found." |
| 96 | + exit 1 |
81 | 97 | fi
|
| 98 | +} |
82 | 99 |
|
83 |
| - local status=$? |
84 |
| - |
85 |
| - return $status |
| 100 | +parse_build () |
| 101 | +{ |
| 102 | + awk -f "$SCRIPT_DIR/xctool.awk" 2>&1 >/dev/null |
86 | 103 | }
|
87 | 104 |
|
88 | 105 | build_scheme ()
|
89 | 106 | {
|
90 | 107 | local scheme=$1
|
91 | 108 |
|
92 |
| - run_xcodebuild "$scheme" 2>&1 | awk -f "$SCRIPT_DIR/xcodebuild.awk" |
| 109 | + echo "*** Cleaning $scheme..." |
| 110 | + run_xctool -scheme "$scheme" clean >/dev/null || exit $? |
| 111 | + |
| 112 | + echo "*** Building and testing $scheme..." |
| 113 | + echo |
| 114 | + |
| 115 | + local sdkflag= |
| 116 | + local action=test |
| 117 | + |
| 118 | + # Determine whether we can run unit tests for this target. |
| 119 | + run_xctool -scheme "$scheme" run-tests | parse_build |
93 | 120 |
|
94 | 121 | local awkstatus=$?
|
95 |
| - local xcstatus=${PIPESTATUS[0]} |
96 | 122 |
|
97 |
| - if [ "$xcstatus" -eq "65" ] |
| 123 | + if [ "$awkstatus" -ne "0" ] |
98 | 124 | then
|
99 |
| - # This probably means that there's no scheme by that name. Give up. |
100 |
| - echo "*** Error building scheme $scheme -- perhaps it doesn't exist" |
101 |
| - elif [ "$awkstatus" -eq "1" ] |
| 125 | + # Unit tests aren't supported. |
| 126 | + action=build |
| 127 | + fi |
| 128 | + |
| 129 | + if [ "$awkstatus" -eq "1" ] |
102 | 130 | then
|
103 |
| - return $awkstatus |
| 131 | + # Build for iOS. |
| 132 | + sdkflag="-sdk iphonesimulator" |
104 | 133 | fi
|
105 | 134 |
|
106 |
| - return $xcstatus |
| 135 | + run_xctool $sdkflag -scheme "$scheme" $action |
107 | 136 | }
|
108 | 137 |
|
109 |
| -echo "*** Building..." |
| 138 | +export -f build_scheme |
| 139 | +export -f run_xctool |
| 140 | +export -f parse_build |
110 | 141 |
|
111 |
| -for scheme in "$@" |
112 |
| -do |
113 |
| - build_scheme "$scheme" || exit $? |
114 |
| -done |
| 142 | +main |
0 commit comments