xref: /aosp_15_r20/external/perfetto/tools/gen_all (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1#!/usr/bin/env python3
2# Copyright (C) 2018 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 argparse
20import subprocess
21import sys
22
23ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
24IS_WIN = sys.platform.startswith('win')
25
26
27def protoc_path(out_directory):
28  path = os.path.join(out_directory, 'protoc') + ('.exe' if IS_WIN else '')
29  assert os.path.isfile(path)
30  return path
31
32
33def call(cmd, *args):
34  path = os.path.join('tools', cmd)
35  command = ['python3', path] + list(args)
36  print('Running', ' '.join(command))
37  try:
38    subprocess.check_call(command, cwd=ROOT_DIR)
39  except subprocess.CalledProcessError as e:
40    assert False, 'Command: {} failed'.format(' '.join(command))
41
42
43def main():
44  parser = argparse.ArgumentParser()
45  parser.add_argument('--check-only', default=False, action='store_true')
46  parser.add_argument('OUT')
47  args = parser.parse_args()
48  out = args.OUT
49
50  try:
51    assert os.path.isdir(out), \
52        'Output directory "{}" is not a directory'.format(out)
53    check_only = ['--check-only'] if args.check_only else []
54    call('check_include_violations')
55    call('check_proto_comments')
56    call('fix_include_guards', *check_only)
57    if not IS_WIN:
58      call('gen_bazel', *check_only)
59      call('gen_android_bp', *check_only)
60    call('gen_merged_protos', *check_only)
61    call('gen_amalgamated_python_tools', *check_only)
62    call('ninja', '-C', out, 'protoc')
63    call('gen_binary_descriptors', '--protoc', protoc_path(out), *check_only)
64
65    if IS_WIN:
66      print('WARNING: Cannot generate BUILD / Android.bp from Windows. ' +
67            'They might be left stale and fail in the CI if you edited any ' +
68            'BUILD.gn file')
69
70  except AssertionError as e:
71    if not str(e):
72      raise
73    print('Error: {}'.format(e))
74    return 1
75
76  return 0
77
78
79if __name__ == '__main__':
80  exit(main())
81