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 | |
Primiano Tucci | 2c5488f | 2019-06-01 03:27:28 +0100 | [diff] [blame^] | 20 | CORE_H = 'include/perfetto/ext/tracing/core' |
Primiano Tucci | 0f2f3b4 | 2019-05-21 19:37:01 +0100 | [diff] [blame] | 21 | CORE_CPP = 'src/tracing/core' |
| 22 | |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 23 | PROTOS = ( |
Primiano Tucci | 0f2f3b4 | 2019-05-21 19:37:01 +0100 | [diff] [blame] | 24 | ('perfetto/common/commit_data_request.proto', CORE_H, CORE_CPP), |
| 25 | ('perfetto/common/observable_events.proto', CORE_H, CORE_CPP), |
| 26 | ('perfetto/common/trace_stats.proto', CORE_H, CORE_CPP), |
| 27 | ('perfetto/config/chrome/chrome_config.proto', CORE_H, CORE_CPP), |
| 28 | ('perfetto/config/data_source_config.proto', CORE_H, CORE_CPP), |
| 29 | ('perfetto/config/data_source_descriptor.proto', CORE_H, CORE_CPP), |
| 30 | ('perfetto/config/test_config.proto', CORE_H, CORE_CPP), |
| 31 | ('perfetto/config/trace_config.proto', CORE_H, CORE_CPP), |
| 32 | |
| 33 | # Generate ftrace cpp/h files into their own directory. |
| 34 | ('perfetto/config/ftrace/ftrace_config.proto', |
| 35 | 'src/traced/probes/ftrace', 'src/traced/probes/ftrace'), |
| 36 | |
| 37 | # Generate profiling cpp/h files into their own directory. |
| 38 | ('perfetto/config/profiling/heapprofd_config.proto', |
| 39 | 'src/profiling/memory', 'src/profiling/memory'), |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 40 | ) |
| 41 | |
Primiano Tucci | 0f2f3b4 | 2019-05-21 19:37:01 +0100 | [diff] [blame] | 42 | |
Primiano Tucci | 2c5488f | 2019-06-01 03:27:28 +0100 | [diff] [blame^] | 43 | HEADER_PATH = 'include/perfetto/ext/tracing/core' |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 44 | CPP_PATH = 'src/tracing/core' |
Primiano Tucci | 2c5488f | 2019-06-01 03:27:28 +0100 | [diff] [blame^] | 45 | INCLUDE_PATH = 'perfetto/ext/tracing/core' |
Primiano Tucci | 1361d98 | 2019-05-14 09:50:41 +0100 | [diff] [blame] | 46 | ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 47 | |
Primiano Tucci | 0f2f3b4 | 2019-05-21 19:37:01 +0100 | [diff] [blame] | 48 | |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 49 | def run(cmd): |
| 50 | print('\nRunning ' + ' '.join(cmd)) |
| 51 | subprocess.check_call(cmd) |
| 52 | |
| 53 | |
| 54 | def main(): |
| 55 | if not os.path.exists('.gn'): |
Primiano Tucci | c501080 | 2018-01-19 17:13:21 +0000 | [diff] [blame] | 56 | print('This script must be executed from the perfetto root directory') |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 57 | return 1 |
| 58 | if len(sys.argv) < 2: |
| 59 | print('Usage: %s out/xxx' % sys.argv[0]) |
| 60 | return 1 |
| 61 | out_dir = sys.argv[1] |
Primiano Tucci | 1361d98 | 2019-05-14 09:50:41 +0100 | [diff] [blame] | 62 | arch = 'mac' if sys.platform == 'darwin' else 'linux64' |
Primiano Tucci | 0f2f3b4 | 2019-05-21 19:37:01 +0100 | [diff] [blame] | 63 | clang_format_path = os.path.join( |
| 64 | ROOT_DIR, 'buildtools', arch, 'clang-format') |
Primiano Tucci | 1361d98 | 2019-05-14 09:50:41 +0100 | [diff] [blame] | 65 | clang_format = [clang_format_path, '-i', '--sort-includes'] |
Primiano Tucci | 0f2f3b4 | 2019-05-21 19:37:01 +0100 | [diff] [blame] | 66 | ninja = os.path.join(ROOT_DIR, 'tools', 'ninja') |
| 67 | run([ninja, '-C', out_dir, 'proto_to_cpp']) |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 68 | tool = os.path.join(out_dir, 'proto_to_cpp') |
Primiano Tucci | 0f2f3b4 | 2019-05-21 19:37:01 +0100 | [diff] [blame] | 69 | assert(os.path.exists(tool)) |
| 70 | for args in PROTOS: |
| 71 | proto, header_dir, cpp_dir = args |
| 72 | include_dir = header_dir.replace('include/', '') |
| 73 | run([tool, proto] + [header_dir, cpp_dir, include_dir]) |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 74 | fname = os.path.basename(proto).replace('.proto', '') |
Primiano Tucci | 0f2f3b4 | 2019-05-21 19:37:01 +0100 | [diff] [blame] | 75 | run(clang_format + [os.path.join(header_dir, fname + '.h')]) |
| 76 | run(clang_format + [os.path.join(cpp_dir, fname + '.cc')]) |
Primiano Tucci | 5fec921 | 2017-12-11 23:08:40 +0000 | [diff] [blame] | 77 | |
| 78 | |
| 79 | if __name__ == '__main__': |
| 80 | sys.exit(main()) |