Skip to content

Commit c5ee5ec

Browse files
committed
Add scripts/README.md
1 parent 2e75419 commit c5ee5ec

File tree

5 files changed

+416
-93
lines changed

5 files changed

+416
-93
lines changed

scripts/README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Local Scripts
2+
3+
## Local Linters
4+
5+
Run all linters on codebase example:
6+
7+
```shell
8+
$ scripts/lint.sh -h
9+
Usage: scripts/lint-all.sh
10+
-h, --help: Display help.
11+
-a, --all: Lint all files.
12+
-c, --cpp: Lint C++ files.
13+
-s, --shell: Lint shell scripts.
14+
-m, --markdown: Lint Markdown files.
15+
-y, --yaml: Lint YAML files.
16+
-C, --cmake: Lint CMake files.
17+
18+
$ scripts/lint.sh --all
19+
Checking linters...
20+
-> clang-format...
21+
-> shellcheck...
22+
-> cmake-format...
23+
-> markdownlint...
24+
-> yamlfmt...
25+
Checking linters finished: all linters installed.
26+
27+
Linting C++ files...
28+
Done.
29+
30+
Linting shell files...
31+
Done.
32+
33+
Linting CMake files...
34+
Done.
35+
36+
Linting Markdown files...
37+
Done.
38+
39+
Linting YAML files...
40+
Done.
41+
```
42+
43+
## Local Run Tests
44+
45+
Run all tests on codebase example:
46+
47+
```shell
48+
$ scripts/run-tests.sh
49+
Usage: scripts/run-tests.sh
50+
-h, --help: Display help.
51+
-v, --verbose: Display verbose output.
52+
-f, --fresh: Run tests on a fresh build directory.
53+
-p, --preset: Run tests on a specific toolchain. Default: all
54+
Available presets: gcc-14 gcc-13 clang-19 clang-18 clang-17
55+
56+
$ scripts/run-tests.sh --preset gcc-18
57+
Testing with etc/gcc-18-toolchain.cmake...
58+
Running: config
59+
-> config successful
60+
Running: build
61+
-> build successful
62+
Running: tests
63+
-> tests passed
64+
Done.
65+
66+
$ scripts/run-tests.sh --preset all
67+
Testing with etc/gcc-14-toolchain.cmake...
68+
Running: config
69+
-> config successful
70+
Running: build
71+
-> build successful
72+
Running: tests
73+
-> tests passed
74+
Testing with etc/gcc-13-toolchain.cmake...
75+
Running: config
76+
-> config successful
77+
Running: build
78+
-> build successful
79+
Running: tests
80+
-> tests passed
81+
Testing with etc/clang-19-toolchain.cmake...
82+
Running: config
83+
-> config successful
84+
Running: build
85+
-> build successful
86+
Running: tests
87+
-> tests passed
88+
Testing with etc/clang-18-toolchain.cmake...
89+
Running: config
90+
-> config successful
91+
Running: build
92+
-> build successful
93+
Running: tests
94+
-> tests passed
95+
Testing with etc/clang-17-toolchain.cmake...
96+
Running: config
97+
-> config successful
98+
Running: build
99+
-> build successful
100+
Running: tests
101+
-> tests passed
102+
Done.
103+
```

scripts/lint-all.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ BASE_DIRS=(
1717
)
1818

1919
# Print usage information.
20-
function usage() {
20+
function print_usage() {
2121
echo "Usage: $0"
2222
echo " -h, --help: Display help."
2323
echo " -a, --all: Lint all files."
@@ -33,7 +33,7 @@ function parse_args() {
3333
while [[ $# -gt 0 ]]; do
3434
case $1 in
3535
-h|--help)
36-
usage
36+
print_usage
3737
exit 0
3838
;;
3939
-a|--all)
@@ -62,7 +62,7 @@ function parse_args() {
6262
;;
6363
*)
6464
echo "Unknown option: $1"
65-
usage
65+
print_usage
6666
exit 1
6767
;;
6868
esac

scripts/lint.sh

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/bin/bash
2+
3+
# scripts/lint.sh -*-shell-*-
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
# Lint all files in the project.
7+
# Expected to be run from the root of the project.
8+
# Expected tools to be installed on the system. A pre-check is done to ensure all tools are installed.
9+
10+
set -e
11+
12+
# Base directories to lint.
13+
BASE_DIRS=(
14+
include
15+
examples
16+
scripts
17+
src
18+
)
19+
20+
# Print usage information.
21+
function print_usage() {
22+
echo "Usage: $0"
23+
echo " -h, --help: Display help."
24+
echo " -a, --all: Lint all files."
25+
echo " -c, --cpp: Lint C++ files."
26+
echo " -s, --shell: Lint shell scripts."
27+
echo " -m, --markdown: Lint Markdown files."
28+
echo " -y, --yaml: Lint YAML files."
29+
echo " -C, --cmake: Lint CMake files."
30+
}
31+
32+
# Parse command line arguments.
33+
function parse_args() {
34+
while [[ $# -gt 0 ]]; do
35+
case $1 in
36+
-h|--help)
37+
print_usage
38+
exit 0
39+
;;
40+
-a|--all)
41+
lint_all_files
42+
exit 0
43+
;;
44+
-c|--cpp)
45+
lint_cpp_files
46+
exit 0
47+
;;
48+
-s|--shell)
49+
lint_shell_files
50+
exit 0
51+
;;
52+
-m|--markdown)
53+
lint_markdown_files
54+
exit 0
55+
;;
56+
-y|--yaml)
57+
lint_yaml_files
58+
exit 0
59+
;;
60+
-C|--cmake)
61+
lint_cmake_files
62+
exit 0
63+
;;
64+
*)
65+
echo "Unknown option: $1"
66+
print_usage
67+
exit 1
68+
;;
69+
esac
70+
done
71+
}
72+
73+
# Check if all linters are installed.
74+
function check_linters_installed() {
75+
echo "Checking linters..."
76+
linters=(
77+
clang-format
78+
shellcheck
79+
cmake-format
80+
markdownlint
81+
yamlfmt
82+
)
83+
84+
for linter in "${linters[@]}"; do
85+
echo " -> ${linter}..."
86+
if ! command -v "${linter}" &> /dev/null; then
87+
echo "${linter} could not be found."
88+
exit 1
89+
fi
90+
done
91+
echo "Checking linters finished: all linters installed."
92+
echo ""
93+
}
94+
95+
# Lint all C++ files in the project.
96+
function lint_cpp_files() {
97+
echo "Linting C++ files..."
98+
99+
CPP_DIRS=(
100+
"${BASE_DIRS[@]}"
101+
)
102+
find -E "${CPP_DIRS[@]}" -regex '.*\.(h|hpp|hxx|cpp|c|cxx)' | xargs clang-format -i -style=file || echo "clang-format failed."
103+
104+
echo "Done."
105+
echo ""
106+
}
107+
108+
# Lint all shell files in the project.
109+
function lint_shell_files() {
110+
echo "Linting shell files..."
111+
112+
SHELL_DIRS=(
113+
"${BASE_DIRS[@]}"
114+
)
115+
find -E "${SHELL_DIRS[@]}" -regex '.*\.(sh)' | xargs shellcheck || echo "shellcheck failed."
116+
117+
echo "Done."
118+
echo ""
119+
}
120+
121+
# Lint all CMake files in the project.
122+
function lint_cmake_files() {
123+
echo "Linting CMake files..."
124+
125+
CMAKE_DIRS=(
126+
CMakeLists.txt
127+
"${BASE_DIRS[@]}"
128+
cmake
129+
)
130+
find -E "${CMAKE_DIRS[@]}" -regex '.*CMakeLists\.txt' | xargs cmake-format -i || echo "cmake-format failed."
131+
132+
echo "Done."
133+
echo ""
134+
}
135+
136+
# Lint all Markdown files in the project.
137+
function lint_markdown_files() {
138+
echo "Linting Markdown files..."
139+
140+
MD_DIRS=(
141+
README.md
142+
"${BASE_DIRS[@]}"
143+
papers/P2988/README.md
144+
)
145+
find -E "${MD_DIRS[@]}" -regex '.*\.(md)' | xargs markdownlint -f || echo "markdownlint failed."
146+
147+
echo "Done."
148+
echo ""
149+
}
150+
151+
# Lint all YAML files in the project.
152+
function lint_yaml_files() {
153+
echo "Linting YAML files..."
154+
155+
YAML_DIRS=(
156+
.github/
157+
"${BASE_DIRS[@]}"
158+
)
159+
find -E "${YAML_DIRS[@]}" -regex '.*\.(yml)' | xargs yamlfmt || echo "yamlfmt failed."
160+
161+
echo "Done."
162+
echo ""
163+
}
164+
165+
# Lint all files in the project.
166+
function lint_all_files() {
167+
check_linters_installed || exit 1
168+
169+
lint_cpp_files || exit 1
170+
lint_shell_files || exit 1
171+
lint_cmake_files || exit 1
172+
lint_markdown_files || exit 1
173+
lint_yaml_files || exit 1
174+
175+
echo "All linters finished."
176+
}
177+
178+
parse_args "$@"

0 commit comments

Comments
 (0)