blob: 901d73ed1a184a8238112de9038b9f45990928cd [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 = (
Oystein Eftevaagab3b1b22018-03-08 16:27:06 -080021 'perfetto/config/chrome/chrome_config.proto',
Primiano Tucci20b760c2018-01-19 12:36:12 +000022 'perfetto/config/data_source_config.proto',
Primiano Tuccidae35652018-03-29 18:32:02 +010023 'perfetto/config/inode_file/inode_file_config.proto',
Hector Dearman1b9c58a2018-03-29 18:45:06 +010024 'perfetto/config/process_stats/process_stats_config.proto',
Primiano Tucci82a8bfd2018-09-19 11:33:04 +010025 'perfetto/config/sys_stats/sys_stats_config.proto',
Primiano Tucci20b760c2018-01-19 12:36:12 +000026 'perfetto/config/data_source_descriptor.proto',
Hector Dearmana89cc572018-02-23 12:02:58 +000027 'perfetto/config/ftrace/ftrace_config.proto',
28 'perfetto/config/trace_config.proto',
Lalit Maganti3f5705c2018-03-09 12:09:44 +000029 'perfetto/config/test_config.proto',
Primiano Tucci6aa75572018-03-21 05:33:14 -070030 'perfetto/common/commit_data_request.proto',
Primiano Tucci82a8bfd2018-09-19 11:33:04 +010031 'perfetto/common/sys_stats_counters.proto',
Primiano Tucci5fec9212017-12-11 23:08:40 +000032)
33
34HEADER_PATH = 'include/perfetto/tracing/core'
35CPP_PATH = 'src/tracing/core'
Sami Kyostila63b62c42018-01-04 21:16:32 +000036INCLUDE_PATH = 'perfetto/tracing/core'
Primiano Tucci5fec9212017-12-11 23:08:40 +000037
38
39def run(cmd):
40 print('\nRunning ' + ' '.join(cmd))
41 subprocess.check_call(cmd)
42
43
44def main():
45 if not os.path.exists('.gn'):
Primiano Tuccic5010802018-01-19 17:13:21 +000046 print('This script must be executed from the perfetto root directory')
Primiano Tucci5fec9212017-12-11 23:08:40 +000047 return 1
48 if len(sys.argv) < 2:
49 print('Usage: %s out/xxx' % sys.argv[0])
50 return 1
51 out_dir = sys.argv[1]
52 clang_format = ['clang-format', '-i', '--sort-includes']
53 tool = os.path.join(out_dir, 'proto_to_cpp')
54 if not os.path.exists(tool):
55 print('Could not find %s, run ninja -C %s proto_to_cpp' % (tool, out_dir))
56 for proto in PROTOS:
Sami Kyostila63b62c42018-01-04 21:16:32 +000057 run([tool, proto] + [HEADER_PATH, CPP_PATH, INCLUDE_PATH])
Primiano Tucci5fec9212017-12-11 23:08:40 +000058 fname = os.path.basename(proto).replace('.proto', '')
59 run(clang_format + [os.path.join(HEADER_PATH, fname + '.h')])
60 run(clang_format + [os.path.join(CPP_PATH, fname + '.cc')])
61
62
63if __name__ == '__main__':
64 sys.exit(main())