Chromium Code Reviews| Index: webrtc/build/ios/build_ios_framework.sh |
| diff --git a/webrtc/build/ios/build_ios_framework.sh b/webrtc/build/ios/build_ios_framework.sh |
| index 35ec552798ce711f2f5f6b3c9912fddc283100ee..8e2d39e50dc6eca30276e6634a1a79fda9bd1985 100755 |
| --- a/webrtc/build/ios/build_ios_framework.sh |
| +++ b/webrtc/build/ios/build_ios_framework.sh |
| @@ -10,76 +10,143 @@ |
| # Generates dynamic FAT framework for iOS in out_ios_framework. |
| -# Check for Darwin. |
| -if [[ ! $(uname) = "Darwin" ]]; then |
| - echo "OS X required." >&2 |
| -fi |
| +# Exit on errors. |
| +set -e |
| -# Check for iOS library build script. |
| -SCRIPT_DIR=$(dirname $0) |
| +# Globals. |
| +SCRIPT_DIR=$(cd $(dirname $0) && pwd) |
| WEBRTC_BASE_DIR=${SCRIPT_DIR}/../../.. |
| -BUILD_WEBRTC_SCRIPT=${WEBRTC_BASE_DIR}/webrtc/build/ios/build_ios_libs.sh |
| -if [[ ! -x ${BUILD_WEBRTC_SCRIPT} ]]; then |
| - echo "Failed to find iOS library build script." >&2 |
| - exit 1 |
| -fi |
| -# Check for flatten iOS headers script. |
| -FLATTEN_HEADERS_SCRIPT=${WEBRTC_BASE_DIR}/webrtc/build/ios/flatten_ios_headers |
| -if [[ ! -x ${FLATTEN_HEADERS_SCRIPT} ]]; then |
| - echo "Failed to find flatten iOS headers script." >&2 |
| - exit 1 |
| -fi |
| +BUILD_WEBRTC_SCRIPT=${SCRIPT_DIR}/build_ios_libs.sh |
| +FLATTEN_HEADERS_SCRIPT=${SCRIPT_DIR}/flatten_ios_headers.py |
| +SDK_DIR=${SCRIPT_DIR}/SDK |
| +FRAMEWORK_PROJECT_DIR=${SDK_DIR}/Framework |
| +FRAMEWORK_PROJECT_PATH=${FRAMEWORK_PROJECT_DIR}/WebRTC.xcodeproj |
| -pushd ${WEBRTC_BASE_DIR} |
| -LIB_BASE_DIR=out_ios_libs |
| -FRAMEWORK_BASE_DIR=out_ios_framework |
| +function check_preconditions { |
| + # Check for Darwin. |
| + if [[ ! $(uname) = "Darwin" ]]; then |
| + echo "OS X required." >&2 |
| + exit 1 |
| + fi |
| + if [[ ! -x ${BUILD_WEBRTC_SCRIPT} ]]; then |
| + echo "Failed to find iOS library build script." >&2 |
| + exit 1 |
| + fi |
| + if [[ ! -x ${FLATTEN_HEADERS_SCRIPT} ]]; then |
| + echo "Failed to find flatten iOS headers script." >&2 |
| + exit 1 |
| + fi |
| + if [[ ! -x ${FRAMEWORK_PROJECT_PATH} ]]; then |
| + echo "Failed to find framework XCode project." >&2 |
| + exit 1 |
| + fi |
| +} |
| -# Build static libraries for iOS. |
| -${BUILD_WEBRTC_SCRIPT} |
| -if [ $? -ne 0 ]; then |
| - echo "Failed to build iOS static libraries." >&2 |
| - exit 1 |
| -fi |
| +function clean_artifacts { |
| + # Make XCode clean up after itself. |
| + xcodebuild -project ${FRAMEWORK_PROJECT_PATH} -scheme WebRTC \ |
| + -configuration Release clean |
| + xcodebuild -project ${FRAMEWORK_PROJECT_PATH} -scheme WebRTC \ |
| + -configuration Release clean \ |
| + -destination "platform=iOS Simulator,name=iPhone 6" |
| + # Remove remaining directory that XCode doesn't delete. |
| + XCODE_BUILD_DIR=${FRAMEWORK_PROJECT_DIR}/build |
| + if [ -d ${XCODE_BUILD_DIR} ]; then |
|
kjellander_webrtc
2016/04/15 04:59:41
Use double-brackets https://engdoc.corp.google.com
tkchin_webrtc
2016/04/16 00:34:18
Done.
|
| + rm -r ${XCODE_BUILD_DIR} |
| + fi |
| + |
| + # Remove the temporary framework header dir. |
| + if [ -d ${FRAMEWORK_INCLUDE_DIR} ]; then |
| + rm -r ${FRAMEWORK_INCLUDE_DIR} |
| + fi |
| + |
| + # Remove the generated framework. |
| + if [ -d ${FRAMEWORK_OUTPUT_DIR} ]; then |
| + rm -r ${FRAMEWORK_OUTPUT_DIR} |
| + fi |
| + |
| + # Let the other script clean up after itself. |
| + ${BUILD_WEBRTC_SCRIPT} -c |
| +} |
| + |
| +function usage { |
| + echo "WebRTC iOS Framework build script." |
| + echo "Builds a dynamic Framework for the WebRTC APIs." |
| + echo "Compiles various architectures and edits header paths as required." |
| + echo "Usage: $0 [-h] [-c]" |
| + echo " -h Print this help." |
| + echo " -c Removes generated build output." |
| + exit 0 |
| +} |
| + |
| +check_preconditions |
| + |
| +# Set the output directories for the various build artifacts. |
| +# For convenience we'll output some generated files in the same directory |
| +# as the one we used to output the generated statis libraries. |
| +LIB_OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_libs |
| +INCLUDE_OUTPUT_DIR=${LIB_OUTPUT_DIR}/include |
| +FRAMEWORK_INCLUDE_DIR=${LIB_OUTPUT_DIR}/framework_include |
| +FRAMEWORK_OUTPUT_DIR=${WEBRTC_BASE_DIR}/out_ios_framework |
| +PERFORM_CLEAN=0 |
| -# Flatten the directory structure for iOS headers. |
| -${FLATTEN_HEADERS_SCRIPT} ${LIB_BASE_DIR} ${FRAMEWORK_BASE_DIR} |
| -if [ $? -ne 0 ]; then |
| - echo "Failed to flatten iOS headers." >&2 |
| - exit 1 |
| +# Parse arguments. |
| +while getopts "hc" opt; do |
| + case "${opt}" in |
| + h) usage;; |
|
kjellander_webrtc
2016/04/15 04:59:41
indent according to https://engdoc.corp.google.com
tkchin_webrtc
2016/04/16 00:34:18
Done.
|
| + c) PERFORM_CLEAN=1;; |
| + esac |
| +done |
| + |
| +if [ ${PERFORM_CLEAN} -ne 0 ]; then |
| + clean_artifacts |
| + exit 0 |
| fi |
| +# Build static libraries for iOS. |
| +${BUILD_WEBRTC_SCRIPT} -o ${LIB_OUTPUT_DIR} |
| + |
| +# Flatten the directory structure for iOS headers generated from building the |
| +# static libraries. |
| +${FLATTEN_HEADERS_SCRIPT} ${INCLUDE_OUTPUT_DIR} ${FRAMEWORK_INCLUDE_DIR} |
| + |
| # Replace full paths for headers with framework paths. |
| SED_PATTERN=' |
| s/(\#import )\"webrtc\/api\/objc\/(.*)\"/\1<WebRTC\/\2>/g; |
| s/(\#import )\"webrtc\/base\/objc\/(.*)\"/\1<WebRTC\/\2>/g; |
| s/(\#include )\"webrtc\/base\/objc\/(.*)\"/\1<WebRTC\/\2>/g; |
| ' |
| -sed -E -i '' "$SED_PATTERN" ${FRAMEWORK_BASE_DIR}/include/*.h |
| +sed -E -i '' "$SED_PATTERN" ${FRAMEWORK_INCLUDE_DIR}/*.h |
| -SDK_DIR=webrtc/build/ios/SDK |
| -PROJECT_DIR=${SDK_DIR}/Framework |
| # Build the framework. |
| -pushd ${PROJECT_DIR} |
| -xcodebuild -project WebRTC.xcodeproj -scheme WebRTC -configuration Release \ |
| - build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO |
| -xcodebuild -project WebRTC.xcodeproj -scheme WebRTC -configuration Release \ |
| - build -destination 'platform=iOS Simulator,name=iPhone 6' |
| -popd |
| - |
| -# Copy podspec, framework, dSYM and LICENSE to FRAMEWORK_BASE_DIR |
| -DEVICE_BUILD_DIR=${PROJECT_DIR}/build/Release-iphoneos |
| -cp ${SDK_DIR}/WebRTC.podspec ${FRAMEWORK_BASE_DIR}/ |
| -cp -R ${DEVICE_BUILD_DIR}/WebRTC.framework ${FRAMEWORK_BASE_DIR}/ |
| -cp -R ${DEVICE_BUILD_DIR}/WebRTC.framework.dSYM ${FRAMEWORK_BASE_DIR}/ |
| -cp -R webrtc/LICENSE ${FRAMEWORK_BASE_DIR}/ |
| - |
| -# Combine multiple architectures |
| -SIMULATOR_BUILD_DIR=${PROJECT_DIR}/build/Release-iphonesimulator |
| +xcodebuild -project ${FRAMEWORK_PROJECT_PATH} -scheme WebRTC \ |
| + -configuration Release build \ |
| + CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO |
| +xcodebuild -project ${FRAMEWORK_PROJECT_PATH} -scheme WebRTC \ |
| + -configuration Release build \ |
| + -destination "platform=iOS Simulator,name=iPhone 6" |
| + |
| +# XCode should output the build artifacts to the following directories. |
| +DEVICE_BUILD_DIR=${FRAMEWORK_PROJECT_DIR}/build/Release-iphoneos |
| +SIMULATOR_BUILD_DIR=${FRAMEWORK_PROJECT_DIR}/build/Release-iphonesimulator |
| + |
| +# Copy podspec, framework, dSYM and LICENSE to FRAMEWORK_OUTPUT_DIR. |
| +mkdir -p ${FRAMEWORK_OUTPUT_DIR} |
| +cp ${SDK_DIR}/WebRTC.podspec ${FRAMEWORK_OUTPUT_DIR}/ |
| +cp -R ${DEVICE_BUILD_DIR}/WebRTC.framework ${FRAMEWORK_OUTPUT_DIR}/ |
| +cp -R ${DEVICE_BUILD_DIR}/WebRTC.framework.dSYM ${FRAMEWORK_OUTPUT_DIR}/ |
| +cp -R webrtc/LICENSE ${FRAMEWORK_OUTPUT_DIR}/ |
| + |
| +# Combine multiple architectures. |
| DYLIB_PATH=WebRTC.framework/WebRTC |
| DWARF_PATH=WebRTC.framework.dSYM/Contents/Resources/DWARF/WebRTC |
| -lipo ${FRAMEWORK_BASE_DIR}/${DYLIB_PATH} ${SIMULATOR_BUILD_DIR}/${DYLIB_PATH} \ |
| - -create -output ${FRAMEWORK_BASE_DIR}/${DYLIB_PATH} |
| -lipo ${FRAMEWORK_BASE_DIR}/${DWARF_PATH} ${SIMULATOR_BUILD_DIR}/${DWARF_PATH} \ |
| - -create -output ${FRAMEWORK_BASE_DIR}/${DWARF_PATH} |
| +lipo ${FRAMEWORK_OUTPUT_DIR}/${DYLIB_PATH} \ |
| + ${SIMULATOR_BUILD_DIR}/${DYLIB_PATH} \ |
| + -create -output ${FRAMEWORK_OUTPUT_DIR}/${DYLIB_PATH} |
| +lipo ${FRAMEWORK_OUTPUT_DIR}/${DWARF_PATH} \ |
| + ${SIMULATOR_BUILD_DIR}/${DWARF_PATH} \ |
| + -create -output ${FRAMEWORK_OUTPUT_DIR}/${DWARF_PATH} |
| + |
| + |
|
kjellander_webrtc
2016/04/15 04:59:41
Remove these ending blank lines
tkchin_webrtc
2016/04/16 00:34:18
Done.
|
| + |
| -popd |