blob: 1ec4a959bd650ba1ed1937a1a178b4a9c7be6b34 [file] [log] [blame]
Primiano Tucci5fec9212017-12-11 23:08:40 +00001#!/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 'protos/tracing_service/trace_config.proto',
22 'protos/tracing_service/data_source_config.proto',
23 'protos/tracing_service/data_source_descriptor.proto',
24)
25
26HEADER_PATH = 'include/perfetto/tracing/core'
27CPP_PATH = 'src/tracing/core'
28
29
30def run(cmd):
31 print('\nRunning ' + ' '.join(cmd))
32 subprocess.check_call(cmd)
33
34
35def main():
36 if not os.path.exists('.gn'):
37 print('This script mast be executed from the perfetto root directory')
38 return 1
39 if len(sys.argv) < 2:
40 print('Usage: %s out/xxx' % sys.argv[0])
41 return 1
42 out_dir = sys.argv[1]
43 clang_format = ['clang-format', '-i', '--sort-includes']
44 tool = os.path.join(out_dir, 'proto_to_cpp')
45 if not os.path.exists(tool):
46 print('Could not find %s, run ninja -C %s proto_to_cpp' % (tool, out_dir))
47 for proto in PROTOS:
48 run([tool, proto] + [HEADER_PATH, CPP_PATH])
49 fname = os.path.basename(proto).replace('.proto', '')
50 run(clang_format + [os.path.join(HEADER_PATH, fname + '.h')])
51 run(clang_format + [os.path.join(CPP_PATH, fname + '.cc')])
52
53
54if __name__ == '__main__':
55 sys.exit(main())