blob: d1be88b703c5286e9626a65a65d3d4dc324e061e [file] [log] [blame]
Primiano Tucci0825bc82017-09-28 18:50:23 +01001#!/usr/bin/env python
2# Copyright (C) 2017 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import argparse
17import os
18import subprocess
19import sys
20
21MAC_BUILD_CONFIGS = {
22 'mac_debug': ['is_clang=true', 'is_debug=true'],
23 'mac_release': ['is_clang=true', 'is_debug=false'],
24 'mac_asan': ['is_clang=true', 'is_debug=false', 'is_asan=true'],
25 'mac_tsan': ['is_clang=true', 'is_debug=false', 'is_tsan=true'],
26 'mac_ubsan': ['is_clang=true', 'is_debug=false', 'is_ubsan=true'],
27}
28
29ANDROID_BUILD_CONFIGS = {
30 'android_debug': ['target_os="android"', 'is_clang=true', 'is_debug=true'],
31 'android_release': ['target_os="android"', 'is_clang=true', 'is_debug=false'],
32 'android_asan': ['target_os="android"', 'is_clang=true', 'is_debug=false', 'is_asan=true'],
33 'android_lsan': ['target_os="android"', 'is_clang=true', 'is_debug=false', 'is_lsan=true'],
34}
35
36ANDROID_ARCHS = [ 'arm', 'arm64' ]
37
38LINUX_BUILD_CONFIGS = {
39 'linux_gcc_debug': ['is_clang=false', 'is_debug=true'],
40 'linux_gcc_release': ['is_clang=false', 'is_debug=false'],
41 'linux_clang_debug': ['is_clang=true', 'is_debug=true'],
42 'linux_clang_release': ['is_clang=true', 'is_debug=false'],
43 'linux_asan': ['is_clang=true', 'is_debug=false', 'is_asan=true'],
44 'linux_lsan': ['is_clang=true', 'is_debug=false', 'is_lsan=true'],
45 'linux_msan': ['is_clang=true', 'is_debug=false', 'is_msan=true'],
46 'linux_tsan': ['is_clang=true', 'is_debug=false', 'is_tsan=true'],
47 'linux_ubsan': ['is_clang=true', 'is_debug=false', 'is_ubsan=true'],
Florian Mayerbfc8e602018-01-30 11:35:11 +000048 'linux_fuzzer': ['is_clang=true', 'is_debug=false', 'use_libfuzzer=true',
Florian Mayer2198b072018-02-12 14:01:22 +000049 'is_asan=true'],
Primiano Tucci0825bc82017-09-28 18:50:23 +010050}
51
52ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
53
54def main():
55 parser = argparse.ArgumentParser()
56 parser.add_argument('--host-only', action='store_true', default=False)
57 parser.add_argument('--build', default=None)
58 args = parser.parse_args()
59
60 configs = {}
61 if not args.host_only:
62 for config_name, gn_args in ANDROID_BUILD_CONFIGS.iteritems():
63 for arch in ANDROID_ARCHS:
64 full_config_name = '%s_%s' % (config_name, arch)
65 configs[full_config_name] = gn_args + ['target_cpu="%s"' % arch]
66
67 if sys.platform == 'linux2':
68 configs.update(LINUX_BUILD_CONFIGS)
69 elif sys.platform == 'darwin':
70 configs.update(MAC_BUILD_CONFIGS)
71 else:
72 assert(False)
73
74 out_base_dir = os.path.join(ROOT_DIR, 'out')
75 if not os.path.isdir(out_base_dir):
76 os.mkdir(out_base_dir)
77
Primiano Tucci7a40e4d2017-12-06 09:51:09 +000078 gn = os.path.join(ROOT_DIR, 'tools', 'gn')
Primiano Tucci0825bc82017-09-28 18:50:23 +010079
80 for config_name, gn_args in configs.iteritems():
81 print '\n\033[32mBuilding %-20s[%s]\033[0m' % (config_name, ','.join(gn_args))
82 out_dir = os.path.join(ROOT_DIR, 'out', config_name)
83 if not os.path.isdir(out_dir):
84 os.mkdir(out_dir)
85 gn_cmd = [gn, 'args', out_dir, '--args=%s' % (' '.join(gn_args)), '--check']
86 print ' '.join(gn_cmd)
87 subprocess.check_call(gn_cmd, cwd=ROOT_DIR, env={'EDITOR':'true'})
88 if args.build:
Primiano Tucci7a40e4d2017-12-06 09:51:09 +000089 ninja = os.path.join(ROOT_DIR, 'tools', 'ninja')
Primiano Tucci0825bc82017-09-28 18:50:23 +010090 ninja_cmd = [ninja, '-C', '.', args.build]
91 subprocess.check_call(ninja_cmd, cwd=out_dir)
92
93
94if __name__ == '__main__':
95 sys.exit(main())