#!/usr/bin/env python
|
# Copyright (C) 2017 The Android Open Source Project
|
#
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
# you may not use this file except in compliance with the License.
|
# You may obtain a copy of the License at
|
#
|
# http://www.apache.org/licenses/LICENSE-2.0
|
#
|
# Unless required by applicable law or agreed to in writing, software
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# See the License for the specific language governing permissions and
|
# limitations under the License.
|
|
import os
|
import subprocess
|
import sys
|
|
PROTOS = (
|
'perfetto/common/android_log_constants.proto',
|
'perfetto/common/commit_data_request.proto',
|
'perfetto/common/observable_events.proto',
|
'perfetto/common/sys_stats_counters.proto',
|
'perfetto/common/trace_stats.proto',
|
'perfetto/config/android/android_log_config.proto',
|
'perfetto/config/chrome/chrome_config.proto',
|
'perfetto/config/data_source_config.proto',
|
'perfetto/config/data_source_descriptor.proto',
|
'perfetto/config/ftrace/ftrace_config.proto',
|
'perfetto/config/inode_file/inode_file_config.proto',
|
'perfetto/config/power/android_power_config.proto',
|
'perfetto/config/process_stats/process_stats_config.proto',
|
'perfetto/config/profiling/heapprofd_config.proto',
|
'perfetto/config/sys_stats/sys_stats_config.proto',
|
'perfetto/config/test_config.proto',
|
'perfetto/config/trace_config.proto',
|
'perfetto/config/android/packages_list_config.proto',
|
)
|
|
HEADER_PATH = 'include/perfetto/tracing/core'
|
CPP_PATH = 'src/tracing/core'
|
INCLUDE_PATH = 'perfetto/tracing/core'
|
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
def run(cmd):
|
print('\nRunning ' + ' '.join(cmd))
|
subprocess.check_call(cmd)
|
|
|
def main():
|
if not os.path.exists('.gn'):
|
print('This script must be executed from the perfetto root directory')
|
return 1
|
if len(sys.argv) < 2:
|
print('Usage: %s out/xxx' % sys.argv[0])
|
return 1
|
out_dir = sys.argv[1]
|
arch = 'mac' if sys.platform == 'darwin' else 'linux64'
|
clang_format_path = os.path.join(ROOT_DIR, 'buildtools', arch, 'clang-format')
|
clang_format = [clang_format_path, '-i', '--sort-includes']
|
tool = os.path.join(out_dir, 'proto_to_cpp')
|
if not os.path.exists(tool):
|
print('Could not find %s, run ninja -C %s proto_to_cpp' % (tool, out_dir))
|
for proto in PROTOS:
|
run([tool, proto] + [HEADER_PATH, CPP_PATH, INCLUDE_PATH])
|
fname = os.path.basename(proto).replace('.proto', '')
|
run(clang_format + [os.path.join(HEADER_PATH, fname + '.h')])
|
run(clang_format + [os.path.join(CPP_PATH, fname + '.cc')])
|
|
|
if __name__ == '__main__':
|
sys.exit(main())
|