Skip to content

Commit

Permalink
chore: add lint and format targets
Browse files Browse the repository at this point in the history
  • Loading branch information
vfusco committed Mar 22, 2024
1 parent 8d92ce6 commit 666cc62
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 8 deletions.
19 changes: 19 additions & 0 deletions sys-utils/libcmt/.clang-format
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions sys-utils/libcmt/.clang-tidy
Original file line number Diff line number Diff line change
@@ -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'
1 change: 1 addition & 0 deletions sys-utils/libcmt/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
compile_flags.txt
*/*.clang-tidy*
55 changes: 47 additions & 8 deletions sys-utils/libcmt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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."
Expand All @@ -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)

Expand Down

0 comments on commit 666cc62

Please sign in to comment.