• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
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
16from __future__ import print_function
17
18import os
19import shutil
20import subprocess
21
22from compat import quote
23from platform import system
24
25GN_ARGS = ' '.join(
26    quote(s) for s in (
27        'is_debug=false',
28        'is_perfetto_build_generator=true',
29        'is_perfetto_embedder=true',
30        'use_custom_libcxx=false',
31        'enable_perfetto_ipc=true',
32    ))
33
34ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
35OUT_DIR = os.path.join('out', 'amalgamated')
36GEN_AMALGAMATED = os.path.join('tools', 'gen_amalgamated')
37
38
39def call(cmd, *args):
40  command = [cmd] + list(args)
41  print('Running:', ' '.join(quote(c) for c in command))
42  try:
43    return subprocess.check_output(command, cwd=ROOT_DIR).decode()
44  except subprocess.CalledProcessError as e:
45    assert False, 'Command: %s failed: %s'.format(' '.join(command))
46
47
48def check_amalgamated_output():
49  call(GEN_AMALGAMATED, '--quiet')
50
51
52def check_amalgamated_build():
53  args = [
54      '-std=c++11', '-Werror', '-Wall', '-Wextra',
55      '-DPERFETTO_AMALGAMATED_SDK_TEST', '-I' + OUT_DIR,
56      OUT_DIR + '/perfetto.cc', 'test/client_api_example.cc', '-o',
57      OUT_DIR + '/test'
58  ]
59  if system().lower() == 'linux':
60    args += ['-lpthread', '-lrt']
61  call('clang++', *args)
62
63
64def check_amalgamated_dependencies():
65  os_deps = {}
66  for os_name in ['android', 'linux', 'mac']:
67    gn_args = (' target_os="%s"' % os_name) + GN_ARGS
68    os_deps[os_name] = call(GEN_AMALGAMATED, '--gn_args', gn_args, '--out',
69                            OUT_DIR, '--dump-deps', '--quiet').split('\n')
70  for os_name, deps in os_deps.items():
71    for dep in deps:
72      for other_os, other_deps in os_deps.items():
73        if not dep in other_deps:
74          raise AssertionError('Discrepancy in amalgamated build dependencies: '
75                               '%s is missing on %s.' % (dep, other_os))
76
77
78def main():
79  check_amalgamated_dependencies()
80  check_amalgamated_output()
81  check_amalgamated_build()
82  shutil.rmtree(OUT_DIR)
83
84
85if __name__ == '__main__':
86  exit(main())
87