Skip to content

Commit

Permalink
Refactory clang-tidy plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldolsribeiro committed Sep 24, 2024
1 parent fb2a4dc commit b633510
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 110 deletions.
17 changes: 12 additions & 5 deletions .microCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,25 @@ steps:
- [ 'yaml', 'new/skip.yml', 'docs/plugin_skip.md' ]
- name: "C++ check with clang-tidy"
network: bridge
only: clang-tidy
plugin:
name: "clang-tidy"
checks:
- "-*"
- "modernize-*"
# - "cppcoreguidelines-*"
# - "hicpp-*"
# - "performance-"
# - "portability-"
# - "readability-"
fix: true
options:
- "-std=c++17"
- "-DFMT_HEADER_ONLY -DSPDLOG_FMT_EXTERNAL=1"
include:
- "/usr/include/"
- "include/"
- "src/"
source:
- "src/*pp"
- "include/*pp"

- "src/*.cpp"
- name: "C++ check with cppcheck"
plugin:
name: "cppcheck"
Expand Down
16 changes: 13 additions & 3 deletions docs/plugin_clang-tidy.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@

```yaml
steps:
- name: "Create C++ code verification report - cppcheck"
- name: "Create C++ code verification report - clang-tidy"
description: "Check C++ code and generate HTML report"
network: bridge # http://clang.llvm.org/extra/clang-tidy/checks/list.html
plugin:
name: "clang-tidy"
checks:
- "-*"
- "cppcoreguidelines-*"
# - "modernize-*"
# - "hicpp-*"
# - "performance-"
# - "portability-"
# - "readability-"
fix: true
options:
- "-std=c++11"
- "-checks='-*,modernize-use-override,modernize-use-nullptr'"
- "-fix"
include:
- "include/"
system_include:
- "/usr/local/include"
- "/usr/include/"
source:
- "src/*.cpp"
Expand Down
2 changes: 1 addition & 1 deletion include/MicroCI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace microci {

using nlohmann::json;

#define microCI_version "0.34.0"
#define microCI_version "0.34.1"

// ----------------------------------------------------------------------
//
Expand Down
96 changes: 60 additions & 36 deletions include/new/clang-tidy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,67 +29,91 @@

// DON'T EDIT THIS FILE, INSTEAD UPDATE ../new/clang-tidy.yml
unsigned char ___new_clang_tidy_yml[] = {
0x23, 0x20, 0x20, 0x20, 0x23, 0x20, 0x63, 0x6c, 0x61, 0x6e, 0x67, 0x2d, 0x74, 0x69, 0x64, 0x79, 0x20, 0x70,
0x6c, 0x75, 0x67, 0x69, 0x6e,
0x23, 0x20, 0x20, 0x20, 0x23, 0x20, 0x63, 0x6c, 0x61, 0x6e, 0x67, 0x2d, 0x74, 0x69, 0x64, 0x79,
0x20, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e,

0x0a, 0x23, 0x20, 0x20, 0x20,

0x0a, 0x23, 0x7b, 0x7b, 0x7b,

0x0a, 0x73, 0x74, 0x65, 0x70, 0x73, 0x3a,

0x0a, 0x20, 0x20, 0x2d, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x20, 0x22, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
0x20, 0x43, 0x2b, 0x2b, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x76, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x20, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x2d, 0x20, 0x63, 0x70, 0x70, 0x63,
0x68, 0x65, 0x63, 0x6b, 0x22,
0x0a, 0x20, 0x20, 0x2d, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x20, 0x22, 0x43, 0x72, 0x65, 0x61,
0x74, 0x65, 0x20, 0x43, 0x2b, 0x2b, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x76, 0x65, 0x72, 0x69,
0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x20,
0x2d, 0x20, 0x63, 0x6c, 0x61, 0x6e, 0x67, 0x2d, 0x74, 0x69, 0x64, 0x79, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20,
0x22, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x43, 0x2b, 0x2b, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x61, 0x6e,
0x64, 0x20, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x48, 0x54, 0x4d, 0x4c, 0x20, 0x72, 0x65,
0x70, 0x6f, 0x72, 0x74, 0x22,
0x0a, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e,
0x3a, 0x20, 0x22, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x43, 0x2b, 0x2b, 0x20, 0x63, 0x6f, 0x64,
0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x48,
0x54, 0x4d, 0x4c, 0x20, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x3a, 0x20, 0x62, 0x72, 0x69, 0x64,
0x67, 0x65, 0x20, 0x23, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x6c, 0x61, 0x6e, 0x67, 0x2e,
0x6c, 0x6c, 0x76, 0x6d, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x65, 0x78, 0x74, 0x72, 0x61, 0x2f, 0x63, 0x6c, 0x61,
0x6e, 0x67, 0x2d, 0x74, 0x69, 0x64, 0x79, 0x2f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x73, 0x2f, 0x6c, 0x69, 0x73,
0x74, 0x2e, 0x68, 0x74, 0x6d, 0x6c,
0x0a, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x3a, 0x20, 0x62, 0x72,
0x69, 0x64, 0x67, 0x65, 0x20, 0x23, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x6c,
0x61, 0x6e, 0x67, 0x2e, 0x6c, 0x6c, 0x76, 0x6d, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x65, 0x78, 0x74,
0x72, 0x61, 0x2f, 0x63, 0x6c, 0x61, 0x6e, 0x67, 0x2d, 0x74, 0x69, 0x64, 0x79, 0x2f, 0x63, 0x68,
0x65, 0x63, 0x6b, 0x73, 0x2f, 0x6c, 0x69, 0x73, 0x74, 0x2e, 0x68, 0x74, 0x6d, 0x6c,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x3a,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x20, 0x22, 0x63, 0x6c, 0x61, 0x6e,
0x67, 0x2d, 0x74, 0x69, 0x64, 0x79, 0x22,
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x20, 0x22, 0x63, 0x6c,
0x61, 0x6e, 0x67, 0x2d, 0x74, 0x69, 0x64, 0x79, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a,
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x73, 0x3a,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x2d, 0x2a, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x63, 0x70, 0x70, 0x63,
0x6f, 0x72, 0x65, 0x67, 0x75, 0x69, 0x64, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x2d, 0x2a, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x23, 0x20, 0x2d, 0x20, 0x22, 0x6d, 0x6f,
0x64, 0x65, 0x72, 0x6e, 0x69, 0x7a, 0x65, 0x2d, 0x2a, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x2d, 0x73, 0x74, 0x64, 0x3d, 0x63,
0x2b, 0x2b, 0x31, 0x31, 0x22,
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x23, 0x20, 0x2d, 0x20, 0x22, 0x68, 0x69,
0x63, 0x70, 0x70, 0x2d, 0x2a, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x2d, 0x63, 0x68, 0x65, 0x63, 0x6b,
0x73, 0x3d, 0x27, 0x2d, 0x2a, 0x2c, 0x6d, 0x6f, 0x64, 0x65, 0x72, 0x6e, 0x69, 0x7a, 0x65, 0x2d, 0x75, 0x73,
0x65, 0x2d, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x2c, 0x6d, 0x6f, 0x64, 0x65, 0x72, 0x6e, 0x69,
0x7a, 0x65, 0x2d, 0x75, 0x73, 0x65, 0x2d, 0x6e, 0x75, 0x6c, 0x6c, 0x70, 0x74, 0x72, 0x27, 0x22,
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x23, 0x20, 0x2d, 0x20, 0x22, 0x70, 0x65,
0x72, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e, 0x63, 0x65, 0x2d, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x2d, 0x66, 0x69, 0x78, 0x22,
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x23, 0x20, 0x2d, 0x20, 0x22, 0x70, 0x6f,
0x72, 0x74, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2d, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x23, 0x20, 0x2d, 0x20, 0x22, 0x72, 0x65,
0x61, 0x64, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2d, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x69, 0x78, 0x3a, 0x20, 0x74, 0x72, 0x75, 0x65,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x2d, 0x73, 0x74, 0x64,
0x3d, 0x63, 0x2b, 0x2b, 0x31, 0x31, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x3a,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x2f, 0x75, 0x73, 0x72, 0x2f, 0x69,
0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x2f, 0x22,
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x69, 0x6e, 0x63, 0x6c,
0x75, 0x64, 0x65, 0x2f, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x5f, 0x69, 0x6e,
0x63, 0x6c, 0x75, 0x64, 0x65, 0x3a,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x2f, 0x75, 0x73, 0x72,
0x2f, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x2f, 0x75, 0x73, 0x72,
0x2f, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x2f, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x3a,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x73, 0x72, 0x63, 0x2f, 0x2a, 0x2e,
0x63, 0x70, 0x70, 0x22,
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x73, 0x72, 0x63, 0x2f,
0x2a, 0x2e, 0x63, 0x70, 0x70, 0x22,

0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x2a,
0x2e, 0x63, 0x70, 0x70, 0x22,
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x20, 0x22, 0x74, 0x65, 0x73, 0x74,
0x2f, 0x2a, 0x2e, 0x63, 0x70, 0x70, 0x22,

0x0a, 0x23, 0x7d, 0x7d, 0x7d,

0x0a, 0x23, 0x20, 0x76, 0x69, 0x6d, 0x3a, 0x20, 0x73, 0x70, 0x65, 0x6c, 0x6c, 0x20, 0x73, 0x70, 0x65, 0x6c,
0x6c, 0x6c, 0x61, 0x6e, 0x67, 0x3d, 0x65, 0x6e,

0x0a,
0x0a, 0x23, 0x20, 0x76, 0x69, 0x6d, 0x3a, 0x20, 0x73, 0x70, 0x65, 0x6c, 0x6c, 0x20, 0x73, 0x70,
0x65, 0x6c, 0x6c, 0x6c, 0x61, 0x6e, 0x67, 0x3d, 0x65, 0x6e,

0x0a};
unsigned int ___new_clang_tidy_yml_len = 531;
unsigned int ___new_clang_tidy_yml_len = 725;
16 changes: 13 additions & 3 deletions new/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@
#
#{{{
steps:
- name: "Create C++ code verification report - cppcheck"
- name: "Create C++ code verification report - clang-tidy"
description: "Check C++ code and generate HTML report"
network: bridge # http://clang.llvm.org/extra/clang-tidy/checks/list.html
plugin:
name: "clang-tidy"
checks:
- "-*"
- "cppcoreguidelines-*"
# - "modernize-*"
# - "hicpp-*"
# - "performance-"
# - "portability-"
# - "readability-"
fix: true
options:
- "-std=c++11"
- "-checks='-*,modernize-use-override,modernize-use-nullptr'"
- "-fix"
include:
- "include/"
system_include:
- "/usr/local/include"
- "/usr/include/"
source:
- "src/*.cpp"
Expand Down
10 changes: 5 additions & 5 deletions new/docker_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
#
#{{{
steps:
- name: "Construir imagem docker"
description: "Descrição deste passo"
- name: "Build docker image"
description: "Builds a docker image"
plugin:
name: docker_build
folder: pasta_que_contem_o_dockerfile
folder: folder_with_dockerfile
dockerfile: alternative.Dockerfile
target: intmain/minha_imagem
target: intmain/my_image
version: 0.1.0
is_latest: true
push: false
#}}}

# vim: spell spelllang=pt,en
# vim: spell spelllang=en

24 changes: 21 additions & 3 deletions src/ClangTidyPluginStepParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ void ClangTidyPluginStepParser::Parse(const YAML::Node &step) {
auto runAs = string{};
list<string> checkList;
list<string> includeList;
list<string> systemIncludeList;
list<string> sourceList;
list<string> optionList;

data = parseRunAs(step, data, "user");
data = parseNetwork(step, data, "none");

bool fixSourceCode = step["plugin"]["fix"] and step["plugin"]["fix"].as<bool>(false);

if (step["plugin"]["checks"] && step["plugin"]["checks"].IsSequence()) {
for (const auto &inc : step["plugin"]["checks"]) {
checkList.push_back(inc.as<string>());
Expand All @@ -69,6 +72,12 @@ void ClangTidyPluginStepParser::Parse(const YAML::Node &step) {
}
}

if (step["plugin"]["system_include"] && step["plugin"]["system_include"].IsSequence()) {
for (const auto &inc : step["plugin"]["system_include"]) {
systemIncludeList.push_back(inc.as<string>());
}
}

if (step["plugin"]["source"] && step["plugin"]["source"].IsSequence()) {
for (const auto &src : step["plugin"]["source"]) {
sourceList.push_back(src.as<string>());
Expand All @@ -89,12 +98,17 @@ void ClangTidyPluginStepParser::Parse(const YAML::Node &step) {
&& clang-tidy \
)",
data);
for (const auto &src : sourceList) {
mMicroCI->Script() << " " << src << " \\\n";
if (fixSourceCode) {
mMicroCI->Script() << " --fix \\\n";
mMicroCI->Script() << " --fix-errors \\\n";
}

for (const auto &inc : systemIncludeList) {
mMicroCI->Script() << " -isystem" << inc << " \\\n";
}

if (checkList.empty()) {
mMicroCI->Script() << " -checks='*' \\\n";
mMicroCI->Script() << " -checks='-*,cppcoreguidelines-*' \\\n";
} else {
string concatenatedList;
for (const auto &check : checkList) {
Expand All @@ -106,6 +120,10 @@ void ClangTidyPluginStepParser::Parse(const YAML::Node &step) {
mMicroCI->Script() << " -checks='" << concatenatedList << "' \\\n";
}

for (const auto &src : sourceList) {
mMicroCI->Script() << " " << src << " \\\n";
}

if (!optionList.empty() or !includeList.empty()) {
mMicroCI->Script() << " -- \\\n";
}
Expand Down
8 changes: 4 additions & 4 deletions src/DockerBuildPluginStepParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ void DockerBuildPluginStepParser::Parse(const YAML::Node &step) {
auto envs = parseEnvs(step);
data["STEP_NAME"] = stepName(step);
data["FUNCTION_NAME"] = sanitizeName(stepName(step));
data["STEP_DESCRIPTION"] = stepDescription(step, "Constroi imagem docker");
data["STEP_DESCRIPTION"] = stepDescription(step, "Builds a docker image");

auto folder = step["plugin"]["folder"].as<string>("dockerfiles");
auto dockerfile = step["plugin"]["dockerfile"].as<string>("Dockerfile");
auto targetName = step["plugin"]["target"].as<string>("minha_imagem");
auto targetName = step["plugin"]["target"].as<string>("my_image");
auto targetVersion = step["plugin"]["version"].as<string>("0.1.0");
auto isLatest = step["plugin"]["is_latest"].as<bool>(false);
auto isPush = step["plugin"]["push"].as<bool>(false);
auto doPush = step["plugin"]["push"].as<bool>(false);

data["FOLDER"] = folder;
data["TARGET_NAME"] = targetName;
Expand All @@ -69,7 +69,7 @@ void DockerBuildPluginStepParser::Parse(const YAML::Node &step) {
data);
}

if (isPush) {
if (doPush) {
mMicroCI->Script() << inja::render(R"( \
&& docker login 2>&1 \
&& docker push {{ TARGET_NAME }}:{{ VERSION }} 2>&1)",
Expand Down
Loading

0 comments on commit b633510

Please sign in to comment.