Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 1 | #!/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 | |
| 16 | import os |
| 17 | import subprocess |
| 18 | import sys |
| 19 | |
| 20 | PROTOS = ( |
Oystein Eftevaag | ab3b1b2 | 2018-03-08 16:27:06 -0800 | [diff] [blame] | 21 | 'perfetto/config/chrome/chrome_config.proto', |
Primiano Tucci | 20b760c | 2018-01-19 12:36:12 +0000 | [diff] [blame] | 22 | 'perfetto/config/data_source_config.proto', |
Primiano Tucci | dae3565 | 2018-03-29 18:32:02 +0100 | [diff] [blame] | 23 | 'perfetto/config/inode_file/inode_file_config.proto', |
Hector Dearman | 1b9c58a | 2018-03-29 18:45:06 +0100 | [diff] [blame] | 24 | 'perfetto/config/process_stats/process_stats_config.proto', |
Primiano Tucci | 82a8bfd | 2018-09-19 11:33:04 +0100 | [diff] [blame] | 25 | 'perfetto/config/sys_stats/sys_stats_config.proto', |
Primiano Tucci | 20b760c | 2018-01-19 12:36:12 +0000 | [diff] [blame] | 26 | 'perfetto/config/data_source_descriptor.proto', |
Hector Dearman | a89cc57 | 2018-02-23 12:02:58 +0000 | [diff] [blame] | 27 | 'perfetto/config/ftrace/ftrace_config.proto', |
| 28 | 'perfetto/config/trace_config.proto', |
Lalit Maganti | 3f5705c | 2018-03-09 12:09:44 +0000 | [diff] [blame] | 29 | 'perfetto/config/test_config.proto', |
Primiano Tucci | 6aa7557 | 2018-03-21 05:33:14 -0700 | [diff] [blame] | 30 | 'perfetto/common/commit_data_request.proto', |
Primiano Tucci | 82a8bfd | 2018-09-19 11:33:04 +0100 | [diff] [blame] | 31 | 'perfetto/common/sys_stats_counters.proto', |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 32 | ) |
| 33 | |
| 34 | HEADER_PATH = 'include/perfetto/tracing/core' |
| 35 | CPP_PATH = 'src/tracing/core' |
Sami Kyostila | 63b62c4 | 2018-01-04 21:16:32 +0000 | [diff] [blame] | 36 | INCLUDE_PATH = 'perfetto/tracing/core' |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 37 | |
| 38 | |
| 39 | def run(cmd): |
| 40 | print('\nRunning ' + ' '.join(cmd)) |
| 41 | subprocess.check_call(cmd) |
| 42 | |
| 43 | |
| 44 | def main(): |
| 45 | if not os.path.exists('.gn'): |
Primiano Tucci | c501080 | 2018-01-19 17:13:21 +0000 | [diff] [blame] | 46 | print('This script must be executed from the perfetto root directory') |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 47 | 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 Kyostila | 63b62c4 | 2018-01-04 21:16:32 +0000 | [diff] [blame] | 57 | run([tool, proto] + [HEADER_PATH, CPP_PATH, INCLUDE_PATH]) |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 58 | 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 | |
| 63 | if __name__ == '__main__': |
| 64 | sys.exit(main()) |