Skip to content

Commit 3b6997f

Browse files
authored
chore: Add boilerplate CMake project and Taskfile tasks to lint CMake files. (#12)
1 parent 16b2700 commit 3b6997f

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

.gersemirc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# yamllint disable-line rule:line-length
2+
# yaml-language-server: $schema=https://raw.githubusercontent.com/BlankSpruce/gersemi/master/gersemi/configuration.schema.json
3+
4+
line_length: 100
5+
list_expansion: "favour-expansion"

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cmake_minimum_required(VERSION 3.16.3)
2+
project(YSTDLIB_CPP LANGUAGES CXX)
3+
4+
set(YSTDLIB_CPP_VERSION "0.0.1" CACHE STRING "Project version.")

lint-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
colorama>=0.4.6
2+
gersemi>=0.16.2
13
yamllint>=1.35.1

taskfiles/lint-cmake.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: "3"
2+
3+
tasks:
4+
cmake-check:
5+
desc: "Runs the CMake linters."
6+
sources: &cmake_format_src_files
7+
- "{{.ROOT_DIR}}/**/*.cmake"
8+
- "{{.ROOT_DIR}}/**/*.cmake.in"
9+
- "{{.ROOT_DIR}}/**/CMakeLists.txt"
10+
- "{{.TASKFILE}}"
11+
- exclude: "{{.ROOT_DIR}}/**/build/*"
12+
- exclude: "{{.ROOT_DIR}}/**/submodules/*"
13+
- exclude: "{{.ROOT_DIR}}/**/tools/*"
14+
cmds:
15+
- task: "gersemi"
16+
vars:
17+
FLAGS: "--diff --color"
18+
- task: "gersemi"
19+
silent: true
20+
vars:
21+
FLAGS: "--check"
22+
23+
cmake-fix:
24+
desc: "Runs the CMake linters and fixes all violations."
25+
sources: *cmake_format_src_files
26+
cmds:
27+
- task: "gersemi"
28+
vars:
29+
FLAGS: "--in-place"
30+
31+
gersemi:
32+
internal: true
33+
requires:
34+
vars:
35+
- "FLAGS"
36+
dir: "{{.ROOT_DIR}}"
37+
deps:
38+
- "venv"
39+
cmds:
40+
- |-
41+
. "{{.G_LINT_VENV_DIR}}/bin/activate"
42+
find . \
43+
\( -path '**/build' -o -path '**/submodules' -o -path '**/tools' \) -prune -o \
44+
\( -iname "CMakeLists.txt" -o -iname "*.cmake" -o -iname "*.cmake.in" \) \
45+
-print0 | \
46+
xargs -0 --no-run-if-empty gersemi {{.FLAGS}}

taskfiles/lint.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
version: "3"
22

33
includes:
4+
cmake:
5+
flatten: true
6+
taskfile: "./lint-cmake.yaml"
47
yaml:
58
flatten: true
69
taskfile: "./lint-yaml.yaml"
@@ -13,11 +16,13 @@ tasks:
1316
check:
1417
desc: "Runs the full suite of linters to identify warnings and violations."
1518
cmds:
19+
- task: "cmake-check"
1620
- task: "yaml-check"
1721

1822
fix:
1923
desc: "Runs the full suite of linters and fixes some violations."
2024
cmds:
25+
- task: "cmake-fix"
2126
- task: "yaml-fix"
2227

2328
venv:
@@ -31,6 +36,7 @@ tasks:
3136
- "lint-requirements.txt"
3237
generates:
3338
- "{{.CHECKSUM_FILE}}"
39+
run: "once"
3440
deps:
3541
- ":init"
3642
- task: ":utils:validate-checksum"

0 commit comments

Comments
 (0)