From 9bf5cde91a9b1673dcfe22a41ca7df9c000f869b Mon Sep 17 00:00:00 2001 From: hjon Date: Fri, 19 Feb 2016 17:15:49 -0800 Subject: [PATCH] Update build_ios_libs.sh script to build new Objective-C API and gather header files. BUG= Review URL: https://codereview.webrtc.org/1673503002 Cr-Commit-Position: refs/heads/master@{#11694} --- talk/build/build_ios_libs.sh | 20 +++++++- talk/build/export_headers | 86 +++++++++++++++++++++++++++++++++++ talk/build/merge_ios_libs | 6 ++- talk/build/merge_ios_libs.gyp | 10 +++- talk/build/objc_app.gypi | 3 ++ 5 files changed, 120 insertions(+), 5 deletions(-) create mode 100755 talk/build/export_headers diff --git a/talk/build/build_ios_libs.sh b/talk/build/build_ios_libs.sh index 0ee112cc41..cc58ccca29 100755 --- a/talk/build/build_ios_libs.sh +++ b/talk/build/build_ios_libs.sh @@ -27,6 +27,9 @@ # Generates static FAT libraries for ios in out_ios_libs. +# Flag to build the new or legacy version of the API. +USE_LEGACY_API=1 + # Check for Darwin. if [[ ! $(uname) = "Darwin" ]]; then echo "OS/X required." >&2 @@ -45,6 +48,12 @@ if [[ ! -x ${GYP_WEBRTC_SCRIPT} ]]; then echo "Failed to find gyp generator." >&2 exit 1 fi +# Check for export headers script. +EXPORT_HEADERS_SCRIPT=${SCRIPT_DIR}/export_headers +if [[ ! -x ${EXPORT_HEADERS_SCRIPT} ]]; then + echo "Failed to find export headers script." >&2 + exit 1 +fi # Check for merge script. MERGE_SCRIPT=${SCRIPT_DIR}/merge_ios_libs if [[ ! -x ${MERGE_SCRIPT} ]]; then @@ -59,7 +68,6 @@ function build_webrtc { OUTPUT_DIR=$1 FLAVOR=$2 TARGET_ARCH=$3 - TARGET_SUBARCH=$4 if [[ ${TARGET_ARCH} = 'arm' || ${TARGET_ARCH} = 'arm64' ]]; then FLAVOR="${FLAVOR}-iphoneos" else @@ -69,7 +77,11 @@ function build_webrtc { export GYP_GENERATORS="ninja" export GYP_GENERATOR_FLAGS="output_dir=${OUTPUT_DIR}" webrtc/build/gyp_webrtc talk/build/merge_ios_libs.gyp - ninja -C ${OUTPUT_DIR}/${FLAVOR} libjingle_peerconnection_objc_no_op + if [[ ${USE_LEGACY_API} -eq 1 ]]; then + ninja -C ${OUTPUT_DIR}/${FLAVOR} libjingle_peerconnection_objc_no_op + else + ninja -C ${OUTPUT_DIR}/${FLAVOR} webrtc_api_objc_no_op + fi mkdir -p ${LIBRARY_BASE_DIR}/${TARGET_ARCH} mv ${OUTPUT_DIR}/${FLAVOR}/*.a ${LIBRARY_BASE_DIR}/${TARGET_ARCH} } @@ -82,5 +94,9 @@ build_webrtc "out_ios_x86_64" "Release" "x64" popd +# Export header files. +${EXPORT_HEADERS_SCRIPT} ${WEBRTC_BASE_DIR}/${LIBRARY_BASE_DIR} \ + ${USE_LEGACY_API} + # Merge the libraries together. ${MERGE_SCRIPT} ${WEBRTC_BASE_DIR}/${LIBRARY_BASE_DIR} diff --git a/talk/build/export_headers b/talk/build/export_headers new file mode 100755 index 0000000000..6d66f06619 --- /dev/null +++ b/talk/build/export_headers @@ -0,0 +1,86 @@ +#!/usr/bin/python + +# Copyright 2016 The WebRTC project authors. All Rights Reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +"""Script for exporting iOS header files.""" + +import errno +import optparse +import os +import re +import shutil +import sys + +LEGACY_HEADER_DIRS = ['talk/app/webrtc/objc/public', 'webrtc/base/objc/'] +HEADER_DIRS = ['webrtc/api/objc/', 'webrtc/base/objc/'] +# Individual header files that should also be exported. +LEGACY_HEADER_INCLUDES = [] +HEADER_INCLUDES = [] +# Individual header files that should not be exported. +LEGACY_HEADER_EXCLUDES = ['talk/app/webrtc/objc/public/RTCNSGLVideoView.h'] +HEADER_EXCLUDES = ['webrtc/api/objc/avfoundationvideocapturer.h', + 'webrtc/api/objc/RTCNSGLVideoView.h'] + +def ExportHeaders(include_base_dir, use_legacy_headers): + """Exports iOS header files. + + Creates an include directory and recreates the hierarchy for the header files + within the include directory. + + Args: + include_base_dir: directory where the include directory should be created + """ + + include_dir_name = 'include' + include_path = os.path.join(include_base_dir, include_dir_name) + + script_path = sys.path[0] + webrtc_base_path = os.path.join(script_path, '../..') + + header_dirs = HEADER_DIRS + include_headers = HEADER_INCLUDES + exclude_headers = HEADER_EXCLUDES + if use_legacy_headers: + header_dirs = LEGACY_HEADER_DIRS + include_headers = LEGACY_HEADER_INCLUDES + exclude_headers = LEGACY_HEADER_EXCLUDES + + for directory in header_dirs: + full_dir_path = os.path.join(webrtc_base_path, directory) + filenames = os.listdir(full_dir_path) + for filename in filenames: + if filename.endswith('.h') and not filename.endswith('+Private.h'): + include_headers.append(os.path.join(directory, filename)) + + for header in exclude_headers: + include_headers.remove(header) + + for header_path in include_headers: + output_dir = os.path.join(include_path, os.path.dirname(header_path)) + # Create hierarchy for the header file within the include directory. + try: + os.makedirs(output_dir) + except OSError as exc: + if exc.errno != errno.EEXIST: + raise exc + current_path = os.path.join(webrtc_base_path, header_path) + new_path = os.path.join(include_path, header_path) + shutil.copy(current_path, new_path) + +def Main(): + parser = optparse.OptionParser() + _, args = parser.parse_args() + if len(args) != 2: + parser.error('Error: Exactly 2 arguments required.') + include_base_dir = args[0] + use_legacy_headers = False if int(args[1]) == 0 else True + ExportHeaders(include_base_dir, use_legacy_headers) + +if __name__ == '__main__': + sys.exit(Main()) diff --git a/talk/build/merge_ios_libs b/talk/build/merge_ios_libs index ba1b21cdca..6d2698bc42 100755 --- a/talk/build/merge_ios_libs +++ b/talk/build/merge_ios_libs @@ -46,9 +46,11 @@ def MergeLibs(lib_base_dir): Returns: Exit code of libtool. """ - output_dir_name = 'fat' + include_dir_name = 'include' + output_dir_name = 'lib' archs = [arch for arch in os.listdir(lib_base_dir) - if arch[:1] != '.' and arch != output_dir_name] + if arch[:1] != '.' and arch != output_dir_name + and arch != include_dir_name] # For each arch, find (library name, libary path) for arch. We will merge # all libraries with the same name. libs = {} diff --git a/talk/build/merge_ios_libs.gyp b/talk/build/merge_ios_libs.gyp index 76313fb61a..83625ff7db 100644 --- a/talk/build/merge_ios_libs.gyp +++ b/talk/build/merge_ios_libs.gyp @@ -34,11 +34,19 @@ 'includes': [ 'objc_app.gypi' ], 'type': 'executable', 'dependencies': [ - '<(webrtc_root)/system_wrappers/system_wrappers.gyp:field_trial_default', '../app/webrtc/legacy_objc_api.gyp:libjingle_peerconnection_objc', ], 'sources': ['<(webrtc_root)/build/no_op.cc',], }, + { + 'target_name': 'webrtc_api_objc_no_op', + 'includes': [ 'objc_app.gypi' ], + 'type': 'executable', + 'dependencies': [ + '<(webrtc_root)/api/api.gyp:rtc_api_objc', + ], + 'sources': ['<(webrtc_root)/build/no_op.cc',], + }, ], }] ], diff --git a/talk/build/objc_app.gypi b/talk/build/objc_app.gypi index a4e0466433..4fbd5aeeaf 100644 --- a/talk/build/objc_app.gypi +++ b/talk/build/objc_app.gypi @@ -32,6 +32,9 @@ 'variables': { 'infoplist_file': './objc_app.plist', }, + 'dependencies': [ + '<(webrtc_root)/system_wrappers/system_wrappers.gyp:field_trial_default', + ], 'mac_bundle': 1, 'mac_bundle_resources': [ '<(infoplist_file)',