diff options
-rw-r--r-- | .editorconfig | 35 | ||||
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | 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 <lukeshu@lukeshu.com> # 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 @@ -5,6 +5,9 @@ *.o *.log +*.tmp .mypy_cache/ build/ + +/.sources.mk @@ -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; /^<!--$$/d; /-\*- .* -\*-/d; s,[/*# ]*,,; s/ - .*//;p; q; }' $$filename); \ - filename_alt1=$$(echo "$$filename" | sed \ - -e 's,^cmd/,,' \ - -e 's,.*/include/,,' \ - -e 's,^lib9p/idl/,,' \ - -e 's/\.wip$$//'); \ - filename_alt2=$$(echo "$$filename_alt1" | sed \ - -e 's,^sbc_harness/hw/,hw/,'); \ - [ "$$dscname" == "$$filename" ] || [ "$$dscname" == "$$filename_alt1" ] || [ "$$dscname" == "$$filename_alt2" ] || \ - { echo "$$filename self-identifies as $$dscname"; r=1; continue; }; \ - done; exit $$r + $(MAKE) -k $(patsubst sources_%,lint/%,$(filter sources_%,$(.VARIABLES))) +lint/sh lint/bash: lint/%: + shellcheck $(sources_$*) +lint/python3: lint/%: + mypy --strict --scripts-are-modules $(sources_$*) + black --check $(sources_$*) + isort --check $(sources_$*) +lint/c: lint/%: + @: TODO +lint/make lint/cmake lint/gitignore lint/ini lint/9p lint/markdown: lint/%: + @: +lint/unknown: lint/%: + @printf "%s: cannot lint unknown file type\n" $(sources_$*) >&2 +lint/all: lint/%: + $(eval export sources_$*) + @find $$(printf '%s\n' $${sources_$*} | grep -vE '^cmd/[^/]+/static/') \ + -maxdepth 0 -type f | \ + { r=0; while read -r filename; do \ + if ! grep -q 'Copyright (C) 2024 Luke T. Shumaker' $$filename; then \ + echo "$$filename is missing a copyright statement"; r=1; continue; \ + fi; \ + dscname=$$(sed -n '1,3{ /^#!/d; /^<!--$$/d; /-\*- .* -\*-/d; s,[/*# ]*,,; s/ - .*//;p; q; }' $$filename); \ + filename_alt1=$$(echo "$$filename" | sed \ + -e 's,^cmd/,,' \ + -e 's,.*/include/,,' \ + -e 's,^lib9p/idl/,,' \ + -e 's/\.wip$$//'); \ + filename_alt2=$$(echo "$$filename_alt1" | sed \ + -e 's,^sbc_harness/hw/,hw/,'); \ + if ! { [ "$$dscname" == "$$filename" ] || [ "$$dscname" == "$$filename_alt1" ] || [ "$$dscname" == "$$filename_alt2" ]; }; then \ + echo "$$filename self-identifies as $$dscname"; r=1; continue; \ + fi; \ + done; exit $$r; } +.PHONY: lint lint/% + +# format ########### format: - black $(sources_py) - isort $(sources_py) -.PHONY: lint format + $(MAKE) -k $(patsubst sources_%,format/%,$(filter-out sources_all,$(filter sources_%,$(.VARIABLES)))) +format/python3: format/%: + black $(sources_$*) + isort $(sources_$*) +format/sh format/bash: format/% + @: +format/c: format/%: + @: TODO +format/make format/cmake format/gitignore format/ini format/9p format/markdown: format/%: + @: +format/unknown: format/%: + @: +.PHONY: format format/% |