Skip to content

Commit ff4ddcf

Browse files
committed
CI: Use cmake-lint
1 parent 22da247 commit ff4ddcf

29 files changed

+366
-298
lines changed

.cmake-format.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
parse: {}
2+
format:
3+
line_width: 227
4+
tab_size: 2
5+
use_tabchars: false
6+
fractional_tab_policy: use-space
7+
max_subgroups_hwrap: 2
8+
max_pargs_hwrap: 6
9+
max_rows_cmdline: 2
10+
separate_ctrl_name_with_space: false
11+
separate_fn_name_with_space: false
12+
dangle_parens: false
13+
dangle_align: prefix
14+
min_prefix_chars: 4
15+
max_prefix_chars: 10
16+
max_lines_hwrap: 2
17+
line_ending: unix
18+
command_case: canonical
19+
keyword_case: unchanged
20+
always_wrap: []
21+
enable_sort: true
22+
autosort: false
23+
require_valid_layout: false
24+
layout_passes: {}
25+
markup:
26+
bullet_char: '*'
27+
enum_char: .
28+
first_comment_is_literal: false
29+
literal_comment_pattern: null
30+
fence_pattern: ^\s*([`~]{3}[`~]*)(.*)$
31+
ruler_pattern: ^\s*[^\w\s]{3}.*[^\w\s]{3}$
32+
explicit_trailing_pattern: '#<'
33+
hashruler_min_length: 10
34+
canonicalize_hashrulers: true
35+
enable_markup: true
36+
lint:
37+
disabled_codes:
38+
- C0103 # Invalid argument name
39+
- C0113 # Missing COMMENT in statement which allows it
40+
- C0111 # Missing docstring on function or macro declaration
41+
function_pattern: '[0-9a-z_]+'
42+
macro_pattern: '[0-9A-Z_]+'
43+
global_var_pattern: '[A-Z][0-9A-Z_]+'
44+
internal_var_pattern: _[A-Z][0-9A-Z_]+
45+
local_var_pattern: '[a-z][a-z0-9_]+'
46+
private_var_pattern: _[0-9a-z_]+
47+
public_var_pattern: '[A-Z][0-9A-Z_]+'
48+
argument_var_pattern: '[a-z][a-z0-9_]+'
49+
keyword_pattern: '[A-Z][0-9A-Z_]+'
50+
max_conditionals_custom_parser: 2
51+
min_statement_spacing: 1
52+
max_statement_spacing: 2
53+
max_returns: 6
54+
max_branches: 30 # Default target: 12
55+
max_arguments: 6 # Default target: 5
56+
max_localvars: 15
57+
max_statements: 103 # Default target: 50
58+
encode:
59+
emit_byteorder_mark: false
60+
input_encoding: utf-8
61+
output_encoding: utf-8
62+
misc:
63+
per_command: {}

.github/workflows/lint.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ on:
99
pull_request:
1010
jobs:
1111
lint:
12-
name: Test
12+
name: Lint
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v2
1616
- name: Setup
17-
run: pip install trim
17+
run: pip install trim cmakelang
1818

1919
- name: Check whitespace
2020
run: |
2121
trim *.cmake
2222
git diff --exit-code
23+
24+
- name: Lint cmake files
25+
run: |
26+
cmake-lint *.cmake

ClangFormat.cmake

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ function(create_clang_format_targets)
9898
add_custom_target(clang-format-all-${PROJECT_NAME}
9999
COMMAND ${x_ALL_COMMAND}
100100
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
101-
)
101+
)
102102
add_custom_target(clang-format-diff-${PROJECT_NAME}
103103
COMMAND ${x_DIFF_COMMAND}
104104
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
105-
)
105+
)
106106

107107
# Top level projects will create the targets clang-format-all and
108108
# clang-format-diff with the same commands as the namespaced targets
@@ -112,21 +112,21 @@ function(create_clang_format_targets)
112112
add_custom_target(clang-format-all
113113
COMMAND ${x_ALL_COMMAND}
114114
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
115-
)
115+
)
116116
add_custom_target(clang-format-diff
117117
COMMAND ${x_DIFF_COMMAND}
118118
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
119-
)
119+
)
120120
add_custom_target(clang-format-all-check
121121
COMMAND git diff --exit-code
122122
DEPENDS clang-format-all
123123
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
124-
)
124+
)
125125
add_custom_target(clang-format-diff-check
126126
COMMAND git diff --exit-code
127127
DEPENDS clang-format-diff
128128
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
129-
)
129+
)
130130
endif()
131131
endfunction()
132132

@@ -184,7 +184,7 @@ function(swift_setup_clang_format)
184184
TOP_LEVEL ${top_level_project}
185185
ALL_COMMAND ${x_SCRIPT} all
186186
DIFF_COMMAND ${x_SCRIPT} diff
187-
)
187+
)
188188
else()
189189
message(FATAL_ERROR "Specified clang-format script ${x_SCRIPT} doesn't exist")
190190
endif()
@@ -202,7 +202,7 @@ function(swift_setup_clang_format)
202202
TOP_LEVEL ${top_level_project}
203203
ALL_COMMAND ${script} all
204204
DIFF_COMMAND ${script} diff
205-
)
205+
)
206206
return()
207207
endif()
208208
endforeach()
@@ -221,7 +221,7 @@ function(swift_setup_clang_format)
221221
clang-format35 clang-format-3.5
222222
clang-format34 clang-format-3.4
223223
clang-format
224-
)
224+
)
225225
endif()
226226
find_program(CLANG_FORMAT NAMES ${x_CLANG_FORMAT_NAMES})
227227

ClangTidy.cmake

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ function(create_clang_tidy_targets)
107107
clang-tidy-all-${PROJECT_NAME}
108108
COMMAND ${x_ALL_COMMAND}
109109
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
110-
)
110+
)
111111
add_custom_target(
112112
clang-tidy-diff-${PROJECT_NAME}
113113
COMMAND ${x_DIFF_COMMAND}
114114
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
115-
)
115+
)
116116

117117
# Top level projects will create the targets clang-tidy-all and
118118
# clang-tidy-diff with the same commands as the namespaced targets
@@ -123,22 +123,22 @@ function(create_clang_tidy_targets)
123123
clang-tidy-all
124124
COMMAND ${x_ALL_COMMAND}
125125
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
126-
)
126+
)
127127
add_custom_target(
128128
clang-tidy-diff
129129
COMMAND ${x_DIFF_COMMAND}
130130
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
131-
)
131+
)
132132
add_custom_target(clang-tidy-all-check
133133
COMMAND test ! -f fixes.yaml
134134
DEPENDS clang-tidy-all
135135
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
136-
)
136+
)
137137
add_custom_target(clang-tidy-diff-check
138138
COMMAND test ! -f fixes.yaml
139139
DEPENDS clang-tidy-diff
140140
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
141-
)
141+
)
142142
endif()
143143
endfunction()
144144

@@ -234,7 +234,7 @@ function(swift_setup_clang_tidy)
234234
TOP_LEVEL ${top_level_project}
235235
ALL_COMMAND ${x_SCRIPT} all
236236
DIFF_COMMAND ${x_SCRIPT} diff
237-
)
237+
)
238238
return()
239239
endif()
240240
message(FATAL_ERROR "Specified clang-tidy script ${x_SCRIPT} doesn't exist")
@@ -250,7 +250,7 @@ function(swift_setup_clang_tidy)
250250
TOP_LEVEL ${top_level_project}
251251
ALL_COMMAND ${script} all
252252
DIFF_COMMAND ${script} diff
253-
)
253+
)
254254
return()
255255
endif()
256256
endforeach()
@@ -269,7 +269,7 @@ function(swift_setup_clang_tidy)
269269
clang-tidy35 clang-tidy-3.5
270270
clang-tidy34 clang-tidy-3.4
271271
clang-tidy
272-
)
272+
)
273273
endif()
274274
find_program(CLANG_TIDY NAMES ${x_CLANG_TIDY_NAMES})
275275

@@ -303,6 +303,6 @@ function(swift_setup_clang_tidy)
303303
git diff --diff-filter=ACMRTUXB --quiet --name-only master -- ${srcs} ||
304304
${${PROJECT_NAME}_CLANG_TIDY} ${x_EXTRA_ARGS} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes.yaml
305305
`git diff --diff-filter=ACMRTUXB --name-only master -- ${srcs}`
306-
)
306+
)
307307
endif()
308308
endfunction()

CodeCoverage.cmake

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ option(
9393

9494
# Programs
9595
if (NOT LLVM_COV_PATH)
96-
if (NOT LLVM_COV_NAME)
97-
set(LLVM_COV_NAME llvm-cov)
98-
endif()
99-
find_program(LLVM_COV_PATH ${LLVM_COV_NAME})
96+
if (NOT LLVM_COV_NAME)
97+
set(LLVM_COV_NAME llvm-cov)
98+
endif()
99+
find_program(LLVM_COV_PATH ${LLVM_COV_NAME})
100100
endif()
101101
find_program(GCOV_PATH gcov)
102102
find_program(LCOV_PATH lcov)
@@ -134,8 +134,8 @@ if(CODE_COVERAGE AND NOT CODE_COVERAGE_ADDED)
134134
if(LLVM_COV_VERSION VERSION_LESS "7.0.0")
135135
message(
136136
WARNING
137-
"target_code_coverage()/add_code_coverage_all_targets() 'EXCLUDE' option only available on llvm-cov >= 7.0.0"
138-
)
137+
"target_code_coverage()/add_code_coverage_all_targets() 'EXCLUDE' option only available on llvm-cov >= 7.0.0"
138+
)
139139
endif()
140140
endif()
141141

@@ -156,14 +156,14 @@ if(CODE_COVERAGE AND NOT CODE_COVERAGE_ADDED)
156156
if(NOT ${upper_build_type} STREQUAL "DEBUG")
157157
message(
158158
WARNING
159-
"Code coverage results with an optimized (non-Debug) build may be misleading"
160-
)
159+
"Code coverage results with an optimized (non-Debug) build may be misleading"
160+
)
161161
endif()
162162
else()
163163
message(
164164
WARNING
165-
"Code coverage results with an optimized (non-Debug) build may be misleading"
166-
)
165+
"Code coverage results with an optimized (non-Debug) build may be misleading"
166+
)
167167
endif()
168168
if(NOT LCOV_PATH)
169169
message(FATAL_ERROR "lcov not found! Aborting...")
@@ -336,7 +336,7 @@ function(target_code_coverage TARGET_NAME)
336336
COMMAND ;
337337
COMMENT
338338
"Open ${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/${TARGET_NAME}/index.html in your browser to view the coverage report."
339-
)
339+
)
340340

341341
# AUTO
342342
if(target_code_coverage_AUTO)
@@ -359,8 +359,8 @@ function(target_code_coverage TARGET_NAME)
359359
if(NOT TARGET ccov-all-processing)
360360
message(
361361
FATAL_ERROR
362-
"Calling target_code_coverage with 'ALL' must be after a call to 'add_code_coverage_all_targets'."
363-
)
362+
"Calling target_code_coverage with 'ALL' must be after a call to 'add_code_coverage_all_targets'."
363+
)
364364
endif()
365365

366366
add_dependencies(ccov-all-processing ccov-run-${TARGET_NAME})
@@ -403,13 +403,13 @@ function(add_code_coverage_all_targets)
403403
${ARGN})
404404

405405
if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME})
406-
# This is the top level project, ie the CMakeLists.txt which cmake was run
407-
# on directly, not a submodule/subproject. We can do some special things now.
408-
# The option to enable code coverage will be enabled by default only for
409-
# top level projects.
410-
set(TOP_LEVEL_PROJECT ON)
406+
# This is the top level project, ie the CMakeLists.txt which cmake was run
407+
# on directly, not a submodule/subproject. We can do some special things now.
408+
# The option to enable code coverage will be enabled by default only for
409+
# top level projects.
410+
set(TOP_LEVEL_PROJECT ON)
411411
else()
412-
set(TOP_LEVEL_PROJECT OFF)
412+
set(TOP_LEVEL_PROJECT OFF)
413413
endif()
414414

415415
if(CODE_COVERAGE AND TOP_LEVEL_PROJECT)
@@ -501,6 +501,6 @@ function(add_code_coverage_all_targets)
501501
COMMAND ;
502502
COMMENT
503503
"Open ${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/all-merged/index.html in your browser to view the coverage report."
504-
)
504+
)
505505
endif()
506506
endfunction()

0 commit comments

Comments
 (0)