diff --git a/pw_presubmit/py/BUILD.bazel b/pw_presubmit/py/BUILD.bazel index e509c92d3..fdf16281f 100644 --- a/pw_presubmit/py/BUILD.bazel +++ b/pw_presubmit/py/BUILD.bazel @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations under # the License. +load("@bazel_skylib//rules:copy_file.bzl", "copy_file") load("@rules_python//python:defs.bzl", "py_library") load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary") load("//pw_build:python.bzl", "pw_py_binary", "pw_py_test") @@ -109,12 +110,24 @@ py_console_script_binary( visibility = ["//visibility:private"], ) +copy_file( + name = "clang-format", + src = select({ + "@platforms//os:macos": "@llvm_toolchain_macos//:bin/clang-format", + "//conditions:default": "@llvm_toolchain//:bin/clang-format", + }), + out = "clang-format", + allow_symlink = True, + is_executable = True, +) + pw_py_binary( name = "format", srcs = ["pw_presubmit/format/pigweed_format.py"], data = [ "//:.black.toml", "//pw_presubmit/py:black", + "//pw_presubmit/py:clang-format", ], main = "pw_presubmit/format/pigweed_format.py", deps = [ diff --git a/pw_presubmit/py/pw_presubmit/format/pigweed_format.py b/pw_presubmit/py/pw_presubmit/format/pigweed_format.py index 8218ad5b5..d15f6d9b1 100644 --- a/pw_presubmit/py/pw_presubmit/format/pigweed_format.py +++ b/pw_presubmit/py/pw_presubmit/format/pigweed_format.py @@ -21,6 +21,7 @@ from pw_cli.tool_runner import ToolRunner, BasicSubprocessRunner from pw_presubmit.format.private.cli import FormattingSuite from pw_presubmit.format.python import BlackFormatter +from pw_presubmit.format.cpp import ClangFormatFormatter try: from python.runfiles import runfiles # type: ignore @@ -84,6 +85,11 @@ def _pigweed_formatting_suite() -> FormattingSuite: default_runner.add_tool( # type: ignore[attr-defined] 'black', 'pigweed/pw_presubmit/py/black', r.CurrentRepository() ) + default_runner.add_tool( # type: ignore[attr-defined] + 'clang-format', + 'pigweed/pw_presubmit/py/clang-format', + r.CurrentRepository(), + ) # This is deliberately not public since there's some work to do to make # things more extensible/maintainable before downstream projects try to @@ -93,6 +99,9 @@ def _pigweed_formatting_suite() -> FormattingSuite: config_file=tool_runfiles['.black.toml'], tool_runner=default_runner, ), + ClangFormatFormatter( + tool_runner=default_runner, + ), ] return FormattingSuite(pigweed_formatters)