blob: aa99bc486bc45cb1f992e2a60f3b1694ddd56c93 [file] [log] [blame]
Primiano Tucci34bc5592021-02-19 17:53:36 +01001#!/usr/bin/env python3
Sami Kyostilaf15f3f62019-08-09 11:00:29 +01002# 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 Clarkson9a5dfa52019-10-03 09:54:04 +010016from __future__ import print_function
17
Sami Kyostilaf15f3f62019-08-09 11:00:29 +010018import os
Primiano Tucci829d9d62019-12-06 15:40:54 +000019import shutil
Sami Kyostilaf15f3f62019-08-09 11:00:29 +010020import subprocess
Lalit Maganti54afee62020-07-16 19:28:04 +010021import sys
Sami Kyostilaf15f3f62019-08-09 11:00:29 +010022
Matthew Clarkson9a5dfa52019-10-03 09:54:04 +010023from compat import quote
Primiano Tucci829d9d62019-12-06 15:40:54 +000024from platform import system
Matthew Clarkson9a5dfa52019-10-03 09:54:04 +010025
Matthew Clarksona990d952019-10-08 14:52:12 +010026GN_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 Kyostilaf15f3f62019-08-09 11:00:29 +010035ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
Primiano Tucci829d9d62019-12-06 15:40:54 +000036OUT_DIR = os.path.join('out', 'amalgamated')
37GEN_AMALGAMATED = os.path.join('tools', 'gen_amalgamated')
Sami Kyostilaf15f3f62019-08-09 11:00:29 +010038
39
40def call(cmd, *args):
Primiano Tucci829d9d62019-12-06 15:40:54 +000041 command = [cmd] + list(args)
Matthew Clarkson9a5dfa52019-10-03 09:54:04 +010042 print('Running:', ' '.join(quote(c) for c in command))
Sami Kyostilaf15f3f62019-08-09 11:00:29 +010043 try:
Matthew Clarksona990d952019-10-08 14:52:12 +010044 return subprocess.check_output(command, cwd=ROOT_DIR).decode()
Sami Kyostilaf15f3f62019-08-09 11:00:29 +010045 except subprocess.CalledProcessError as e:
Alexander Timin4e669c82021-02-05 13:48:29 +000046 assert False, 'Command: %s failed: %s' % (' '.join(command), e)
Sami Kyostilaf15f3f62019-08-09 11:00:29 +010047
48
49def check_amalgamated_output():
Primiano Tucci829d9d62019-12-06 15:40:54 +000050 call(GEN_AMALGAMATED, '--quiet')
51
52
53def 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 Maganti54afee62020-07-16 19:28:04 +010062
63 if sys.platform.startswith('linux'):
64 llvm_script = os.path.join(ROOT_DIR, 'gn', 'standalone', 'toolchain',
65 'linux_find_llvm.py')
Primiano Tucci34bc5592021-02-19 17:53:36 +010066 cxx = subprocess.check_output([llvm_script]).splitlines()[2].decode()
Lalit Maganti54afee62020-07-16 19:28:04 +010067 else:
68 cxx = 'clang++'
69 call(cxx, *args)
Sami Kyostilaf15f3f62019-08-09 11:00:29 +010070
71
72def check_amalgamated_dependencies():
73 os_deps = {}
74 for os_name in ['android', 'linux', 'mac']:
Matthew Clarksona990d952019-10-08 14:52:12 +010075 gn_args = (' target_os="%s"' % os_name) + GN_ARGS
Primiano Tucci829d9d62019-12-06 15:40:54 +000076 os_deps[os_name] = call(GEN_AMALGAMATED, '--gn_args', gn_args, '--out',
77 OUT_DIR, '--dump-deps', '--quiet').split('\n')
Sami Kyostilaf15f3f62019-08-09 11:00:29 +010078 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
86def main():
Sami Kyostilaf15f3f62019-08-09 11:00:29 +010087 check_amalgamated_dependencies()
Primiano Tucci829d9d62019-12-06 15:40:54 +000088 check_amalgamated_output()
89 check_amalgamated_build()
90 shutil.rmtree(OUT_DIR)
Sami Kyostilaf15f3f62019-08-09 11:00:29 +010091
92
93if __name__ == '__main__':
94 exit(main())