Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: tools-webrtc/ios/build_ios_libs.sh

Issue 2662513004: Rewrite iOS FAT libraries build script in Python (Closed)
Patch Set: Rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools-webrtc/ios/build_ios_libs.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Copyright 2015 The WebRTC project authors. All Rights Reserved. 3 # Copyright 2017 The WebRTC project authors. All Rights Reserved.
4 # 4 #
5 # Use of this source code is governed by a BSD-style license 5 # Use of this source code is governed by a BSD-style license
6 # that can be found in the LICENSE file in the root of the source 6 # that can be found in the LICENSE file in the root of the source
7 # tree. An additional intellectual property rights grant can be found 7 # tree. An additional intellectual property rights grant can be found
8 # in the file PATENTS. All contributing project authors may 8 # in the file PATENTS. All contributing project authors may
9 # be found in the AUTHORS file in the root of the source tree. 9 # be found in the AUTHORS file in the root of the source tree.
10 10
11 # Generates static FAT libraries for ios in out_ios_libs. 11 # This script has been rewritten in Python. Temporary "redirect":
12 12
13 # Exit on errors. 13 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
14 set -e
15 14
16 # Environment 15 exec "$SCRIPT_DIR/build_ios_libs.py" "$@"
17 export PATH=/usr/libexec:$PATH
18
19 SCRIPT_DIR=$(cd $(dirname $0) && pwd)
20 WEBRTC_BASE_DIR=${SCRIPT_DIR}/../..
21
22 function clean_artifacts {
23 local output_dir=$1
24 if [[ -d ${output_dir} ]]; then
25 echo "Deleting ${output_dir}"
26 rm -r ${output_dir}
27 fi
28 }
29
30 function build_webrtc {
31 local target_arch=$1
32 local flavor=$2
33 local build_type=$3
34 local ios_deployment_target=$4
35 local libvpx_build_vp9=$5
36 local use_bitcode=$6
37 local custom_gn_options=$7
38
39 OUTPUT_DIR=${SDK_OUTPUT_DIR}/${target_arch}_libs
40 GN_ARGS="target_os=\"ios\" ios_enable_code_signing=false \
41 use_xcode_clang=true is_component_build=false"
42
43 # Add flavor option.
44 if [[ ${flavor} = "debug" ]]; then
45 GN_ARGS="${GN_ARGS} is_debug=true"
46 elif [[ ${flavor} = "release" ]]; then
47 GN_ARGS="${GN_ARGS} is_debug=false"
48 else
49 echo "Unexpected flavor type: ${flavor}"
50 exit 1
51 fi
52
53 # Add the specified architecture.
54 GN_ARGS="${GN_ARGS} target_cpu=\"${target_arch}\""
55
56 # Add deployment target.
57 GN_ARGS="${GN_ARGS} ios_deployment_target=\"${ios_deployment_target}\""
58
59 # Add vp9 option.
60 GN_ARGS="${GN_ARGS} rtc_libvpx_build_vp9=${libvpx_build_vp9}"
61
62 # Add bitcode option.
63 GN_ARGS="${GN_ARGS} enable_ios_bitcode=${use_bitcode}"
64
65 # Add custom options.
66 if [[ -n "${custom_gn_options}" ]]; then
67 GN_ARGS="${GN_ARGS} ${custom_gn_options}"
68 fi
69
70 # Generate static or dynamic.
71 if [[ ${build_type} = "static_only" ]]; then
72 GN_TARGET_NAME="rtc_sdk_objc"
73 elif [[ ${build_type} == "framework" ]]; then
74 GN_TARGET_NAME="rtc_sdk_framework_objc"
75 GN_ARGS="${GN_ARGS} enable_dsyms=true enable_stripping=true"
76 else
77 echo "Build type \"${build_type}\" is not supported."
78 exit 1
79 fi
80
81 echo "Building WebRTC with args: ${GN_ARGS}"
82 gn gen ${OUTPUT_DIR} --args="${GN_ARGS}"
83 echo "Building target: ${GN_TARGET_NAME}"
84 ninja -C ${OUTPUT_DIR} ${GN_TARGET_NAME}
85
86 # Strip debug symbols to reduce size.
87 if [[ ${build_type} = "static_only" ]]; then
88 strip -S ${OUTPUT_DIR}/obj/webrtc/sdk/lib${GN_TARGET_NAME}.a -o \
89 ${OUTPUT_DIR}/lib${GN_TARGET_NAME}.a
90 fi
91 }
92
93 function usage {
94 echo "WebRTC iOS FAT libraries build script."
95 echo "Each architecture is compiled separately before being merged together."
96 echo "By default, the library is created in out_ios_libs/. (Change with -o.)"
97 echo "The headers will be copied to out_ios_libs/include."
98 echo "Usage: $0 [-h] [-b build_type] [-c] [-o output_dir] [-r rev_num] [-e]"
99 echo " -h Print this help."
100 echo " -b The build type. Can be \"framework\" or \"static_only\"."
101 echo " Defaults to \"framework\"."
102 echo " -c Removes the previously generated build output, if any."
103 echo " -o Specifies a directory to output the build artifacts to."
104 echo " If specified together with -c, deletes the dir."
105 echo " -r Specifies a revision number to embed if building the framework."
106 echo " -e Compile with bitcode."
107 exit 0
108 }
109
110 SDK_OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs
111 SDK_LIB_NAME="librtc_sdk_objc.a"
112 SDK_FRAMEWORK_NAME="WebRTC.framework"
113
114 BUILD_FLAVOR="release"
115 BUILD_TYPE="framework"
116 ENABLED_ARCHITECTURES=("arm" "arm64" "x64")
117 IOS_DEPLOYMENT_TARGET="8.0"
118 LIBVPX_BUILD_VP9="false"
119 USE_BITCODE="false"
120 CUSTOM_GN_OPTS=""
121 WEBRTC_REVISION="0"
122
123 # Parse arguments.
124 while getopts "hb:co:r:e" opt; do
125 case "${opt}" in
126 h) usage;;
127 b) BUILD_TYPE="${OPTARG}";;
128 c) PERFORM_CLEAN=1;;
129 e) USE_BITCODE="true";;
130 o) SDK_OUTPUT_DIR="${OPTARG}";;
131 r) WEBRTC_REVISION="${OPTARG}";;
132 *)
133 usage
134 exit 1
135 ;;
136 esac
137 done
138
139 if [[ ${PERFORM_CLEAN} -ne 0 ]]; then
140 clean_artifacts ${SDK_OUTPUT_DIR}
141 exit 0
142 fi
143
144 # Build all architectures.
145 for arch in ${ENABLED_ARCHITECTURES[*]}; do
146 build_webrtc $arch ${BUILD_FLAVOR} ${BUILD_TYPE} \
147 ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${USE_BITCODE} \
148 ${CUSTOM_GN_OPTS}
149 done
150
151 # Ignoring x86 except for static libraries for now because of a GN build issue
152 # where the generated dynamic framework has the wrong architectures.
153
154 # Create FAT archive.
155 if [[ ${BUILD_TYPE} = "static_only" ]]; then
156 build_webrtc "x86" ${BUILD_FLAVOR} ${BUILD_TYPE} \
157 ${IOS_DEPLOYMENT_TARGET} ${LIBVPX_BUILD_VP9} ${USE_BITCODE} \
158 ${CUSTOM_GN_OPTS}
159
160 ARM_LIB_PATH=${SDK_OUTPUT_DIR}/arm_libs/${SDK_LIB_NAME}
161 ARM64_LIB_PATH=${SDK_OUTPUT_DIR}/arm64_libs/${SDK_LIB_NAME}
162 X64_LIB_PATH=${SDK_OUTPUT_DIR}/x64_libs/${SDK_LIB_NAME}
163 X86_LIB_PATH=${SDK_OUTPUT_DIR}/x86_libs/${SDK_LIB_NAME}
164
165 # Combine the slices.
166 lipo ${ARM_LIB_PATH} ${ARM64_LIB_PATH} ${X64_LIB_PATH} ${X86_LIB_PATH} \
167 -create -output ${SDK_OUTPUT_DIR}/${SDK_LIB_NAME}
168 elif [[ ${BUILD_TYPE} = "framework" ]]; then
169 ARM_LIB_PATH=${SDK_OUTPUT_DIR}/arm_libs
170 ARM64_LIB_PATH=${SDK_OUTPUT_DIR}/arm64_libs
171 X64_LIB_PATH=${SDK_OUTPUT_DIR}/x64_libs
172 X86_LIB_PATH=${SDK_OUTPUT_DIR}/x86_libs
173
174 # Combine the slices.
175 DYLIB_PATH="WebRTC.framework/WebRTC"
176 cp -R ${ARM64_LIB_PATH}/WebRTC.framework ${SDK_OUTPUT_DIR}
177 rm ${SDK_OUTPUT_DIR}/${DYLIB_PATH}
178 echo "Merging framework slices."
179 lipo ${ARM_LIB_PATH}/${DYLIB_PATH} \
180 ${ARM64_LIB_PATH}/${DYLIB_PATH} \
181 ${X64_LIB_PATH}/${DYLIB_PATH} \
182 -create -output ${SDK_OUTPUT_DIR}/${DYLIB_PATH}
183
184 # Merge the dSYM slices.
185 DSYM_PATH="WebRTC.dSYM/Contents/Resources/DWARF/WebRTC"
186 cp -R ${ARM64_LIB_PATH}/WebRTC.dSYM ${SDK_OUTPUT_DIR}
187 rm ${SDK_OUTPUT_DIR}/${DSYM_PATH}
188 echo "Merging dSYM slices."
189 lipo ${ARM_LIB_PATH}/${DSYM_PATH} \
190 ${ARM64_LIB_PATH}/${DSYM_PATH} \
191 ${X64_LIB_PATH}/${DSYM_PATH} \
192 -create -output ${SDK_OUTPUT_DIR}/${DSYM_PATH}
193
194 # Modify the version number.
195 # Format should be <Branch cut MXX>.<Hotfix #>.<Rev #>.
196 # e.g. 55.0.14986 means branch cut 55, no hotfixes, and revision number 14986.
197 INFOPLIST_PATH=${SDK_OUTPUT_DIR}/WebRTC.framework/Info.plist
198 MAJOR_MINOR=$(PlistBuddy -c "Print :CFBundleShortVersionString" \
199 ${INFOPLIST_PATH})
200 VERSION_NUMBER="${MAJOR_MINOR}.${WEBRTC_REVISION}"
201 echo "Substituting revision number: ${VERSION_NUMBER}"
202 PlistBuddy -c "Set :CFBundleVersion ${VERSION_NUMBER}" ${INFOPLIST_PATH}
203 plutil -convert binary1 ${INFOPLIST_PATH}
204 else
205 echo "BUILD_TYPE ${BUILD_TYPE} not supported."
206 exit 1
207 fi
208
209 echo "Done."
OLDNEW
« no previous file with comments | « tools-webrtc/ios/build_ios_libs.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698