From 666cc62d6341102a77ffe0b7be0c2830a376c8f9 Mon Sep 17 00:00:00 2001 From: Victor Fusco <1221933+vfusco@users.noreply.github.com> Date: Fri, 22 Mar 2024 12:47:38 -0300 Subject: [PATCH] chore: add lint and format targets --- sys-utils/libcmt/.clang-format | 19 ++++++++++++ sys-utils/libcmt/.clang-tidy | 52 ++++++++++++++++++++++++++++++++ sys-utils/libcmt/.gitignore | 1 + sys-utils/libcmt/Makefile | 55 +++++++++++++++++++++++++++++----- 4 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 sys-utils/libcmt/.clang-format create mode 100644 sys-utils/libcmt/.clang-tidy diff --git a/sys-utils/libcmt/.clang-format b/sys-utils/libcmt/.clang-format new file mode 100644 index 00000000..989c84a2 --- /dev/null +++ b/sys-utils/libcmt/.clang-format @@ -0,0 +1,19 @@ +Language: Cpp +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignOperands: DontAlign +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortFunctionsOnASingleLine: Empty +AlwaysBreakTemplateDeclarations: Yes +BreakInheritanceList: AfterColon +BreakBeforeTernaryOperators: false +BreakConstructorInitializers: AfterColon +ColumnLimit: 120 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +IndentCaseLabels: true +IndentWidth: 4 +SpaceAfterCStyleCast: true +Standard: c++17 diff --git a/sys-utils/libcmt/.clang-tidy b/sys-utils/libcmt/.clang-tidy new file mode 100644 index 00000000..70c7a2ff --- /dev/null +++ b/sys-utils/libcmt/.clang-tidy @@ -0,0 +1,52 @@ +Checks: >- + boost*, + bugprone*, + -bugprone-branch-clone, + -bugprone-easily-swappable-parameters, + cert*, + clang-analyzer*, + cppcoreguidelines*, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-pro-bounds*, + -cppcoreguidelines-pro-type-vararg, + -cppcoreguidelines-avoid-c-arrays, + google-readability-*, + misc*, + -misc-include-cleaner, + -misc-no-recursion, + -misc-non-private-member-variables-in-classes, + -misc-use-anonymous-namespace, + modernize*, + -modernize-redundant-void-arg, + -modernize-use-default-member-init, + -modernize-use-nodiscard, + -modernize-use-trailing-return-type, + -modernize-avoid-c-arrays, + -modernize-use-auto, + performance*, + portability*, + readability*, + -readability-else-after-return, + -readability-function-cognitive-complexity, + -readability-implicit-bool-conversion, + -readability-identifier-length, + -readability-magic-numbers, + -readability-named-parameter, + -readability-redundant-member-init +WarningsAsErrors: >- + boost*, + bugprone*, + cert*, + clang-analyzer*, + cppcoreguidelines*, + google*, + misc*, + modernize*, + performance*, + portability*, + readability* +CheckOptions: + - key: performance-move-const-arg.CheckTriviallyCopyableMove + value: 'false' diff --git a/sys-utils/libcmt/.gitignore b/sys-utils/libcmt/.gitignore index 895dab3f..811ea164 100644 --- a/sys-utils/libcmt/.gitignore +++ b/sys-utils/libcmt/.gitignore @@ -1 +1,2 @@ compile_flags.txt +*/*.clang-tidy* diff --git a/sys-utils/libcmt/Makefile b/sys-utils/libcmt/Makefile index a3d95aac..0588fd34 100644 --- a/sys-utils/libcmt/Makefile +++ b/sys-utils/libcmt/Makefile @@ -24,9 +24,8 @@ TARGET_AR := $(TOOLCHAIN_PREFIX)ar TARGET_CFLAGS := -Wvla -O2 -g -Wall -pedantic -Wextra -Isrc CFLAGS := -Wvla -O2 -g -Wall -pedantic -Wextra -Isrc -ALL := libcmt mock tools test doc -all: $(ALL) - +all: libcmt host +host: mock tools test #------------------------------------------------------------------------------- examples_SRC := \ doc/examples/abi_encode_000.c \ @@ -165,11 +164,47 @@ $(tools_OBJDIR)/funsel: tools/funsel.c $(mock_LIB) tools: $(tools_BINS) +#------------------------------------------------------------------------------- +LINTER_IGNORE_SOURCES=src/io.c +LINTER_IGNORE_HEADERS= +LINTER_SOURCES=$(filter-out $(LINTER_IGNORE_SOURCES),$(strip $(wildcard src/*.c) $(wildcard tests/*.c) $(wildcard tools/*.c))) +LINTER_HEADERS=$(filter-out $(LINTER_IGNORE_HEADERS),$(strip $(wildcard src/*.h))) + +CLANG_TIDY=clang-tidy +CLANG_TIDY_TARGETS=$(patsubst %.c,%.clang-tidy,$(LINTER_SOURCES)) + +CLANG_FORMAT=clang-format +CLANG_FORMAT_FILES:=$(wildcard src/*.c) $(wildcard src/*.h) $(wildcard tests/*.c) $(wildcard tools/*.c) +CLANG_FORMAT_IGNORE_FILES:= +CLANG_FORMAT_FILES:=$(strip $(CLANG_FORMAT_FILES)) +CLANG_FORMAT_FILES:=$(filter-out $(CLANG_FORMAT_IGNORE_FILES),$(strip $(CLANG_FORMAT_FILES))) + +EMPTY:= +SPACE:=$(EMPTY) $(EMPTY) +CLANG_TIDY_HEADER_FILTER=$(CURDIR)/($(subst $(SPACE),|,$(LINTER_HEADERS))) + +%.clang-tidy: %.c + @$(CLANG_TIDY) --header-filter='$(CLANG_TIDY_HEADER_FILTER)' $< -- $(CFLAGS) 2>/dev/null + @$(CC) $(CFLAGS) $< -MM -MT $@ -MF $@.d > /dev/null 2>&1 + @touch $@ + +clangd-config: + @echo "$(CFLAGS)" | sed -e $$'s/ \{1,\}/\\\n/g' | grep -v "MMD" > compile_flags.txt + +format: + @$(CLANG_FORMAT) -i $(CLANG_FORMAT_FILES) + +check-format: + @$(CLANG_FORMAT) -Werror --dry-run $(CLANG_FORMAT_FILES) + +lint: $(CLANG_TIDY_TARGETS) + #------------------------------------------------------------------------------- help: @echo "Targets: (default: '*')" - @echo "* all - $(ALL)" + @echo "* all - Build libcmt and host targets" + @echo " host - Build mock, tools and test targets" @echo " libcmt - Build the library, tools and examples; to run on the cartesi-machine." @echo " (requires the cartesi Linux headers to build)" @echo " mock - Build a mocked version of the library, tools and examples; to run on the host system." @@ -190,10 +225,14 @@ doc: doc/theme examples doxygen doc/Doxyfile clean: - rm -rf build - -clangd-config: - @echo "$(CFLAGS)" | sed -e $$'s/ \{1,\}/\\\n/g' | grep -v "MMD" > compile_flags.txt + @rm -rf build + @rm -rf src/*.clang-tidy src/*.d + @rm -rf tests/*.clang-tidy tests/*.d + @rm -rf tools/*.clang-tidy tools/*.d + +distclean: clean + @rm -rf doc/html doc/theme + @rm -rf compile_flags.txt OBJ := $(mock_OBJ) $(libcmt_OBJ) $(examples_OBJ) $(tools_OBJ)