blob: 6808e67e14772429d27738d3a11f6a9176d64e37 [file] [log] [blame]
hjon9bf5cde2016-02-19 17:15:49 -08001#!/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
13import errno
14import optparse
15import os
16import re
17import shutil
18import sys
19
20LEGACY_HEADER_DIRS = ['talk/app/webrtc/objc/public', 'webrtc/base/objc/']
21HEADER_DIRS = ['webrtc/api/objc/', 'webrtc/base/objc/']
22# Individual header files that should also be exported.
23LEGACY_HEADER_INCLUDES = []
24HEADER_INCLUDES = []
25# Individual header files that should not be exported.
26LEGACY_HEADER_EXCLUDES = ['talk/app/webrtc/objc/public/RTCNSGLVideoView.h']
27HEADER_EXCLUDES = ['webrtc/api/objc/avfoundationvideocapturer.h',
Jon Hjelle3a2f7e02016-03-25 14:48:14 -070028 'webrtc/api/objc/RTCNSGLVideoView.h',
29 'webrtc/base/objc/NSString+StdString.h',
30 'webrtc/base/objc/RTCUIApplication.h',]
hjon9bf5cde2016-02-19 17:15:49 -080031
32def ExportHeaders(include_base_dir, use_legacy_headers):
33 """Exports iOS header files.
34
35 Creates an include directory and recreates the hierarchy for the header files
36 within the include directory.
37
38 Args:
39 include_base_dir: directory where the include directory should be created
40 """
41
42 include_dir_name = 'include'
43 include_path = os.path.join(include_base_dir, include_dir_name)
44
45 script_path = sys.path[0]
hjonbc73fe12016-03-21 11:38:26 -070046 webrtc_base_path = os.path.join(script_path, '../../..')
hjon9bf5cde2016-02-19 17:15:49 -080047
48 header_dirs = HEADER_DIRS
49 include_headers = HEADER_INCLUDES
50 exclude_headers = HEADER_EXCLUDES
51 if use_legacy_headers:
52 header_dirs = LEGACY_HEADER_DIRS
53 include_headers = LEGACY_HEADER_INCLUDES
54 exclude_headers = LEGACY_HEADER_EXCLUDES
55
56 for directory in header_dirs:
57 full_dir_path = os.path.join(webrtc_base_path, directory)
58 filenames = os.listdir(full_dir_path)
59 for filename in filenames:
60 if filename.endswith('.h') and not filename.endswith('+Private.h'):
61 include_headers.append(os.path.join(directory, filename))
62
63 for header in exclude_headers:
64 include_headers.remove(header)
65
66 for header_path in include_headers:
67 output_dir = os.path.join(include_path, os.path.dirname(header_path))
68 # Create hierarchy for the header file within the include directory.
69 try:
70 os.makedirs(output_dir)
71 except OSError as exc:
72 if exc.errno != errno.EEXIST:
73 raise exc
74 current_path = os.path.join(webrtc_base_path, header_path)
75 new_path = os.path.join(include_path, header_path)
76 shutil.copy(current_path, new_path)
77
78def Main():
79 parser = optparse.OptionParser()
80 _, args = parser.parse_args()
81 if len(args) != 2:
82 parser.error('Error: Exactly 2 arguments required.')
83 include_base_dir = args[0]
84 use_legacy_headers = False if int(args[1]) == 0 else True
85 ExportHeaders(include_base_dir, use_legacy_headers)
86
87if __name__ == '__main__':
88 sys.exit(Main())