Path: blob/main_old/scripts/apply_clang_format_on_all_sources.py
1693 views
#!/usr/bin/env python12# Copyright 2019 The ANGLE Project Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.56# apply_clang_format_on_all_sources.py:7# Script to apply clang-format recursively on directory,8# example usage:9# ./scripts/apply_clang_format_on_all_sources.py src1011from __future__ import print_function1213import os14import sys15import platform16import subprocess1718# inplace change and use style from .clang-format19CLANG_FORMAT_ARGS = ['-i', '-style=file']202122def main(directory):23system = platform.system()2425clang_format_exe = 'clang-format'26if system == 'Windows':27clang_format_exe += '.bat'2829partial_cmd = [clang_format_exe] + CLANG_FORMAT_ARGS3031for subdir, _, files in os.walk(directory):32if 'third_party' in subdir:33continue3435for f in files:36if f.endswith(('.c', '.h', '.cpp', '.hpp')):37f_abspath = os.path.join(subdir, f)38print("Applying clang-format on ", f_abspath)39subprocess.check_call(partial_cmd + [f_abspath])404142if __name__ == '__main__':43if len(sys.argv) > 2:44print('Too mang args', file=sys.stderr)4546elif len(sys.argv) == 2:47main(os.path.join(os.getcwd(), sys.argv[1]))4849else:50main(os.getcwd())515253