/
build_framework.sh
executable file
·167 lines (141 loc) · 5.25 KB
/
build_framework.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/sh
#
# Copyright 2010-present Facebook.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This script builds Bolts.framework.
. ${BOLTS_SCRIPT:-$(dirname $0)}/common.sh
# process options, valid arguments -c [Debug|Release] -n
BUILDCONFIGURATION=Debug
NOEXTRAS=1
while getopts ":ntc:" OPTNAME
do
case "$OPTNAME" in
"c")
BUILDCONFIGURATION=$OPTARG
;;
"n")
NOEXTRAS=1
;;
"t")
NOEXTRAS=0
;;
"?")
echo "$0 -c [Debug|Release] -n"
echo " -c sets configuration (default=Debug)"
echo " -n no test run (default)"
echo " -t test run"
die
;;
":")
echo "Missing argument value for option $OPTARG"
die
;;
*)
# Should not occur
echo "Unknown error while processing options"
die
;;
esac
done
test -x "$XCODEBUILD" || die 'Could not find xcodebuild in $PATH'
test -x "$LIPO" || die 'Could not find lipo in $PATH'
BOLTS_IOS_BINARY=$BOLTS_BUILD/${BUILDCONFIGURATION}-universal/Bolts.framework/Bolts
BOLTS_OSX_BINARY=$BOLTS_BUILD/${BUILDCONFIGURATION}/Bolts.framework
BOLTS_TVOS_BINARY=$BOLTS_BUILD/${BUILDCONFIGURATION}-appletv-universal/Bolts.framework/Bolts
# -----------------------------------------------------------------------------
progress_message Building Framework.
# -----------------------------------------------------------------------------
# Compile binaries
#
test -d "$BOLTS_BUILD" \
|| mkdir -p "$BOLTS_BUILD" \
|| die "Could not create directory $BOLTS_BUILD"
test -d "$BOLTS_IOS_BUILD" \
|| mkdir -p "$BOLTS_IOS_BUILD" \
|| die "Could not create directory $BOLTS_IOS_BUILD"
test -d "$BOLTS_OSX_BUILD" \
|| mkdir -p "$BOLTS_OSX_BUILD" \
|| die "Could not create directory $BOLTS_OSX_BUILD"
test -d "$BOLTS_TVOS_BUILD" \
|| mkdir -p "$BOLTS_TVOS_BUILD" \
|| die "Could not create directory $BOLTS_TVOS_BUILD"
cd "$BOLTS_SRC"
function xcode_build_target() {
echo "Compiling for platform: ${1}."
$XCODEBUILD \
-target "${3}Bolts" \
-sdk $1 \
-configuration "${2}" \
SYMROOT="$BOLTS_BUILD" \
CURRENT_PROJECT_VERSION="$BOLTS_VERSION_FULL" \
clean build \
|| die "Xcode build failed for platform: ${1}."
}
xcode_build_target "iphonesimulator" "${BUILDCONFIGURATION}"
xcode_build_target "iphoneos" "${BUILDCONFIGURATION}"
xcode_build_target "macosx" "${BUILDCONFIGURATION}" "Mac"
xcode_build_target "appletvsimulator" "${BUILDCONFIGURATION}" "TV"
xcode_build_target "appletvos" "${BUILDCONFIGURATION}" "TV"
# -----------------------------------------------------------------------------
# Merge lib files for different platforms into universal binary
#
progress_message "Building Bolts univeral library using lipo."
mkdir -p "$(dirname "$BOLTS_IOS_BINARY")"
mkdir -p "$(dirname "$BOLTS_TVOS_BINARY")"
# Copy/Paste iOS Framework to get structure/resources/etc
cp -av \
"$BOLTS_BUILD/${BUILDCONFIGURATION}-iphoneos/Bolts.framework" \
"$BOLTS_BUILD/${BUILDCONFIGURATION}-universal"
rm "$BOLTS_BUILD/${BUILDCONFIGURATION}-universal/Bolts.framework/Bolts"
# Copy/Paste AppleTV framework to get structure/resources/etc
cp -av \
"$BOLTS_BUILD/${BUILDCONFIGURATION}-appletvos/Bolts.framework" \
"$BOLTS_BUILD/${BUILDCONFIGURATION}-appletv-universal"
rm "$BOLTS_BUILD/${BUILDCONFIGURATION}-appletv-universal/Bolts.framework/Bolts"
# Combine iOS/Simulator binaries into a single universal binary.
$LIPO \
-create \
"$BOLTS_BUILD/${BUILDCONFIGURATION}-iphonesimulator/Bolts.framework/Bolts" \
"$BOLTS_BUILD/${BUILDCONFIGURATION}-iphoneos/Bolts.framework/Bolts" \
-output "$BOLTS_IOS_BINARY" \
|| die "lipo failed - could not create universal static library"
# Combine AppleTV/Simulator binaries into a single universal binary.
$LIPO \
-create \
"$BOLTS_BUILD/${BUILDCONFIGURATION}-appletvsimulator/Bolts.framework/Bolts" \
"$BOLTS_BUILD/${BUILDCONFIGURATION}-appletvos/Bolts.framework/Bolts" \
-output "$BOLTS_TVOS_BINARY" \
|| die "lipo failed - could not create universal static library"
# Copy/Paste created iOS Framework to final location
cp -av "$(dirname "$BOLTS_IOS_BINARY")" $BOLTS_IOS_FRAMEWORK
# Copy/Paste OSX framework, as this is already built for us
cp -av "$BOLTS_OSX_BINARY" $BOLTS_OSX_FRAMEWORK
# Copy/Paste TVOS Framework
cp -av "$(dirname "$BOLTS_TVOS_BINARY")" $BOLTS_TVOS_FRAMEWORK
# -----------------------------------------------------------------------------
# Run unit tests
#
if [ ${NOEXTRAS:-0} -eq 1 ];then
progress_message "Skipping unit tests."
else
progress_message "Running unit tests."
cd $BOLTS_SRC
$BOLTS_SCRIPT/run_tests.sh -c $BUILDCONFIGURATION MacBolts
fi
# -----------------------------------------------------------------------------
# Done
#
progress_message "Framework version info:" `perl -pe "s/.*@//" < $BOLTS_SRC/Bolts/Common/BoltsVersion.h`
common_success