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