Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 1 | #!/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 | |
| 16 | import argparse |
| 17 | import os |
| 18 | import subprocess |
| 19 | import sys |
| 20 | |
| 21 | MAC_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 | |
| 29 | ANDROID_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 | |
| 36 | ANDROID_ARCHS = [ 'arm', 'arm64' ] |
| 37 | |
| 38 | LINUX_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 Mayer | bfc8e60 | 2018-01-30 11:35:11 +0000 | [diff] [blame] | 48 | 'linux_fuzzer': ['is_clang=true', 'is_debug=false', 'use_libfuzzer=true', |
Florian Mayer | 2198b07 | 2018-02-12 14:01:22 +0000 | [diff] [blame] | 49 | 'is_asan=true'], |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 53 | |
| 54 | def 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 Tucci | 7a40e4d | 2017-12-06 09:51:09 +0000 | [diff] [blame] | 78 | gn = os.path.join(ROOT_DIR, 'tools', 'gn') |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 79 | |
| 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 Tucci | 7a40e4d | 2017-12-06 09:51:09 +0000 | [diff] [blame] | 89 | ninja = os.path.join(ROOT_DIR, 'tools', 'ninja') |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 90 | ninja_cmd = [ninja, '-C', '.', args.build] |
| 91 | subprocess.check_call(ninja_cmd, cwd=out_dir) |
| 92 | |
| 93 | |
| 94 | if __name__ == '__main__': |
| 95 | sys.exit(main()) |