Primiano Tucci | 34bc559 | 2021-02-19 17:53:36 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 2 | # Copyright (C) 2019 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 | |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 16 | from __future__ import print_function |
| 17 | |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 18 | import os |
Primiano Tucci | 829d9d6 | 2019-12-06 15:40:54 +0000 | [diff] [blame] | 19 | import shutil |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 20 | import subprocess |
Lalit Maganti | 54afee6 | 2020-07-16 19:28:04 +0100 | [diff] [blame] | 21 | import sys |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 22 | |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 23 | from compat import quote |
Primiano Tucci | 829d9d6 | 2019-12-06 15:40:54 +0000 | [diff] [blame] | 24 | from platform import system |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 25 | |
Matthew Clarkson | a990d95 | 2019-10-08 14:52:12 +0100 | [diff] [blame] | 26 | GN_ARGS = ' '.join( |
| 27 | quote(s) for s in ( |
| 28 | 'is_debug=false', |
| 29 | 'is_perfetto_build_generator=true', |
| 30 | 'is_perfetto_embedder=true', |
| 31 | 'use_custom_libcxx=false', |
| 32 | 'enable_perfetto_ipc=true', |
| 33 | )) |
| 34 | |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 35 | ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
Primiano Tucci | 829d9d6 | 2019-12-06 15:40:54 +0000 | [diff] [blame] | 36 | OUT_DIR = os.path.join('out', 'amalgamated') |
| 37 | GEN_AMALGAMATED = os.path.join('tools', 'gen_amalgamated') |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 38 | |
| 39 | |
| 40 | def call(cmd, *args): |
Primiano Tucci | 829d9d6 | 2019-12-06 15:40:54 +0000 | [diff] [blame] | 41 | command = [cmd] + list(args) |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 42 | print('Running:', ' '.join(quote(c) for c in command)) |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 43 | try: |
Matthew Clarkson | a990d95 | 2019-10-08 14:52:12 +0100 | [diff] [blame] | 44 | return subprocess.check_output(command, cwd=ROOT_DIR).decode() |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 45 | except subprocess.CalledProcessError as e: |
Alexander Timin | 4e669c8 | 2021-02-05 13:48:29 +0000 | [diff] [blame] | 46 | assert False, 'Command: %s failed: %s' % (' '.join(command), e) |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 47 | |
| 48 | |
| 49 | def check_amalgamated_output(): |
Primiano Tucci | 829d9d6 | 2019-12-06 15:40:54 +0000 | [diff] [blame] | 50 | call(GEN_AMALGAMATED, '--quiet') |
| 51 | |
| 52 | |
| 53 | def check_amalgamated_build(): |
| 54 | args = [ |
| 55 | '-std=c++11', '-Werror', '-Wall', '-Wextra', |
| 56 | '-DPERFETTO_AMALGAMATED_SDK_TEST', '-I' + OUT_DIR, |
| 57 | OUT_DIR + '/perfetto.cc', 'test/client_api_example.cc', '-o', |
| 58 | OUT_DIR + '/test' |
| 59 | ] |
| 60 | if system().lower() == 'linux': |
| 61 | args += ['-lpthread', '-lrt'] |
Lalit Maganti | 54afee6 | 2020-07-16 19:28:04 +0100 | [diff] [blame] | 62 | |
| 63 | if sys.platform.startswith('linux'): |
| 64 | llvm_script = os.path.join(ROOT_DIR, 'gn', 'standalone', 'toolchain', |
| 65 | 'linux_find_llvm.py') |
Primiano Tucci | 34bc559 | 2021-02-19 17:53:36 +0100 | [diff] [blame] | 66 | cxx = subprocess.check_output([llvm_script]).splitlines()[2].decode() |
Lalit Maganti | 54afee6 | 2020-07-16 19:28:04 +0100 | [diff] [blame] | 67 | else: |
| 68 | cxx = 'clang++' |
| 69 | call(cxx, *args) |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 70 | |
| 71 | |
| 72 | def check_amalgamated_dependencies(): |
| 73 | os_deps = {} |
| 74 | for os_name in ['android', 'linux', 'mac']: |
Matthew Clarkson | a990d95 | 2019-10-08 14:52:12 +0100 | [diff] [blame] | 75 | gn_args = (' target_os="%s"' % os_name) + GN_ARGS |
Primiano Tucci | 829d9d6 | 2019-12-06 15:40:54 +0000 | [diff] [blame] | 76 | os_deps[os_name] = call(GEN_AMALGAMATED, '--gn_args', gn_args, '--out', |
| 77 | OUT_DIR, '--dump-deps', '--quiet').split('\n') |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 78 | for os_name, deps in os_deps.items(): |
| 79 | for dep in deps: |
| 80 | for other_os, other_deps in os_deps.items(): |
| 81 | if not dep in other_deps: |
| 82 | raise AssertionError('Discrepancy in amalgamated build dependencies: ' |
| 83 | '%s is missing on %s.' % (dep, other_os)) |
| 84 | |
| 85 | |
| 86 | def main(): |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 87 | check_amalgamated_dependencies() |
Primiano Tucci | 829d9d6 | 2019-12-06 15:40:54 +0000 | [diff] [blame] | 88 | check_amalgamated_output() |
| 89 | check_amalgamated_build() |
| 90 | shutil.rmtree(OUT_DIR) |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 91 | |
| 92 | |
| 93 | if __name__ == '__main__': |
| 94 | exit(main()) |