From c8bb7b15b66e57e9b0c7f58104dc1912b028745e Mon Sep 17 00:00:00 2001 From: Wyatt Hepler Date: Fri, 29 Jul 2022 21:51:30 +0000 Subject: [PATCH] pw_presubmit: Exclude third_party/fuchsia/repo from formatting Do not automatically format sources that will be imported from Fuchsia. A .clang-format file is included for these sources, but they may have been formatted by a different version of clang-format. Change-Id: I587047340425aa8521abfcf97b77845dae3b834a Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/103884 Pigweed-Auto-Submit: Wyatt Hepler Commit-Queue: Auto-Submit Reviewed-by: Rob Mohr --- PW_PLUGINS | 1 + pw_presubmit/py/pw_presubmit/format_code.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/PW_PLUGINS b/PW_PLUGINS index a3047aef41..2c71655d95 100644 --- a/PW_PLUGINS +++ b/PW_PLUGINS @@ -11,6 +11,7 @@ # return an int to use as the exit code. # Pigweed's presubmit check script +format pw_presubmit.format_code _pigweed_upstream_main heap-viewer pw_allocator.heap_viewer main package pw_package.pigweed_packages main presubmit pw_presubmit.pigweed_presubmit main diff --git a/pw_presubmit/py/pw_presubmit/format_code.py b/pw_presubmit/py/pw_presubmit/format_code.py index 82ca0036b7..64e67cff48 100755 --- a/pw_presubmit/py/pw_presubmit/format_code.py +++ b/pw_presubmit/py/pw_presubmit/format_code.py @@ -565,6 +565,19 @@ def main() -> int: return format_paths_in_repo(**vars(arguments(git_paths=True).parse_args())) +def _pigweed_upstream_main() -> int: + """Check and fix formatting for source files in upstream Pigweed. + + Excludes third party sources. + """ + args = arguments(git_paths=True).parse_args() + + # Exclude paths with third party code from formatting. + args.exclude.append(re.compile('^third_party/fuchsia/repo/')) + + return format_paths_in_repo(**vars(args)) + + if __name__ == '__main__': try: # If pw_cli is available, use it to initialize logs.