Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,45 @@ CHECK += check-monitor
HELP_check-monitor = check env if monitor is possible
check-monitor: | check-docker check-dev

### cppcheck target

.PHONY: check-code
TARGET += check-code
ALL += check-code
HELP_check-code = checks code with cppcheck
check-code: | check-docker
@make --no-print-directory -C $(DOCKERDIR) format EXEC=' cppcheck $(FILES) \
--enable=warning,performance,portability,information \
--std=c11 \
--verbose \
--suppress=missingInclude \
--template="[{severity}][{id}] {message} {callstack} (On {file}:{line})"'

### clang-format

.PHONY: format-code
TARGET += format-code
HELP_format-code = formats code with clang-format
format-code: | check-docker
@make --no-print-directory -C $(DOCKERDIR) format \
EXEC="find . \
\( -name \"*.h\" -o -name \"*.c\" \) \
! -path \"*build*\" \
-printf \"formatting %h/%f\n\" \
-exec clang-format-9 -style=file -i \"{}\" \";\" "

.PHONY: check-format
TARGET += check-format
HELP_check-format = check if formatting code with clang-format is necessary
check-format: | check-docker
@make --no-print-directory -C $(DOCKERDIR) format \
EXEC="find . \
\( -name \"*.h\" -o -name \"*.c\" \) \
! -path \"*build*\" \
\( -exec sh -c \" clang-format-9 -style=file {} | diff -q - {} >/dev/null \" \";\" \
-or -printf \"format required for %h/%f\n\" \) \
| tee /tmp/format; test ! -s /tmp/format"

### vscode ###

.PHONY: vscode
Expand Down
127 changes: 127 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: 0
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: All
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: true
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseTab: Never
...

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ This repository features multiple idf projects for different purposes.
* `make monitor`
1. creates idf docker image if needed
2. starts idf docker container to connect to ESP via specified device by `make dev`
6. Static Code analysis
* `make check-code`
1. creates format docker image if needed
2. starts format docker container to run `cppcheck` on all src and header files
7. Code formatting
* `make format-code`
1. creates format docker image if needed
2. starts format docker container to run `clang-format-9` on all src and header files
* via local esd-idf toolchain
1. Choose flavor
* i.e. `cd lifesensor`
Expand Down
37 changes: 37 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ HELP_WORKDIR = Where to enter docker container
WORKDIR=$(shell pwd)/..

### docker build targets ###
.PHONY: format-image
ALL += format-image
DEFAULT += format-image
TARGET_format += format-image
HELP_format-image = builds docker format image
format-image: | check-docker
docker build \
--build-arg=UID=$(UID) \
--build-arg=GID=$(GID) \
-t "lifesensor/format" \
format

.PHONY: idf-image
ALL += idf-image
Expand Down Expand Up @@ -76,6 +87,21 @@ vscode-image: qemu-image | check-docker
vscode

### docker run targets ###
.PHONY: format
TARGET += format
HELP_format = runs formatting container
format: | format-image check-docker
docker run \
--rm \
-ti \
$(DOCKER_DEV) \
-v format-home:/home/developer:rw \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is a persistent home needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we want to change our src files, i think so

Copy link
Contributor

@nopeslide nopeslide Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything that is created in the home directory,
therefore I don't see the necessity.
Did I overlook sth?
If not: also remove the clean-format

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the c and header files are adapted to the style, nothing is created

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the files this container modifies are mounted and have nothing to do with the container home dir. the other docker containers feature a persistent home for custom configs and caches of the toolchain (i.e. ccache, .gdbinit, ...). this is not needed in this case (why customize the format style?), hence my initial question.

-v "$(shell pwd)/..:$(shell pwd)/..:rw" \
-w "$(shell pwd)/.." \
--hostname format \
$(DOCKEROPTS) \
lifesensor/format \
/bin/bash -ic '$(EXEC)'

.PHONY: idf
TARGET += idf
Expand Down Expand Up @@ -133,6 +159,11 @@ code vscode: | vscode-image check-docker
/bin/bash -ic '$(EXEC)'

### docker remove volume targets ###
.PHONY: clean-format
CLEAN += clean-format
HELP_clean-format = removes format volume
clean-format:
-docker volume rm format-home

.PHONY: clean-idf
CLEAN += clean-idf
Expand All @@ -153,6 +184,12 @@ clean-vscode:
-docker volume rm vscode-home

### docker remove image targets ###
.PHONY: distclean-format
DISTCLEAN += distclean-format
HELP_distclean-format = removes format docker image
distclean-format: clean-format
-docker image remove "lifesensor/format"
docker image prune

.PHONY: distclean-idf
DISTCLEAN += distclean-idf
Expand Down
14 changes: 14 additions & 0 deletions docker/format/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ubuntu:18.04

RUN apt-get update && apt-get install -y cppcheck clang-format-9

ARG UID=1000
ARG GID=1000
RUN groupadd -g $GID -o developer
RUN useradd -m -u $UID -g $GID -s /bin/bash developer
RUN echo "developer ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

WORKDIR /home/developer
USER developer
ENV LC_ALL=C.UTF-8 LANG=C.UTF-8

8 changes: 8 additions & 0 deletions lifesensor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ This directory contains the main build of the project.
* `make monitor`
1. creates idf docker image if needed
2. starts idf docker container to connect to ESP via specified device by `make dev`
6. Static Code analysis
* `make check-code`
1. creates format docker image if needed
2. starts format docker container to run `cppcheck` on all src and header files
7. Code formatting
* `make format-code`
1. creates format docker image if needed
2. starts format docker container to run `clang-format-9` on all src and header files
* via local esd-idf toolchain
2. Building
* `idf.py build`
Expand Down
8 changes: 8 additions & 0 deletions lifesensor_test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ This directory contains a test build of the project, running various unit tests.
* `make monitor`
1. creates idf docker image if needed
2. starts idf docker container to connect to ESP via specified device by `make dev`
6. Static Code analysis
* `make check-code`
1. creates format docker image if needed
2. starts format docker container to run `cppcheck` on all src and header files
7. Code formatting
* `make format-code`
1. creates format docker image if needed
2. starts format docker container to run `clang-format-9` on all src and header files
* via local esd-idf toolchain
2. Building
* `idf.py build`
Expand Down