Skip to content

Commit a534e56

Browse files
committed
build(buildscript): add build.sh script
1 parent 411cef5 commit a534e56

File tree

3 files changed

+259
-16
lines changed

3 files changed

+259
-16
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@ DerivedData
9090

9191
Carthage
9292
Pods/
93+
94+
## Custom
95+
96+
Release
97+
Podfile.lock
98+

Example/Podfile.lock

Lines changed: 0 additions & 16 deletions
This file was deleted.

build.sh

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
#!/usr/bin/env bash
2+
#
3+
# LPM | Author: Ben Marten
4+
# Copyright (c) 2017 Leanplum Inc. All rights reserved.
5+
#
6+
# shellcheck disable=SC2140
7+
set -eo pipefail; [[ $DEBUG ]] && set -x
8+
9+
#######################################
10+
# COMMON BEGIN
11+
#######################################
12+
13+
#######################################
14+
# Print out error messages along with other status information.
15+
# Globals:
16+
# None
17+
# Arguments:
18+
# None
19+
# Returns:
20+
# None
21+
#######################################
22+
err() {
23+
printf "%s%s%s\n" "${RED}ERROR [$(date +'%Y-%m-%dT%H:%M:%S%z')]: " "$@" "${NORMAL}" >&2
24+
}
25+
26+
#######################################
27+
# Runs a sub command and only outputs the stderr to console, then exits.
28+
# Globals:
29+
# None
30+
# Arguments:
31+
# Description of the command to run.
32+
# The command to run.
33+
# Returns:
34+
# None
35+
#######################################
36+
run() {
37+
echo "$1"
38+
local cmd=${*:2}
39+
40+
set +o errexit
41+
local error
42+
error=$(${cmd} 2>&1 >/dev/null)
43+
set -o errexit
44+
45+
if [ -n "$error" ]; then
46+
err "Error running command: '$cmd':" "$error"
47+
exit 1
48+
fi
49+
}
50+
51+
#######################################
52+
# COMMON END
53+
#######################################
54+
55+
#######################################
56+
# Builds the Apple SDK.
57+
# Globals:
58+
# IOS_VERSION The version to build.
59+
# BUILD_NUMBER The build number to use, defaults to timestamp.
60+
# Arguments:
61+
# None
62+
# Returns:
63+
# None
64+
#######################################
65+
main() {
66+
# Check for Jenkins build number, otherwise default to curent time in seconds.
67+
if [[ -z "${BUILD_NUMBER+x}" ]]; then
68+
BUILD_NUMBER=$(date "+%s")
69+
fi
70+
export IOS_VERSION_STRING="$IOS_VERSION+$BUILD_NUMBER"
71+
72+
LEANPLUM_SDK_ROOT=${LEANPLUM_SDK_ROOT:-"$(pwd)/."}
73+
RELEASE_DIR_BASE=${RELEASE_DIR_BASE:-"$LEANPLUM_SDK_ROOT/Release"}
74+
CONFIGURATION=${CONFIGURATION:-"Release"}
75+
BUILD_DIR=${BUILD_DIR:-"/tmp/AppleSDK-build"}
76+
BUILD_ROOT=${BUILD_ROOT:-"/tmp/AppleSDK-build"}
77+
ARM64_DIR=${ARM64_DIR:-"/build-arm64"}
78+
ARMV7S_DIR=${ARMV7S_DIR:-"/build-armv7s"}
79+
X8664_DIR=${X8664_DIR:-"/build-x86_64"}
80+
ARMV7_DIR=${ARMV7_DIR:-"/build-armv7"}
81+
X86_DIR=${X86_DIR:-"/build-x86"}
82+
default="${BUILD_DIR}${ARMV7_DIR}/${CONFIGURATION}-iphoneos"
83+
CURRENTCONFIG_ARMV7_DEVICE_DIR=${CURRENTCONFIG_ARMV7_DEVICE_DIR:-$default}
84+
default="${BUILD_DIR}${ARM64_DIR}/${CONFIGURATION}-iphoneos"
85+
CURRENTCONFIG_ARM64_DEVICE_DIR=${CURRENTCONFIG_ARM64_DEVICE_DIR:-$default}
86+
default="${BUILD_DIR}${ARMV7S_DIR}/${CONFIGURATION}-iphoneos"
87+
CURRENTCONFIG_ARMV7S_DEVICE_DIR=${CURRENTCONFIG_ARMV7S_DEVICE_DIR:-$default}
88+
default="${BUILD_DIR}${X86_DIR}/${CONFIGURATION}-iphonesimulator"
89+
CURRENTCONFIG_X86_DEVICE_DIR=${CURRENTCONFIG_X86_DEVICE_DIR:-$default}
90+
default="${BUILD_DIR}${X8664_DIR}/${CONFIGURATION}-iphonesimulator"
91+
CURRENTCONFIG_X8664_SIMULATOR_DIR=${CURRENTCONFIG_X8664_SIMULATOR_DIR:-$default}
92+
ACTION="clean build"
93+
94+
DEVICE_SDK="iphoneos"
95+
SIM_SDK="iphonesimulator"
96+
97+
rm -rf "$RELEASE_DIR_BASE"
98+
mkdir -p "$RELEASE_DIR_BASE"
99+
RELEASE_DIR="$RELEASE_DIR_BASE"
100+
mkdir -p "$RELEASE_DIR"
101+
102+
# Build Dynamic Framework
103+
cd "$LEANPLUM_SDK_ROOT/Example/"
104+
pod install
105+
cd "$LEANPLUM_SDK_ROOT/Example/Pods"
106+
build_ios_dylib
107+
108+
# Build Static Framework
109+
RELEASE_DIR="$RELEASE_DIR_BASE/static"
110+
mkdir -p "$RELEASE_DIR"
111+
112+
export LP_STATIC=1
113+
cd "$LEANPLUM_SDK_ROOT/Example/"
114+
pod install
115+
cd "$LEANPLUM_SDK_ROOT/Example/Pods"
116+
build_ios
117+
118+
echo "${GREEN} Done.${NORMAL}"
119+
}
120+
121+
#######################################
122+
# Builds the iOS Target.
123+
# Globals:
124+
# None
125+
# Arguments:
126+
# None
127+
# Returns:
128+
# None
129+
#######################################
130+
build_ios() {
131+
echo "Starting build for Leanplum-SDK (iOS)"
132+
133+
run "Building Leanplum-SDK (device/armv7) target ..." \
134+
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source-iOS" -sdk "${DEVICE_SDK}" \
135+
"$ACTION" ARCHS='armv7' RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}${ARMV7_DIR}" \
136+
BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode"
137+
run "Building Leanplum-SDK (device/armv7s) target ..." \
138+
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source-iOS" -sdk "${DEVICE_SDK}" \
139+
"$ACTION" ARCHS='armv7s' RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}${ARMV7S_DIR}" \
140+
BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode"
141+
run "Building Leanplum-SDK (device/arm64) target ..." \
142+
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source-iOS" -sdk "${DEVICE_SDK}" \
143+
"$ACTION" ARCHS='arm64' RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}${ARM64_DIR}" \
144+
BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode"
145+
run "Building Leanplum-SDK (simulator/i386) target ..." \
146+
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source-iOS" -sdk "${SIM_SDK}" \
147+
"$ACTION" ARCHS='i386' VALID_ARCHS='i386' RUN_CLANG_STATIC_ANALYZER=NO \
148+
BUILD_DIR="${BUILD_DIR}${X86_DIR}" BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode"
149+
run "Building Leanplum-SDK (simulator/x86_64) target ..." \
150+
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source-iOS" -sdk "${SIM_SDK}" \
151+
"$ACTION" ARCHS='x86_64' VALID_ARCHS='x86_64' RUN_CLANG_STATIC_ANALYZER=NO \
152+
BUILD_DIR="${BUILD_DIR}${X8664_DIR}" BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode"
153+
154+
mkdir "${RELEASE_DIR}/Leanplum.framework/"
155+
run "Combining builds to universal fat library ..." \
156+
lipo -create -output "${RELEASE_DIR}/Leanplum.framework/Leanplum" \
157+
"${CURRENTCONFIG_ARMV7_DEVICE_DIR}/Leanplum-iOS-SDK-source-iOS/libLeanplum-iOS-SDK-source-iOS.a" \
158+
"${CURRENTCONFIG_ARMV7S_DEVICE_DIR}/Leanplum-iOS-SDK-source-iOS/libLeanplum-iOS-SDK-source-iOS.a" \
159+
"${CURRENTCONFIG_ARM64_DEVICE_DIR}/Leanplum-iOS-SDK-source-iOS/libLeanplum-iOS-SDK-source-iOS.a" \
160+
"${CURRENTCONFIG_X86_DEVICE_DIR}/Leanplum-iOS-SDK-source-iOS/libLeanplum-iOS-SDK-source-iOS.a" \
161+
"${CURRENTCONFIG_X8664_SIMULATOR_DIR}/Leanplum-iOS-SDK-source-iOS/libLeanplum-iOS-SDK-source-iOS.a"
162+
163+
# Create .framework package.
164+
mkdir -p "${RELEASE_DIR}/Leanplum.framework"
165+
mkdir -p "${RELEASE_DIR}/Leanplum.framework/Headers"
166+
mkdir -p "${RELEASE_DIR}/Leanplum.framework/Modules"
167+
168+
# Add modulemap.
169+
cat <<EOF > "${RELEASE_DIR}/Leanplum.framework/Modules/module.modulemap"
170+
framework module Leanplum {
171+
umbrella header "Leanplum.h"
172+
export *
173+
module *
174+
{ export * }
175+
}
176+
EOF
177+
178+
# Copy headers.
179+
cp "$LEANPLUM_SDK_ROOT/Leanplum-SDK/Classes/Leanplum.h" "${RELEASE_DIR}/Leanplum.framework/Headers"
180+
cp "$LEANPLUM_SDK_ROOT/Leanplum-SDK/Classes/Leanplum.h" "${RELEASE_DIR}/Leanplum.framework/Headers"
181+
182+
printf "%s\n" "Successfully built Leanplum-SDK (iOS) Framework."
183+
}
184+
185+
#######################################
186+
# Builds the iOS dynamic library Target.
187+
# Globals:
188+
# None
189+
# Arguments:
190+
# None
191+
# Returns:
192+
# None
193+
#######################################
194+
build_ios_dylib() {
195+
echo "Starting build for Leanplum-SDK (iOS)"
196+
197+
run "Building Leanplum-SDK (device/armv7) target ..." \
198+
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source-iOS" -sdk "${DEVICE_SDK}" \
199+
"$ACTION" ARCHS='armv7' RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}${ARMV7_DIR}" \
200+
BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode"
201+
run "Building Leanplum-SDK (device/armv7s) target ..." \
202+
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source-iOS" -sdk "${DEVICE_SDK}" \
203+
"$ACTION" ARCHS='armv7s' RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}${ARMV7S_DIR}" \
204+
BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode"
205+
run "Building Leanplum-SDK (device/arm64) target ..." \
206+
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source-iOS" -sdk "${DEVICE_SDK}" \
207+
"$ACTION" ARCHS='arm64' RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}${ARM64_DIR}" \
208+
BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode"
209+
run "Building Leanplum-SDK (simulator/i386) target ..." \
210+
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source-iOS" -sdk "${SIM_SDK}" \
211+
"$ACTION" ARCHS='i386' VALID_ARCHS='i386' RUN_CLANG_STATIC_ANALYZER=NO \
212+
BUILD_DIR="${BUILD_DIR}${X86_DIR}" BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode"
213+
run "Building Leanplum-SDK (simulator/x86_64) target ..." \
214+
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source-iOS" -sdk "${SIM_SDK}" \
215+
"$ACTION" ARCHS='x86_64' VALID_ARCHS='x86_64' RUN_CLANG_STATIC_ANALYZER=NO \
216+
BUILD_DIR="${BUILD_DIR}${X8664_DIR}" BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode"
217+
218+
run "Combining builds to universal fat library ..." \
219+
lipo -create -output "${RELEASE_DIR}/Leanplum" \
220+
"${CURRENTCONFIG_ARMV7_DEVICE_DIR}/Leanplum-iOS-SDK-source-iOS/Leanplum.framework/Leanplum" \
221+
"${CURRENTCONFIG_ARMV7S_DEVICE_DIR}/Leanplum-iOS-SDK-source-iOS/Leanplum.framework/Leanplum" \
222+
"${CURRENTCONFIG_ARM64_DEVICE_DIR}/Leanplum-iOS-SDK-source-iOS/Leanplum.framework/Leanplum" \
223+
"${CURRENTCONFIG_X86_DEVICE_DIR}/Leanplum-iOS-SDK-source-iOS/Leanplum.framework/Leanplum" \
224+
"${CURRENTCONFIG_X8664_SIMULATOR_DIR}/Leanplum-iOS-SDK-source-iOS/Leanplum.framework/Leanplum"
225+
226+
# Copy generated framework
227+
cp -r "${BUILD_DIR}$ARMV7_DIR/$CONFIGURATION-iphoneos/Leanplum-iOS-SDK-source-iOS/Leanplum.framework/" \
228+
"${RELEASE_DIR}/Leanplum.framework"
229+
rm -f "${RELEASE_DIR}/Leanplum.framework/Leanplum"
230+
mv "${RELEASE_DIR}/Leanplum" "${RELEASE_DIR}/Leanplum.framework/"
231+
232+
# Delete unnecessary headers
233+
mv "${RELEASE_DIR}/Leanplum.framework/Headers/Leanplum.h" \
234+
"${RELEASE_DIR}/Leanplum.framework/"
235+
mv "${RELEASE_DIR}/Leanplum.framework/Headers/LPInbox.h" \
236+
"${RELEASE_DIR}/Leanplum.framework/"
237+
rm -rf "${RELEASE_DIR}/Leanplum.framework/Headers"
238+
mkdir "${RELEASE_DIR}/Leanplum.framework/Headers"
239+
mv "${RELEASE_DIR}/Leanplum.framework/Leanplum.h" \
240+
"${RELEASE_DIR}/Leanplum.framework/Headers/"
241+
mv "${RELEASE_DIR}/Leanplum.framework/LPInbox.h" \
242+
"${RELEASE_DIR}/Leanplum.framework/Headers/"
243+
244+
rm -rf "${RELEASE_DIR}/Leanplum.framework/_CodeSignature"
245+
# Update modulemap with correct import, since umbrella header is not generated by cocoapods with
246+
# a custom module_name set.
247+
sed -i "" -e "s/Leanplum-iOS-SDK-source-iOS-umbrella.h/Leanplum.h/g" \
248+
"${RELEASE_DIR}/Leanplum.framework/modules/module.modulemap"
249+
250+
printf "%s\n" "Successfully built Leanplum-SDK (iOS) Framework.\n"
251+
}
252+
253+
main "$@"

0 commit comments

Comments
 (0)