hjon | 9bf5cde | 2016-02-19 17:15:49 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | # Copyright 2016 The WebRTC project authors. All Rights Reserved. |
| 4 | # |
| 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 |
| 7 | # tree. An additional intellectual property rights grant can be found |
| 8 | # in the file PATENTS. All contributing project authors may |
| 9 | # be found in the AUTHORS file in the root of the source tree. |
| 10 | |
| 11 | """Script for exporting iOS header files.""" |
| 12 | |
| 13 | import errno |
hjon | 9bf5cde | 2016-02-19 17:15:49 -0800 | [diff] [blame] | 14 | import sys |
| 15 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 16 | import argparse |
| 17 | import os |
| 18 | import shutil |
| 19 | |
hjon | 9bf5cde | 2016-02-19 17:15:49 -0800 | [diff] [blame] | 20 | LEGACY_HEADER_DIRS = ['talk/app/webrtc/objc/public', 'webrtc/base/objc/'] |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 21 | HEADER_DIRS = ['webrtc/api/objc/', 'webrtc/base/objc/', |
| 22 | 'webrtc/modules/audio_device/ios/objc'] |
hjon | 9bf5cde | 2016-02-19 17:15:49 -0800 | [diff] [blame] | 23 | # Individual header files that should also be exported. |
| 24 | LEGACY_HEADER_INCLUDES = [] |
| 25 | HEADER_INCLUDES = [] |
| 26 | # Individual header files that should not be exported. |
| 27 | LEGACY_HEADER_EXCLUDES = ['talk/app/webrtc/objc/public/RTCNSGLVideoView.h'] |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 28 | HEADER_EXCLUDES = [ |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 29 | 'webrtc/api/objc/avfoundationvideocapturer.h', |
| 30 | 'webrtc/api/objc/RTCNSGLVideoView.h', |
| 31 | 'webrtc/api/objc/RTCVideoRendererAdapter.h', |
| 32 | 'webrtc/base/objc/NSString+StdString.h', |
| 33 | 'webrtc/base/objc/RTCUIApplication.h', |
| 34 | 'webrtc/modules/audio_device/ios/objc/RTCAudioSessionDelegateAdapter.h', |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 35 | ] |
hjon | 9bf5cde | 2016-02-19 17:15:49 -0800 | [diff] [blame] | 36 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 37 | |
hjon | 9bf5cde | 2016-02-19 17:15:49 -0800 | [diff] [blame] | 38 | def ExportHeaders(include_base_dir, use_legacy_headers): |
| 39 | """Exports iOS header files. |
| 40 | |
| 41 | Creates an include directory and recreates the hierarchy for the header files |
| 42 | within the include directory. |
| 43 | |
| 44 | Args: |
| 45 | include_base_dir: directory where the include directory should be created |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 46 | use_legacy_headers: whether or not to export the old headers |
hjon | 9bf5cde | 2016-02-19 17:15:49 -0800 | [diff] [blame] | 47 | """ |
| 48 | |
| 49 | include_dir_name = 'include' |
| 50 | include_path = os.path.join(include_base_dir, include_dir_name) |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 51 | # Remove existing directory first in case files change. |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 52 | if os.path.exists(include_path): |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 53 | shutil.rmtree(include_path) |
hjon | 9bf5cde | 2016-02-19 17:15:49 -0800 | [diff] [blame] | 54 | |
| 55 | script_path = sys.path[0] |
hjon | bc73fe1 | 2016-03-21 11:38:26 -0700 | [diff] [blame] | 56 | webrtc_base_path = os.path.join(script_path, '../../..') |
hjon | 9bf5cde | 2016-02-19 17:15:49 -0800 | [diff] [blame] | 57 | |
| 58 | header_dirs = HEADER_DIRS |
| 59 | include_headers = HEADER_INCLUDES |
| 60 | exclude_headers = HEADER_EXCLUDES |
| 61 | if use_legacy_headers: |
| 62 | header_dirs = LEGACY_HEADER_DIRS |
| 63 | include_headers = LEGACY_HEADER_INCLUDES |
| 64 | exclude_headers = LEGACY_HEADER_EXCLUDES |
| 65 | |
| 66 | for directory in header_dirs: |
| 67 | full_dir_path = os.path.join(webrtc_base_path, directory) |
| 68 | filenames = os.listdir(full_dir_path) |
| 69 | for filename in filenames: |
| 70 | if filename.endswith('.h') and not filename.endswith('+Private.h'): |
| 71 | include_headers.append(os.path.join(directory, filename)) |
| 72 | |
| 73 | for header in exclude_headers: |
| 74 | include_headers.remove(header) |
| 75 | |
| 76 | for header_path in include_headers: |
| 77 | output_dir = os.path.join(include_path, os.path.dirname(header_path)) |
| 78 | # Create hierarchy for the header file within the include directory. |
| 79 | try: |
| 80 | os.makedirs(output_dir) |
| 81 | except OSError as exc: |
| 82 | if exc.errno != errno.EEXIST: |
| 83 | raise exc |
| 84 | current_path = os.path.join(webrtc_base_path, header_path) |
| 85 | new_path = os.path.join(include_path, header_path) |
| 86 | shutil.copy(current_path, new_path) |
| 87 | |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 88 | |
hjon | 9bf5cde | 2016-02-19 17:15:49 -0800 | [diff] [blame] | 89 | def Main(): |
tkchin | 5209d67 | 2016-04-16 12:06:33 -0700 | [diff] [blame^] | 90 | parser_description = 'Export WebRTC ObjC API headers.' |
| 91 | parser = argparse.ArgumentParser(description=parser_description) |
| 92 | parser.add_argument('output_dir', |
| 93 | help='Output directory to write headers to.', |
| 94 | type=str) |
| 95 | parser.add_argument('use_legacy_headers', |
| 96 | help='Reads the old headers instead of the current ones.', |
| 97 | type=int) |
| 98 | args = parser.parse_args() |
| 99 | use_legacy_headers = args.use_legacy_headers != 0 |
| 100 | output_dir = args.output_dir |
| 101 | ExportHeaders(output_dir, use_legacy_headers) |
| 102 | |
hjon | 9bf5cde | 2016-02-19 17:15:49 -0800 | [diff] [blame] | 103 | |
| 104 | if __name__ == '__main__': |
| 105 | sys.exit(Main()) |