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/inode_file/inode_file_config.proto', 24 'perfetto/config/process_stats/process_stats_config.proto', 25 'perfetto/config/data_source_descriptor.proto', 26 'perfetto/config/ftrace/ftrace_config.proto', 27 'perfetto/config/trace_config.proto', 28 'perfetto/config/test_config.proto', 29 'perfetto/common/commit_data_request.proto', 30) 31 32HEADER_PATH = 'include/perfetto/tracing/core' 33CPP_PATH = 'src/tracing/core' 34INCLUDE_PATH = 'perfetto/tracing/core' 35 36 37def run(cmd): 38 print('\nRunning ' + ' '.join(cmd)) 39 subprocess.check_call(cmd) 40 41 42def main(): 43 if not os.path.exists('.gn'): 44 print('This script must be executed from the perfetto root directory') 45 return 1 46 if len(sys.argv) < 2: 47 print('Usage: %s out/xxx' % sys.argv[0]) 48 return 1 49 out_dir = sys.argv[1] 50 clang_format = ['clang-format', '-i', '--sort-includes'] 51 tool = os.path.join(out_dir, 'proto_to_cpp') 52 if not os.path.exists(tool): 53 print('Could not find %s, run ninja -C %s proto_to_cpp' % (tool, out_dir)) 54 for proto in PROTOS: 55 run([tool, proto] + [HEADER_PATH, CPP_PATH, INCLUDE_PATH]) 56 fname = os.path.basename(proto).replace('.proto', '') 57 run(clang_format + [os.path.join(HEADER_PATH, fname + '.h')]) 58 run(clang_format + [os.path.join(CPP_PATH, fname + '.cc')]) 59 60 61if __name__ == '__main__': 62 sys.exit(main()) 63