blob: 9ae472a8d165bce048140dcee7e4adffe20b3058 [file] [log] [blame]
Primiano Tucci5fec9212017-12-11 23:08:40 +00001#!/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
16import os
17import subprocess
18import sys
19
20PROTOS = (
Primiano Tucci64df2ca2019-01-03 22:26:47 +000021 'perfetto/common/android_log_constants.proto',
Primiano Tucci6aa75572018-03-21 05:33:14 -070022 'perfetto/common/commit_data_request.proto',
Eric Seckler7b0c9452019-03-18 13:14:36 +000023 'perfetto/common/observable_events.proto',
Primiano Tucci82a8bfd2018-09-19 11:33:04 +010024 'perfetto/common/sys_stats_counters.proto',
Eric Secklereaf29ed2019-01-23 09:53:55 +000025 'perfetto/common/trace_stats.proto',
Primiano Tucci64df2ca2019-01-03 22:26:47 +000026 'perfetto/config/android/android_log_config.proto',
Primiano Tuccib86e9ca2018-12-03 20:20:11 +010027 'perfetto/config/chrome/chrome_config.proto',
28 'perfetto/config/data_source_config.proto',
29 'perfetto/config/data_source_descriptor.proto',
30 'perfetto/config/ftrace/ftrace_config.proto',
31 'perfetto/config/inode_file/inode_file_config.proto',
32 'perfetto/config/power/android_power_config.proto',
33 'perfetto/config/process_stats/process_stats_config.proto',
34 'perfetto/config/profiling/heapprofd_config.proto',
35 'perfetto/config/sys_stats/sys_stats_config.proto',
36 'perfetto/config/test_config.proto',
37 'perfetto/config/trace_config.proto',
Primiano Tucci5fec9212017-12-11 23:08:40 +000038)
39
40HEADER_PATH = 'include/perfetto/tracing/core'
41CPP_PATH = 'src/tracing/core'
Sami Kyostila63b62c42018-01-04 21:16:32 +000042INCLUDE_PATH = 'perfetto/tracing/core'
Primiano Tucci1361d982019-05-14 09:50:41 +010043ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Primiano Tucci5fec9212017-12-11 23:08:40 +000044
45def run(cmd):
46 print('\nRunning ' + ' '.join(cmd))
47 subprocess.check_call(cmd)
48
49
50def main():
51 if not os.path.exists('.gn'):
Primiano Tuccic5010802018-01-19 17:13:21 +000052 print('This script must be executed from the perfetto root directory')
Primiano Tucci5fec9212017-12-11 23:08:40 +000053 return 1
54 if len(sys.argv) < 2:
55 print('Usage: %s out/xxx' % sys.argv[0])
56 return 1
57 out_dir = sys.argv[1]
Primiano Tucci1361d982019-05-14 09:50:41 +010058 arch = 'mac' if sys.platform == 'darwin' else 'linux64'
59 clang_format_path = os.path.join(ROOT_DIR, 'buildtools', arch, 'clang-format')
60 clang_format = [clang_format_path, '-i', '--sort-includes']
Primiano Tucci5fec9212017-12-11 23:08:40 +000061 tool = os.path.join(out_dir, 'proto_to_cpp')
62 if not os.path.exists(tool):
63 print('Could not find %s, run ninja -C %s proto_to_cpp' % (tool, out_dir))
64 for proto in PROTOS:
Sami Kyostila63b62c42018-01-04 21:16:32 +000065 run([tool, proto] + [HEADER_PATH, CPP_PATH, INCLUDE_PATH])
Primiano Tucci5fec9212017-12-11 23:08:40 +000066 fname = os.path.basename(proto).replace('.proto', '')
67 run(clang_format + [os.path.join(HEADER_PATH, fname + '.h')])
68 run(clang_format + [os.path.join(CPP_PATH, fname + '.cc')])
69
70
71if __name__ == '__main__':
72 sys.exit(main())