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', |
| 23 | 'perfetto/config/data_source_descriptor.proto', |
Hector Dearman | a89cc57 | 2018-02-23 12:02:58 +0000 | [diff] [blame] | 24 | 'perfetto/config/ftrace/ftrace_config.proto', |
| 25 | 'perfetto/config/trace_config.proto', |
Lalit Maganti | 3f5705c | 2018-03-09 12:09:44 +0000 | [diff] [blame] | 26 | 'perfetto/config/test_config.proto', |
Primiano Tucci | 6aa7557 | 2018-03-21 05:33:14 -0700 | [diff] [blame] | 27 | 'perfetto/common/commit_data_request.proto', |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | HEADER_PATH = 'include/perfetto/tracing/core' |
| 31 | CPP_PATH = 'src/tracing/core' |
Sami Kyostila | 63b62c4 | 2018-01-04 21:16:32 +0000 | [diff] [blame] | 32 | INCLUDE_PATH = 'perfetto/tracing/core' |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 33 | |
| 34 | |
| 35 | def run(cmd): |
| 36 | print('\nRunning ' + ' '.join(cmd)) |
| 37 | subprocess.check_call(cmd) |
| 38 | |
| 39 | |
| 40 | def main(): |
| 41 | if not os.path.exists('.gn'): |
Primiano Tucci | c501080 | 2018-01-19 17:13:21 +0000 | [diff] [blame] | 42 | print('This script must be executed from the perfetto root directory') |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 43 | return 1 |
| 44 | if len(sys.argv) < 2: |
| 45 | print('Usage: %s out/xxx' % sys.argv[0]) |
| 46 | return 1 |
| 47 | out_dir = sys.argv[1] |
| 48 | clang_format = ['clang-format', '-i', '--sort-includes'] |
| 49 | tool = os.path.join(out_dir, 'proto_to_cpp') |
| 50 | if not os.path.exists(tool): |
| 51 | print('Could not find %s, run ninja -C %s proto_to_cpp' % (tool, out_dir)) |
| 52 | for proto in PROTOS: |
Sami Kyostila | 63b62c4 | 2018-01-04 21:16:32 +0000 | [diff] [blame] | 53 | run([tool, proto] + [HEADER_PATH, CPP_PATH, INCLUDE_PATH]) |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 54 | fname = os.path.basename(proto).replace('.proto', '') |
| 55 | run(clang_format + [os.path.join(HEADER_PATH, fname + '.h')]) |
| 56 | run(clang_format + [os.path.join(CPP_PATH, fname + '.cc')]) |
| 57 | |
| 58 | |
| 59 | if __name__ == '__main__': |
| 60 | sys.exit(main()) |