[Bf-blender-cvs] [6f27fab9d1d] temp-clang-format: clang-format: make tab expanding optional
Campbell Barton
noreply at git.blender.org
Mon Apr 15 18:56:58 CEST 2019
Commit: 6f27fab9d1dfb7cc5b8545935b963dd6b2f7f113
Author: Campbell Barton
Date: Mon Apr 15 18:52:12 2019 +0200
Branches: temp-clang-format
https://developer.blender.org/rB6f27fab9d1dfb7cc5b8545935b963dd6b2f7f113
clang-format: make tab expanding optional
Use argparse module for argument parsing.
===================================================================
M GNUmakefile
M build_files/utils/clang_format_paths.py
===================================================================
diff --git a/GNUmakefile b/GNUmakefile
index f765788d115..84c3aa29203 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -514,7 +514,8 @@ update: .FORCE
git submodule foreach git pull --rebase origin master
format: .FORCE
- PATH="../lib/${OS_NCASE}/llvm/bin/:$(PATH)" python3 build_files/utils/clang_format_paths.py $(PATHS)
+ PATH="../lib/${OS_NCASE}/llvm/bin/:$(PATH)" \
+ python3 build_files/utils/clang_format_paths.py --expand-tabs $(PATHS)
# -----------------------------------------------------------------------------
diff --git a/build_files/utils/clang_format_paths.py b/build_files/utils/clang_format_paths.py
index 18c52690200..07e71a0f554 100755
--- a/build_files/utils/clang_format_paths.py
+++ b/build_files/utils/clang_format_paths.py
@@ -8,35 +8,6 @@ import subprocess
CLANG_FORMAT_CMD = "clang-format"
VERSION_MIN = (6, 0, 0)
-# Optionally pass in files to operate on.
-paths = sys.argv[1:]
-if not paths:
- paths.extend((
- "intern/atomic",
- "intern/audaspace",
- "intern/clog",
- "intern/cycles",
- "intern/dualcon",
- "intern/eigen",
- "intern/ffmpeg",
- "intern/ghost",
- "intern/glew-mx",
- "intern/guardedalloc",
- "intern/iksolver",
- "intern/locale",
- "intern/memutil",
- "intern/mikktspace",
- "intern/opencolorio",
- "intern/openvdb",
- "intern/rigidbody",
- "intern/string",
- "intern/utfconv",
- "source",
- "tests/gtests",
- ))
-
-if os.sep != "/":
- paths = [f.replace("/", os.sep) for f in paths]
extensions = (
".c", ".cc", ".cpp", ".cxx",
@@ -49,11 +20,41 @@ ignore_files = {
"intern/cycles/render/sobol.cpp", # Too heavy for clang-format
}
-print("Operating on:")
-for p in paths:
- print(" ", p)
-def source_files_from_git():
+def compute_paths(paths_arg):
+ # Optionally pass in files to operate on.
+ paths = paths_arg
+ if not paths:
+ paths.extend((
+ "intern/atomic",
+ "intern/audaspace",
+ "intern/clog",
+ "intern/cycles",
+ "intern/dualcon",
+ "intern/eigen",
+ "intern/ffmpeg",
+ "intern/ghost",
+ "intern/glew-mx",
+ "intern/guardedalloc",
+ "intern/iksolver",
+ "intern/locale",
+ "intern/memutil",
+ "intern/mikktspace",
+ "intern/opencolorio",
+ "intern/openvdb",
+ "intern/rigidbody",
+ "intern/string",
+ "intern/utfconv",
+ "source",
+ "tests/gtests",
+ ))
+
+ if os.sep != "/":
+ paths = [f.replace("/", os.sep) for f in paths]
+ return paths
+
+
+def source_files_from_git(paths):
cmd = ("git", "ls-tree", "-r", "HEAD", *paths, "--name-only", "-z")
files = subprocess.check_output(cmd).split(b'\0')
return [f.decode('ascii') for f in files]
@@ -116,6 +117,31 @@ def clang_format(files):
pool.close()
pool.join()
+def argparse_create():
+ import argparse
+
+ # When --help or no args are given, print this help
+ usage_text = "Format source code"
+ epilog = "This script runs clang-format on multiple files/directories"
+ parser = argparse.ArgumentParser(description=usage_text, epilog=epilog)
+ parser.add_argument(
+ "--expand-tabs",
+ dest="expand_tabs",
+ default=False,
+ action='store_true',
+ help="Run a pre-pass that expands tabs "
+ "(default=False)",
+ required=False,
+ )
+ parser.add_argument(
+ "paths",
+ nargs=argparse.REMAINDER,
+ help="All trailing arguments are treated as paths."
+ )
+
+ return parser
+
+
def main():
version = clang_format_version()
@@ -126,13 +152,21 @@ def main():
print("Version of clang-format is too old:", version, "<", VERSION_MIN)
sys.exit(1)
+ args = argparse_create().parse_args()
+
+ paths = compute_paths(args.paths)
+ print("Operating on:")
+ for p in paths:
+ print(" ", p)
+
files = [
- f for f in source_files_from_git()
+ f for f in source_files_from_git(paths)
if f.endswith(extensions)
if f not in ignore_files
]
- convert_tabs_to_spaces(files)
+ if args.expand_tabs:
+ convert_tabs_to_spaces(files)
clang_format(files)
More information about the Bf-blender-cvs
mailing list