File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -488,6 +488,30 @@ quake: artifact $(quake_deps)
488488endif
489489endif
490490
491+ CLANG_FMT := $(shell which clang-format 2>/dev/null)
492+ SH_FMT := $(shell which shfmt 2>/dev/null)
493+ BLACK := $(shell which black 2>/dev/null)
494+ SUBMODULES := $(shell git config --file .gitmodules --get-regexp path | awk '{ print $$2 }')
495+ SUBMODULES_PRUNE_PATHS := $(shell for subm in $(SUBMODULES ) ; do echo -n "-path \"./$$subm\" -o "; done | sed 's/ -o $$//')
496+ format :
497+ ifeq ($(CLANG_FMT ) ,)
498+ $(error clang-format not found. Install clang-format version 18 or above and try again)
499+ else
500+ # Skip formatting submodules and everything in $(OUT), apply the same rule for shfmt and black
501+ $(Q)$(shell $(CLANG_FMT) -i $(shell find . \( $(SUBMODULES_PRUNE_PATHS) -o -path \"./$(OUT)\" \) -prune -o -name "*.[ch]" -print))
502+ endif
503+ ifeq ($(SH_FMT ) ,)
504+ $(error shfmt not found. Install shfmt and try again)
505+ else
506+ $(Q)$(shell $(SH_FMT) -w $(shell find . \( $(SUBMODULES_PRUNE_PATHS) -o -path \"./$(OUT)\" \) -prune -o -name "*.sh" -print))
507+ endif
508+ ifeq ($(BLACK ) ,)
509+ $(error black not found. Install black version 25.1.0 or above and try again)
510+ else
511+ $(Q)$(shell $(BLACK) --quiet $(shell find . \( $(SUBMODULES_PRUNE_PATHS) -o -path \"./$(OUT)\" \) -prune -o \( -name "*.py" -o -name "*.pyi" \) -print))
512+ endif
513+ $(Q)$(call notice,All files are properly formatted.)
514+
491515clean :
492516 $(VECHO ) " Cleaning... "
493517 $(Q )$(RM ) $(BIN ) $(OBJS ) $(DEV_OBJS ) $(BUILD_DTB ) $(BUILD_DTB2C ) $(HIST_BIN ) $(HIST_OBJS ) $(deps ) $(WEB_FILES ) $(CACHE_OUT )
You can’t perform that action at this time.
0 commit comments