This GitLab instance will be migrated to gitlab.mel.vin before 2020-06-01 and will lose the shared runners, setup your own runners if needed.

Commit 038c8cc9 authored by Vermeeren's avatar Vermeeren

strip down c template to doc template

v-very big commit, scary!
parent 1068cf00
Pipeline #1488 passed with stages
in 1 minute and 23 seconds
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -8
AlignAfterOpenBracket: DontAlign
AlignEscapedNewlines: DontAlign
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortFunctionsOnASingleLine: None
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
ColumnLimit: 80
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
FixNamespaceComments: false
IndentWidth: 8
JavaScriptQuotes: Single
KeepEmptyLinesAtTheStartOfBlocks: false
ObjCBlockIndentWidth: 8
SpaceAfterTemplateKeyword: false
SpacesInContainerLiterals: false
TabWidth: 8
UseTab: ForContinuationAndIndentation
Checks: '*,-fuchsia-default-arguments,-google-readability-namespace-comments,-hicpp-deprecated-headers,-llvm-header-guard,-llvm-namespace-comment,-modernize-deprecated-headers'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
FormatStyle: file
CheckOptions:
- key: bugprone-argument-comment.StrictMode
value: '1'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '2'
- key: hicpp-braces-around-statements.ShortStatementLines
value: '2'
- key: misc-misplaced-widening-cast.CheckImplicitCasts
value: '1'
- key: misc-suspicious-enum-usage.StrictMode
value: '1'
- key: misc-suspicious-string-compare.WarnOnImplicitComparison
value: '0'
- key: misc-suspicious-string-compare.WarnOnLogicalNotComparison
value: '0'
- key: modernize-loop-convert.NamingStyle
value: lower_case
- key: readability-braces-around-statements.ShortStatementLines
value: '2'
- key: readability-identifier-naming.NamespaceCase
value: lower_case
- key: readability-identifier-naming.InlineNamespaceCase
value: lower_case
- key: readability-identifier-naming.EnumConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.ConstexprVariableCase
value: UPPER_CASE
- key: readability-identifier-naming.ConstantMemberCase
value: lower_case
- key: readability-identifier-naming.PrivateMemberCase
value: lower_case
- key: readability-identifier-naming.ProtectedMemberCase
value: lower_case
- key: readability-identifier-naming.PublicMemberCase
value: lower_case
- key: readability-identifier-naming.MemberCase
value: lower_case
- key: readability-identifier-naming.ClassConstantCase
value: lower_case
- key: readability-identifier-naming.ClassMemberCase
value: lower_case
- key: readability-identifier-naming.GlobalConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.GlobalVariableCase
value: lower_case
- key: readability-identifier-naming.LocalConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.LocalVariableCase
value: lower_case
- key: readability-identifier-naming.StaticConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.StaticVariableCase
value: lower_case
- key: readability-identifier-naming.ConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.VariableCase
value: lower_case
- key: readability-identifier-naming.ConstantParameterCase
value: lower_case
- key: readability-identifier-naming.ParameterPackCase
value: lower_case
- key: readability-identifier-naming.ParameterCase
value: lower_case
- key: readability-identifier-naming.AbstractClassCase
value: lower_case
- key: readability-identifier-naming.StructCase
value: lower_case
- key: readability-identifier-naming.ClassCase
value: lower_case
- key: readability-identifier-naming.UnionCase
value: lower_case
- key: readability-identifier-naming.EnumCase
value: lower_case
- key: readability-identifier-naming.GlobalFunctionCase
value: lower_case
- key: readability-identifier-naming.ConstexprFunctionCase
value: lower_case
- key: readability-identifier-naming.FunctionCase
value: lower_case
- key: readability-identifier-naming.ConstexprMethodCase
value: lower_case
- key: readability-identifier-naming.VirtualMethodCase
value: lower_case
- key: readability-identifier-naming.ClassMethodCase
value: lower_case
- key: readability-identifier-naming.PrivateMethodCase
value: lower_case
- key: readability-identifier-naming.ProtectedMethodCase
value: lower_case
- key: readability-identifier-naming.PublicMethodCase
value: lower_case
- key: readability-identifier-naming.MethodCase
value: lower_case
- key: readability-identifier-naming.TypedefCase
value: lower_case
- key: readability-identifier-naming.TypeTemplateParameterCase
value: lower_case
- key: readability-identifier-naming.ValueTemplateParameterCase
value: lower_case
- key: readability-identifier-naming.TemplateTemplateParameterCase
value: lower_case
- key: readability-identifier-naming.TemplateParameterCase
value: lower_case
- key: readability-identifier-naming.TypeAliasCase
value: lower_case
- key: readability-identifier-naming.MacroDefinitionCase
value: UPPER_CASE
- key: readability-implicit-bool-conversion.AllowIntegerConditions
value: '1'
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: '1'
- key: readability-simplify-boolean-expr.ChainedConditionalAssignment
value: '1'
- key: readability-simplify-boolean-expr.ChainedConditionalReturn
value: '1'
/build/
/build_*/
/include/*/version.h
stages:
- analyse
- build
- test
- doc
- deploy
variables:
GIT_SUBMODULE_STRATEGY: normal
clang_format:
stage: analyse
allow_failure: true
image: git.mel.vin:5005/template/c/cicd/clang_tools:1.1
script:
- mkdir build
- cd build
- cmake -DCODE:BOOL=OFF -DFORMAT:BOOL=ON -DWERROR:BOOL=ON ..
- make format_check
clang_tidy:
stage: analyse
allow_failure: true
image: git.mel.vin:5005/template/c/cicd/clang_tools:1.1
script:
- mkdir build
- cd build
- cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DCLANG_TIDY:BOOL=ON -DTEST:BOOL=ON
-DWERROR:BOOL=ON ..
- make -j $(nproc)
doxygen:
stage: analyse
allow_failure: true
image: git.mel.vin:5005/template/c/cicd/doxygen:1.1
script:
- mkdir build
- cd build
- cmake -DCODE:BOOL=OFF -DDOC:STRING=doxygen -DWERROR:BOOL=ON ..
- make doc
line_limit:
stage: analyse
allow_failure: true
......@@ -46,7 +13,7 @@ line_limit:
script:
- mkdir build
- cd build
- cmake -DCODE:BOOL=OFF -DLINE_LIMIT:BOOL=ON -DWERROR:BOOL=ON ..
- cmake -DDOC:BOOL=OFF -DLINE_LIMIT:BOOL=ON -DWERROR:BOOL=ON ..
- make line_limit
regex_check:
......@@ -56,67 +23,17 @@ regex_check:
script:
- mkdir build
- cd build
- cmake -DCODE:BOOL=OFF -DREGEX_CHECK:BOOL=ON -DWERROR:BOOL=ON ..
- cmake -DDOC:BOOL=OFF -DREGEX_CHECK:BOOL=ON -DWERROR:BOOL=ON ..
- make regex_check
clang:
stage: build
only:
- master
image: git.mel.vin:5005/template/c/cicd/clang:1.1
script:
- mkdir build
- cd build
- cmake ..
- make -j $(nproc)
gcc:
stage: build
only:
- master
image: git.mel.vin:5005/template/c/cicd/gcc:1.1
script:
- mkdir build
- cd build
- cmake ..
- make -j $(nproc)
clang_sanitise:
stage: test
image: git.mel.vin:5005/template/c/cicd/clang_tools:1.1
script:
- mkdir build
- cd build
- cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DSANITISE:BOOL=ON -DTEST:BOOL=ON
-DWERROR:BOOL=ON ..
- make -j $(nproc)
- make test
gcc_coverage:
stage: test
image: git.mel.vin:5005/template/c/cicd/gcc_coverage:1.1
coverage: '/^ *lines\.+: (\d+\.\d+\%) \(\d+ of \d+ lines\)$/'
script:
- mkdir build
- cd build
- cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DCOVERAGE:BOOL=ON -DTEST:BOOL=ON
-DWERROR:BOOL=ON ..
- make -j $(nproc)
- make test
- make coverage_report
artifacts:
paths:
- build/coverage_report
sphinx_html:
stage: doc
dependencies: []
image: git.mel.vin:5005/template/c/cicd/sphinx_html:1.2
image: git.mel.vin:5005/template/doc/cicd/sphinx_html:1.0
script:
- mkdir build
- cd build
- cmake -DCODE:BOOL=OFF -DDOC:STRING=html -DWERROR:BOOL=ON ..
- make doc
- cmake -DWERROR:BOOL=ON ..
- make
artifacts:
paths:
- build/doc/html
......@@ -126,14 +43,13 @@ review:
variables:
GIT_STRATEGY: none
only:
- branches@template/c
- branches@template/doc
dependencies:
- gcc_coverage
- sphinx_html
image: git.mel.vin:5005/template/c/cicd/coreutils:1.1
environment:
name: review/$CI_COMMIT_REF_NAME
url: https://doc.mel.vin/template/c/$CI_ENVIRONMENT_SLUG
url: https://doc.mel.vin/template/doc/$CI_ENVIRONMENT_SLUG
on_stop: review_stop
script:
- mkdir -p ~/.ssh
......@@ -141,8 +57,7 @@ review:
- eval $(ssh-agent)
- echo "$DOC_SSH_KEY" | ssh-add - >/dev/null
- mv build/doc/html public
- mv build/coverage_report public/coverage
- rsync -a --delete public/ doc@mel.vin:~/template/c/$CI_ENVIRONMENT_SLUG
- rsync -a --delete public/ doc@mel.vin:~/template/doc/$CI_ENVIRONMENT_SLUG
review_stop:
stage: deploy
......@@ -161,7 +76,7 @@ review_stop:
- echo "$DOC_SSH_KEY" | ssh-add - >/dev/null
- mkdir /tmp/empty
- rsync -a --delete --filter="+ $CI_ENVIRONMENT_SLUG" --filter='-,p *'
/tmp/empty/ doc@mel.vin:~/template/c
/tmp/empty/ doc@mel.vin:~/template/doc
- rmdir /tmp/empty
pages:
......@@ -169,14 +84,12 @@ pages:
variables:
GIT_STRATEGY: none
only:
- tags@template/c
- tags@template/doc
dependencies:
- gcc_coverage
- sphinx_html
image: git.mel.vin:5005/template/c/cicd/coreutils:1.1
script:
- mv build/doc/html public
- mv build/coverage_report public/coverage
artifacts:
paths:
- public
# 3.8.2 required for CMAKE_CXX_STANDARD 17
# 3.8.2 required because template/c requires it
cmake_minimum_required(VERSION 3.8.2 FATAL_ERROR)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
......@@ -11,34 +11,18 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
endif()
# options
option(CLANG_TIDY "Check code with clang-tidy." OFF)
option(CODE "Build primary libraries and executables." ON)
option(COVERAGE "Instrument code with coverage flags." OFF)
option(FORMAT "Add \"format\" target which runs clang-format." OFF)
option(FLAWFINDER "Add \"flawfinder\" target which checks code." OFF)
option(LINE_LIMIT "Check files with line_limit." OFF)
option(REGEX_CHECK "Check files with regex_check." OFF)
option(SANITISE "Add -fsanitize=address and -fsanitize=undefined flags." OFF)
option(TEST "Build unit and functional tests." OFF)
option(WERROR "Make all warnings into errors." OFF)
if(NOT DEFINED DOC)
set(DOC OFF CACHE STRING
set(DOC html CACHE STRING
"The documentation type to generate." FORCE)
endif()
# disable base languages
unset(PROJECT_LANGUAGES)
if(${CODE})
set(PROJECT_LANGUAGES ${PROJECT_LANGUAGES} C)
endif()
# test framework requires c++
if(${TEST})
set(PROJECT_LANGUAGES ${PROJECT_LANGUAGES} CXX)
endif()
project(c_template
project(doc_template
VERSION 1.6.0
DESCRIPTION "__DESCRIPTION__"
LANGUAGES ${PROJECT_LANGUAGES})
......@@ -53,26 +37,11 @@ foreach (prefix "" "CMAKE_")
endforeach(prefix)
string(TOUPPER "${PROJECT_NAME}" PROJECT_NAME_UPPER)
include(version)
include(version_header)
if(${CODE})
include(code)
elseif(${CLANG_TIDY} OR ${COVERAGE} OR ${SANITISE} OR ${TEST})
message(FATAL_ERROR "At least one flag enabled that requires CODE=ON.")
endif()
if(NOT DOC STREQUAL "OFF")
add_subdirectory(doc)
endif()
if(${FORMAT})
include(clang_format)
endif()
if(${FLAWFINDER})
include(flawfinder)
endif()
if(${LINE_LIMIT})
include(line_limit)
endif()
......@@ -81,6 +50,6 @@ if(${REGEX_CHECK})
include(regex_check)
endif()
if(${LINE_LIMIT} OR ${REGEX_CHECK} OR ${FLAWFINDER} OR ${FORMAT})
if(${LINE_LIMIT} OR ${REGEX_CHECK})
include(check)
endif()
# C Template
# Doc Template
Magical template for C projects, improves quality of life.
Magical template for documentation projects, improves quality of life.
Released into the public domain so you don't have to bother with crediting this.
A list of software used can be found in this file. For absolute minimum
requirements for build steps refer to `cicd/docker_targets/*/bootstrap.sh`.
Further details and diagrams are provided in the generated sphinx/doxygen-based
html documentation:
* [Latest release tag](https://template.doc.mel.vin/c)
* [Development version](https://doc.mel.vin/template/c/review-master-sm85pj)
Further details and diagrams are provided in the generated sphinx-based html
documentation:
* [Latest release tag](https://template.doc.mel.vin/doc)
* [Development version](https://doc.mel.vin/template/doc/review-master-3x73j2)
The official project home and all official mirrors:
* Home: https://git.mel.vin/template/c
* GitLab: https://gitlab.com/melvinvermeeren/template\_c
* GitHub: https://github.com/melvinvermeeren/template\_c
## Code
* a nice directory layout that is easily extended
* [clang-format](https://clang.llvm.org/docs/ClangFormat.html)
* relieves reviewers of trashing you yet again
## Analyse
* [clang-tidy](https://clang.llvm.org/extra/clang-tidy/)
* both in-depth analysis of code and style enforcement
* [flawfinder](https://www.dwheeler.com/flawfinder/)
* prevent embarrassing security flaws which the GDPR will fine you for
* Home: https://git.mel.vin/template/doc
* GitLab: https://gitlab.com/melvinvermeeren/template\_doc
* GitHub: https://github.com/melvinvermeeren/template\_doc
## Build
* [cmake](https://cmake.org/)
* simplified complicated build system
* [gcc](https://gcc.gnu.org/)
* blessed, holy grail C/C++ compiler
* [clang](https://clang.llvm.org/)
* fruity C/C++ compiler for when GPLv3 scares you
## Test
* [Catch2](https://github.com/catchorg/Catch2)
* easy-to-use header-only unit testing framework
* [gcov](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html)
* instrument code for coverage, with freedom
* [llvm-cov](https://llvm.org/docs/CommandGuide/llvm-cov.html)
* like gcov, but with less enforced freedom
* [lcov](http://ltp.sourceforge.net/coverage/lcov.php)
* generate beautiful html-based coverage reports
## Documentation
* a nice directory layout that is easily extended
* [Doxygen](https://www.stack.nl/~dimitri/doxygen/)
* for technical API documentation in source code
* [Sphinx](http://www.sphinx-doc.org/en/stable/)
* for all other documentation in wonderful reStructuredText
* [Breathe](https://github.com/michaeljones/breathe)
* breathes in doxygen and exhales reStructuredText
## CI CD
......@@ -69,14 +40,6 @@ The official project home and all official mirrors:
## Tips
* [perf](https://perf.wiki.kernel.org/index.php/Main_Page)
* efficient profiler, requires Linux kernel
* [hotspot](https://github.com/KDAB/hotspot)
* useful GUI for perf
* [heaptrack](https://github.com/KDE/heaptrack)
* heap memory profiler, requires Linux kernel
* [valgrind](http://valgrind.org/)
* still useful for undefined behaviour and data-race checking at times
* [spacevim](http://spacevim.org/)
* the brilliant cult again creates the superior user experience
* [spacemacs](http://spacemacs.org/)
......
FROM alpine:latest
ADD bootstrap.sh /
RUN /bootstrap.sh && rm /bootstrap.sh
git.mel.vin:5005/template/c/cicd/clang:1.1
#!/bin/sh
set -e
apk --no-cache add \
binutils \
clang \
cmake \
g++ \
gcc \
git \
libc-dev \
make
ln -s /usr/bin/clang /usr/local/bin/cc
ln -s /usr/bin/clang++ /usr/local/bin/c++
FROM debian:buster
ADD bootstrap.sh /
RUN /bootstrap.sh && rm /bootstrap.sh
git.mel.vin:5005/template/c/cicd/clang_tools:1.1
#!/bin/sh
CATCH=2.2.3
CLANG=6.0
set -e
apt-get update
apt-get install --no-install-recommends -y \
binutils \
ca-certificates \
clang-$CLANG \
clang-format-$CLANG \
clang-tidy-$CLANG \
cmake \
curl \
git \
make
mkdir -p /usr/local/include/catch
curl -Lf \
-o /usr/local/include/catch/catch.hpp \
https://git.mel.vin/mirror/catch/raw/v$CATCH/catch/catch.hpp
apt-get purge -y \
curl
apt-get autoremove -y
apt-get clean
rm -rf /var/lib/apt/lists/*
ln -s /usr/bin/clang-$CLANG /usr/local/bin/cc
ln -s /usr/bin/clang++-$CLANG /usr/local/bin/c++
ln -s /usr/bin/clang-format-$CLANG /usr/local/bin/clang-format
ln -s /usr/bin/clang-tidy-$CLANG /usr/local/bin/clang-tidy
FROM alpine:latest
ADD bootstrap.sh /
RUN /bootstrap.sh && rm /bootstrap.sh
git.mel.vin:5005/template/c/cicd/doxygen:1.1
#!/bin/sh
set -e
apk --no-cache add \
cmake \
doxygen \
git \
graphviz \
make
FROM alpine:latest
ADD bootstrap.sh /
RUN /bootstrap.sh && rm /bootstrap.sh
git.mel.vin:5005/template/c/cicd/gcc:1.1
#!/bin/sh
set -e
apk --no-cache add \
binutils \
cmake \
gcc \
git \
libc-dev \
make
# lcov will land in 3.8, so use edge for now
FROM alpine:edge
ADD bootstrap.sh /
RUN /bootstrap.sh && rm /bootstrap.sh
git.mel.vin:5005/template/c/cicd/gcc_coverage:1.1
#!/bin/sh
CATCH=2.2.3
set -e
echo 'http://dl-cdn.alpinelinux.org/alpine/edge/testing' \
>> /etc/apk/repositories
apk --no-cache add \
binutils \
cmake \
g++ \
gcc \
git \
lcov \
libc-dev \
make
apk --no-cache add -t tmp \
curl
mkdir -p /usr/local/include/catch
curl -Lf \
-o /usr/local/include/catch/catch.hpp \
https://git.mel.vin/mirror/catch/raw/v$CATCH/catch/catch.hpp
apk --no-cache del tmp
git.mel.vin:5005/template/c/cicd/sphinx_html:1.2
git.mel.vin:5005/template/doc/cicd/sphinx_html:1.0
......@@ -20,7 +20,6 @@ apk --no-cache add -t tmp \
curl
pip install \
breathe \
sphinx \
sphinx_rtd_theme \
sphinxcontrib-plantuml
......
if(BREATHE_APIDOC_FOUND)
return()
endif()
find_program(BREATHE_APIDOC_PATH
NAMES breathe-apidoc
DOC "Path to breathe-apidoc.")
if(NOT BREATHE_APIDOC_PATH)
message(FATAL_ERROR "Could not find breathe-apidoc.")
endif()
set(BREATHE_APIDOC_FOUND ON CACHE BOOL "Found breathe-apidoc.")
mark_as_advanced(BREATHE_APIDOC_FOUND)
message(STATUS "Found breathe-apidoc: ${BREATHE_APIDOC_PATH}")
find_path(CATCH_INCLUDE_DIR
NAMES catch/catch.hpp
DOC "Path to Catch as in <catch/catch.hpp>.")
if(NOT CATCH_INCLUDE_DIR)
message(FATAL_ERROR "Could not find Catch.")
endif()
message(STATUS "Found Catch include dir: ${CATCH_INCLUDE_DIR}")
......@@ -8,11 +8,3 @@ endif()
if(${REGEX_CHECK})
add_dependencies(check regex_check)
endif()
if(${FLAWFINDER})
add_dependencies(check flawfinder)
endif()
if(${FORMAT})
add_dependencies(check format_check)
endif()
find_program(CLANG_FORMAT_PATH
NAMES clang-format
DOC "Path to clang-format.")
if(NOT CLANG_FORMAT_PATH)
message(FATAL_ERROR "Could not find clang-format.")
endif()
message(STATUS "Found clang-format: ${CLANG_FORMAT_PATH}")
add_custom_target(format
COMMENT "Formatting source code"
COMMAND ./cicd/clang_format.sh format "${CLANG_FORMAT_PATH}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
add_custom_target(format_check
COMMENT "Running format check"
COMMAND WERROR=${WERROR} ./cmake/format_check.sh
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
find_program(CLANG_TIDY_PATH
NAMES clang-tidy
DOC "Path to clang-tidy.")
if(NOT CLANG_TIDY_PATH)
message(FATAL_ERROR "Could not find clang-tidy.")
endif()
message(STATUS "Found clang-tidy: ${CLANG_TIDY_PATH}")
set(OPT "${CLANG_TIDY_PATH}")
if(${WERROR})