-
Notifications
You must be signed in to change notification settings - Fork 710
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Makefile with formatter helper (#521)
* Add Makefile with format target * Use Makefile in CI * Trigger clang-format on Makefile changes
- Loading branch information
Showing
2 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Directories to search | ||
SEARCH_DIRS = Sources Tests Samples/Common/Sources/CrashTriggers | ||
|
||
# File extensions to format | ||
FILE_EXTENSIONS = c cpp h m mm | ||
|
||
# Check for clang-format-18 first, then fall back to clang-format | ||
CLANG_FORMAT := $(shell command -v clang-format-18 2> /dev/null || command -v clang-format 2> /dev/null) | ||
|
||
# Define the default target | ||
.PHONY: format check-format | ||
|
||
all: format | ||
|
||
format: | ||
ifeq ($(CLANG_FORMAT),) | ||
@echo "Error: clang-format or clang-format-18 is not installed. Please install it and try again." | ||
@exit 1 | ||
else | ||
@echo "Using $(CLANG_FORMAT)" | ||
find $(SEARCH_DIRS) $(foreach ext,$(FILE_EXTENSIONS),-name '*.$(ext)' -o) -false | \ | ||
xargs -r $(CLANG_FORMAT) -style=file -i | ||
endif | ||
|
||
check-format: | ||
ifeq ($(CLANG_FORMAT),) | ||
@echo "Error: clang-format or clang-format-18 is not installed. Please install it and try again." | ||
@exit 1 | ||
else | ||
@echo "Checking format using $(CLANG_FORMAT)" | ||
@find $(SEARCH_DIRS) $(foreach ext,$(FILE_EXTENSIONS),-name '*.$(ext)' -o) -false | \ | ||
xargs -r $(CLANG_FORMAT) -style=file -n -Werror | ||
endif |