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 = ( |
Primiano Tucci | 64df2ca | 2019-01-03 22:26:47 +0000 | [diff] [blame] | 21 | 'perfetto/common/android_log_constants.proto', |
Primiano Tucci | 6aa7557 | 2018-03-21 05:33:14 -0700 | [diff] [blame] | 22 | 'perfetto/common/commit_data_request.proto', |
Eric Seckler | 7b0c945 | 2019-03-18 13:14:36 +0000 | [diff] [blame] | 23 | 'perfetto/common/observable_events.proto', |
Primiano Tucci | 82a8bfd | 2018-09-19 11:33:04 +0100 | [diff] [blame] | 24 | 'perfetto/common/sys_stats_counters.proto', |
Eric Seckler | eaf29ed | 2019-01-23 09:53:55 +0000 | [diff] [blame] | 25 | 'perfetto/common/trace_stats.proto', |
Primiano Tucci | 64df2ca | 2019-01-03 22:26:47 +0000 | [diff] [blame] | 26 | 'perfetto/config/android/android_log_config.proto', |
Primiano Tucci | b86e9ca | 2018-12-03 20:20:11 +0100 | [diff] [blame] | 27 | '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 Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 38 | ) |
| 39 | |
| 40 | HEADER_PATH = 'include/perfetto/tracing/core' |
| 41 | CPP_PATH = 'src/tracing/core' |
Sami Kyostila | 63b62c4 | 2018-01-04 21:16:32 +0000 | [diff] [blame] | 42 | INCLUDE_PATH = 'perfetto/tracing/core' |
Primiano Tucci | 1361d98 | 2019-05-14 09:50:41 +0100 | [diff] [blame^] | 43 | ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 44 | |
| 45 | def run(cmd): |
| 46 | print('\nRunning ' + ' '.join(cmd)) |
| 47 | subprocess.check_call(cmd) |
| 48 | |
| 49 | |
| 50 | def main(): |
| 51 | if not os.path.exists('.gn'): |
Primiano Tucci | c501080 | 2018-01-19 17:13:21 +0000 | [diff] [blame] | 52 | print('This script must be executed from the perfetto root directory') |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 53 | 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 Tucci | 1361d98 | 2019-05-14 09:50:41 +0100 | [diff] [blame^] | 58 | 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 Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 61 | 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 Kyostila | 63b62c4 | 2018-01-04 21:16:32 +0000 | [diff] [blame] | 65 | run([tool, proto] + [HEADER_PATH, CPP_PATH, INCLUDE_PATH]) |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 66 | 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 | |
| 71 | if __name__ == '__main__': |
| 72 | sys.exit(main()) |