From 318162fdf1ff86297afcce334f61d2d6ff5e3345 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sun, 20 Oct 2024 13:56:08 -0600 Subject: Makefile: Use editorconfig for lint/format --- .editorconfig | 35 ++++++++++++++++++++++- .gitignore | 3 ++ Makefile | 91 +++++++++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 103 insertions(+), 26 deletions(-) diff --git a/.editorconfig b/.editorconfig index fa5f176..2aa13e7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,4 @@ -# .editorconfig - How files in sbc_harness should be formatted +# .editorconfig - How files in sbc-harness should be formatted # # Copyright (C) 2024 Luke T. Shumaker # SPDX-Licence-Identifier: AGPL-3.0-or-later @@ -6,8 +6,41 @@ root = true [*] +# Custom (sbc-harness) options for scripting +_mode = unknown +# Standard (editorconfig.org) options charset = utf-8 end_of_line = lf indent_style = tab insert_final_newline = true trim_trailing_whitespace = true + +[*.{c,h}] +_mode = c + +[Makefile] +_mode = make + +[{CMakeLists.txt,*.cmake}] +_mode = cmake + +[*.md] +_mode = markdown + +[*.9p{,.wip}] +_mode = 9p + +[{3rd-party/linux-errno.txt.gen,cmd/srv9p/static.h.gen}] +_mode = sh + +[libusb/include/libusb/tusb_helpers.h.gen] +_mode = bash + +[{lib9p/idl.gen,lib9p/include/lib9p/linux-errno.h.gen}] +_mode = python3 + +[{.editorconfig,.gitmodules}] +_mode = ini + +[.gitignore] +_mode = gitignore diff --git a/.gitignore b/.gitignore index 9729c27..964c5aa 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ *.o *.log +*.tmp .mypy_cache/ build/ + +/.sources.mk diff --git a/Makefile b/Makefile index a89ec25..d0c5c78 100644 --- a/Makefile +++ b/Makefile @@ -50,30 +50,71 @@ generate-clean: rm -f -- $(generate/files) .PHONY: generate-clean -sources_sh = 3rd-party/linux-errno.txt.gen -sources_sh += libusb/include/libusb/tusb_helpers.h.gen -sources_py = lib9p/idl.gen -sources_py += lib9p/include/lib9p/linux-errno.h.gen +################################################################################ + +.PHONY: FORCE + +# List of sources, by type. +.sources.mk: $(if $(wildcard .git),FORCE) + git ls-files | grep -vFx $(foreach f,$(generate/files),-e $f) \ + | sed 's,^,$(CURDIR)/,' | xargs editorconfig \ + | sed -nE -e 's,\[$(CURDIR)/(.*)\],\1,p' -e 's/^_mode=//p' \ + | sed -E '{N;s/(.*)\n(.*)/sources_\2 += \1/;}' \ + | sort \ + >$@.tmp + if ! cmp -s $@.tmp $@; then mv $@.tmp $@; fi +-include .sources.mk +sources_all := $(foreach v,$(filter sources_%,$(.VARIABLES)),$($v)) + +# lint ############# lint: - shellcheck $(sources_sh) - mypy --strict --scripts-are-modules $(sources_py) - black --check $(sources_py) - isort --check $(sources_py) - r=0; find $$(git ls-files -- $(foreach f,$(generate/files),:!$f) :!cmd/*/static/*) -maxdepth 0 -type f | while read -r filename; do \ - grep -q 'Copyright (C) 2024 Luke T. Shumaker' $$filename || \ - { echo "$$filename is missing a copyright statement"; r=1; continue; }; \ - dscname=$$(sed -n '1,3{ /^#!/d; /^