gen_tracing_cpp_headers_from_protos.py revision 3f5705c949361d50daccbd44fc8abd234abb766e
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 16import os 17import subprocess 18import sys 19 20PROTOS = ( 21 'perfetto/config/chrome/chrome_config.proto', 22 'perfetto/config/data_source_config.proto', 23 'perfetto/config/data_source_descriptor.proto', 24 'perfetto/config/ftrace/ftrace_config.proto', 25 'perfetto/config/trace_config.proto', 26 'perfetto/config/test_config.proto', 27 'perfetto/ipc/commit_data_request.proto', 28) 29 30HEADER_PATH = 'include/perfetto/tracing/core' 31CPP_PATH = 'src/tracing/core' 32INCLUDE_PATH = 'perfetto/tracing/core' 33 34 35def run(cmd): 36 print('\nRunning ' + ' '.join(cmd)) 37 subprocess.check_call(cmd) 38 39 40def main(): 41 if not os.path.exists('.gn'): 42 print('This script must be executed from the perfetto root directory') 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: 53 run([tool, proto] + [HEADER_PATH, CPP_PATH, INCLUDE_PATH]) 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 59if __name__ == '__main__': 60 sys.exit(main()) 61