Add .clang-format files and format more files

The .clang-format files tell clang-format to ignore certain directories
(replacing code in lint_clang_format.sh which will be removed).

$ git ls-tree -r master --name-only | grep '\.\(c\|h\|cpp\|gn\|gni\|mm\|m\|py\)$' | xargs ./append-space-to-files
$ git checkout -- generator/templates third_party/khronos/{KHR,vulkan}
$ git cl format --full --python

Followed by manual reformatting of a few things in Python for
readability.

Bug: none
Change-Id: I4c9e472cc9a5cd80c07286e808f4e597cfef5428
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24785
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Kai Ninomiya
2020-07-15 19:51:17 +00:00
committed by Commit Bot service account
parent 5a1d39ad0b
commit 01aeca22a9
12 changed files with 508 additions and 200 deletions

View File

@@ -15,11 +15,15 @@
import argparse, glob, os, sys
def check_in_subdirectory(path, directory):
return path.startswith(directory) and not '/' in path[len(directory):]
def check_is_allowed(path, allowed_dirs):
return any(check_in_subdirectory(path, directory) for directory in allowed_dirs)
return any(
check_in_subdirectory(path, directory) for directory in allowed_dirs)
def get_all_files_in_dir(find_directory):
result = []
@@ -27,15 +31,28 @@ def get_all_files_in_dir(find_directory):
result += [os.path.join(directory, filename) for filename in files]
return result
def run():
# Parse command line arguments
parser = argparse.ArgumentParser(
description = "Removes stale autogenerated files from gen/ directories."
description="Removes stale autogenerated files from gen/ directories.")
parser.add_argument(
'--root-dir',
type=str,
help='The root directory, all other paths in files are relative to it.'
)
parser.add_argument('--root-dir', type=str, help='The root directory, all other paths in files are relative to it.')
parser.add_argument('--allowed-output-dirs-file', type=str, help='The file containing a list of allowed directories')
parser.add_argument('--stale-dirs-file', type=str, help='The file containing a list of directories to check for stale files')
parser.add_argument('--stamp', type=str, help='A stamp written once this script completes')
parser.add_argument(
'--allowed-output-dirs-file',
type=str,
help='The file containing a list of allowed directories')
parser.add_argument(
'--stale-dirs-file',
type=str,
help=
'The file containing a list of directories to check for stale files')
parser.add_argument('--stamp',
type=str,
help='A stamp written once this script completes')
args = parser.parse_args()
root_dir = args.root_dir
@@ -43,11 +60,13 @@ def run():
# Load the list of allowed and stale directories
with open(args.allowed_output_dirs_file) as f:
allowed_dirs = set([os.path.join(root_dir, line.strip()) for line in f.readlines()])
allowed_dirs = set(
[os.path.join(root_dir, line.strip()) for line in f.readlines()])
for directory in allowed_dirs:
if not directory.endswith('/'):
print('Allowed directory entry "{}" doesn\'t end with /'.format(directory))
print('Allowed directory entry "{}" doesn\'t end with /'.format(
directory))
return 1
with open(args.stale_dirs_file) as f:
@@ -67,5 +86,6 @@ def run():
return 0
if __name__ == "__main__":
sys.exit(run())