OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 3 # Copyright (c) 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 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 def _ParseArgs(): | 47 def _ParseArgs(): |
48 parser = argparse.ArgumentParser(description='libwebrtc.aar generator.') | 48 parser = argparse.ArgumentParser(description='libwebrtc.aar generator.') |
49 parser.add_argument('--output', default='libwebrtc.aar', | 49 parser.add_argument('--output', default='libwebrtc.aar', |
50 help='Output file of the script.') | 50 help='Output file of the script.') |
51 parser.add_argument('--arch', action='append', default=[], | 51 parser.add_argument('--arch', action='append', default=[], |
52 help='Architectures to build. Defaults to ' + str(DEFAULT_ARCHS)) | 52 help='Architectures to build. Defaults to ' + str(DEFAULT_ARCHS)) |
53 parser.add_argument('--use-goma', action='store_true', default=False, | 53 parser.add_argument('--use-goma', action='store_true', default=False, |
54 help='Use goma.') | 54 help='Use goma.') |
55 parser.add_argument('--verbose', action='store_true', default=False, | 55 parser.add_argument('--verbose', action='store_true', default=False, |
56 help='Debug logging.') | 56 help='Debug logging.') |
57 parser.add_argument('--extra-gn-args', action='append', default=[], | |
sakal
2017/02/06 09:24:11
I would prefer this be a regular string parameter.
kjellander_webrtc
2017/02/06 14:44:12
Since I have action='append' it is possible to pas
sakal
2017/02/06 14:52:57
I find passing arguments one by one a little cumbe
| |
58 help='Additional GN args to be used during Ninja generation.') | |
57 return parser.parse_args() | 59 return parser.parse_args() |
58 | 60 |
59 | 61 |
60 def _RunGN(args): | 62 def _RunGN(args): |
61 cmd = ['gn'] | 63 cmd = ['gn'] |
62 cmd.extend(args) | 64 cmd.extend(args) |
63 logging.debug('Running: %r', cmd) | 65 logging.debug('Running: %r', cmd) |
64 subprocess.check_call(cmd) | 66 subprocess.check_call(cmd) |
65 | 67 |
66 | 68 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 if arch == 'armeabi': | 103 if arch == 'armeabi': |
102 return 6 | 104 return 6 |
103 elif arch == 'armeabi-v7a': | 105 elif arch == 'armeabi-v7a': |
104 return 7 | 106 return 7 |
105 elif arch == 'x86': | 107 elif arch == 'x86': |
106 return None | 108 return None |
107 else: | 109 else: |
108 raise Exception('Unknown arch: ' + arch) | 110 raise Exception('Unknown arch: ' + arch) |
109 | 111 |
110 | 112 |
111 def Build(tmp_dir, arch, use_goma): | 113 def Build(tmp_dir, arch, use_goma, extra_gn_args): |
112 """Generates target architecture using GN and builds it using ninja.""" | 114 """Generates target architecture using GN and builds it using ninja.""" |
113 logging.info('Building: %s', arch) | 115 logging.info('Building: %s', arch) |
114 output_directory = _GetOutputDirectory(tmp_dir, arch) | 116 output_directory = _GetOutputDirectory(tmp_dir, arch) |
115 gn_args = { | 117 gn_args = { |
116 'target_os': 'android', | 118 'target_os': 'android', |
117 'is_debug': False, | 119 'is_debug': False, |
118 'is_component_build': False, | 120 'is_component_build': False, |
119 'target_cpu': _GetTargetCpu(arch), | 121 'target_cpu': _GetTargetCpu(arch), |
120 'use_goma': use_goma | 122 'use_goma': use_goma |
121 } | 123 } |
122 arm_version = _GetArmVersion(arch) | 124 arm_version = _GetArmVersion(arch) |
123 if arm_version: | 125 if arm_version: |
124 gn_args['arm_version'] = arm_version | 126 gn_args['arm_version'] = arm_version |
125 gn_args_str = '--args=' + ' '.join([ | 127 gn_args_str = '--args=' + ' '.join([ |
126 k + '=' + _EncodeForGN(v) for k, v in gn_args.items()]) | 128 k + '=' + _EncodeForGN(v) for k, v in gn_args.items()] + extra_gn_args) |
sakal
2017/02/06 09:24:11
I would prefer a system where you can override exi
kjellander_webrtc
2017/02/06 14:44:12
argparse doesn't support dicts, so I think it's a
sakal
2017/02/06 14:52:57
Yeah, you would have to manually parse the list in
| |
127 | 129 |
128 _RunGN(['gen', output_directory, gn_args_str]) | 130 _RunGN(['gen', output_directory, gn_args_str]) |
129 | 131 |
130 ninja_args = TARGETS | 132 ninja_args = TARGETS |
131 if use_goma: | 133 if use_goma: |
132 ninja_args.extend(['-j', '1024']) | 134 ninja_args.extend(['-j', '1024']) |
133 _RunNinja(output_directory, ninja_args) | 135 _RunNinja(output_directory, ninja_args) |
134 | 136 |
135 | 137 |
136 def CollectCommon(aar_file, tmp_dir, arch): | 138 def CollectCommon(aar_file, tmp_dir, arch): |
(...skipping 18 matching lines...) Expand all Loading... | |
155 def main(): | 157 def main(): |
156 args = _ParseArgs() | 158 args = _ParseArgs() |
157 if not args.arch: | 159 if not args.arch: |
158 args.arch = DEFAULT_ARCHS | 160 args.arch = DEFAULT_ARCHS |
159 | 161 |
160 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) | 162 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) |
161 | 163 |
162 tmp_dir = tempfile.mkdtemp() | 164 tmp_dir = tempfile.mkdtemp() |
163 | 165 |
164 for arch in args.arch: | 166 for arch in args.arch: |
165 Build(tmp_dir, arch, args.use_goma) | 167 Build(tmp_dir, arch, args.use_goma, args.extra_gn_args) |
166 | 168 |
167 with zipfile.ZipFile(args.output, 'w') as aar_file: | 169 with zipfile.ZipFile(args.output, 'w') as aar_file: |
168 # Architecture doesn't matter here, arbitrarily using the first one. | 170 # Architecture doesn't matter here, arbitrarily using the first one. |
169 CollectCommon(aar_file, tmp_dir, args.arch[0]) | 171 CollectCommon(aar_file, tmp_dir, args.arch[0]) |
170 for arch in args.arch: | 172 for arch in args.arch: |
171 Collect(aar_file, tmp_dir, arch) | 173 Collect(aar_file, tmp_dir, arch) |
172 | 174 |
173 shutil.rmtree(tmp_dir, True) | 175 shutil.rmtree(tmp_dir, True) |
174 | 176 |
175 | 177 |
176 if __name__ == '__main__': | 178 if __name__ == '__main__': |
177 sys.exit(main()) | 179 sys.exit(main()) |
OLD | NEW |