-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e75419
commit c5ee5ec
Showing
5 changed files
with
416 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Local Scripts | ||
|
||
## Local Linters | ||
|
||
Run all linters on codebase example: | ||
|
||
```shell | ||
$ scripts/lint.sh -h | ||
Usage: scripts/lint-all.sh | ||
-h, --help: Display help. | ||
-a, --all: Lint all files. | ||
-c, --cpp: Lint C++ files. | ||
-s, --shell: Lint shell scripts. | ||
-m, --markdown: Lint Markdown files. | ||
-y, --yaml: Lint YAML files. | ||
-C, --cmake: Lint CMake files. | ||
|
||
$ scripts/lint.sh --all | ||
Checking linters... | ||
-> clang-format... | ||
-> shellcheck... | ||
-> cmake-format... | ||
-> markdownlint... | ||
-> yamlfmt... | ||
Checking linters finished: all linters installed. | ||
|
||
Linting C++ files... | ||
Done. | ||
|
||
Linting shell files... | ||
Done. | ||
|
||
Linting CMake files... | ||
Done. | ||
|
||
Linting Markdown files... | ||
Done. | ||
|
||
Linting YAML files... | ||
Done. | ||
``` | ||
|
||
## Local Run Tests | ||
|
||
Run all tests on codebase example: | ||
|
||
```shell | ||
$ scripts/run-tests.sh | ||
Usage: scripts/run-tests.sh | ||
-h, --help: Display help. | ||
-v, --verbose: Display verbose output. | ||
-f, --fresh: Run tests on a fresh build directory. | ||
-p, --preset: Run tests on a specific toolchain. Default: all | ||
Available presets: gcc-14 gcc-13 clang-19 clang-18 clang-17 | ||
|
||
$ scripts/run-tests.sh --preset gcc-18 | ||
Testing with etc/gcc-18-toolchain.cmake... | ||
Running: config | ||
-> config successful | ||
Running: build | ||
-> build successful | ||
Running: tests | ||
-> tests passed | ||
Done. | ||
|
||
$ scripts/run-tests.sh --preset all | ||
Testing with etc/gcc-14-toolchain.cmake... | ||
Running: config | ||
-> config successful | ||
Running: build | ||
-> build successful | ||
Running: tests | ||
-> tests passed | ||
Testing with etc/gcc-13-toolchain.cmake... | ||
Running: config | ||
-> config successful | ||
Running: build | ||
-> build successful | ||
Running: tests | ||
-> tests passed | ||
Testing with etc/clang-19-toolchain.cmake... | ||
Running: config | ||
-> config successful | ||
Running: build | ||
-> build successful | ||
Running: tests | ||
-> tests passed | ||
Testing with etc/clang-18-toolchain.cmake... | ||
Running: config | ||
-> config successful | ||
Running: build | ||
-> build successful | ||
Running: tests | ||
-> tests passed | ||
Testing with etc/clang-17-toolchain.cmake... | ||
Running: config | ||
-> config successful | ||
Running: build | ||
-> build successful | ||
Running: tests | ||
-> tests passed | ||
Done. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
#!/bin/bash | ||
|
||
# scripts/lint.sh -*-shell-*- | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
# Lint all files in the project. | ||
# Expected to be run from the root of the project. | ||
# Expected tools to be installed on the system. A pre-check is done to ensure all tools are installed. | ||
|
||
set -e | ||
|
||
# Base directories to lint. | ||
BASE_DIRS=( | ||
include | ||
examples | ||
scripts | ||
src | ||
) | ||
|
||
# Print usage information. | ||
function print_usage() { | ||
echo "Usage: $0" | ||
echo " -h, --help: Display help." | ||
echo " -a, --all: Lint all files." | ||
echo " -c, --cpp: Lint C++ files." | ||
echo " -s, --shell: Lint shell scripts." | ||
echo " -m, --markdown: Lint Markdown files." | ||
echo " -y, --yaml: Lint YAML files." | ||
echo " -C, --cmake: Lint CMake files." | ||
} | ||
|
||
# Parse command line arguments. | ||
function parse_args() { | ||
while [[ $# -gt 0 ]]; do | ||
case $1 in | ||
-h|--help) | ||
print_usage | ||
exit 0 | ||
;; | ||
-a|--all) | ||
lint_all_files | ||
exit 0 | ||
;; | ||
-c|--cpp) | ||
lint_cpp_files | ||
exit 0 | ||
;; | ||
-s|--shell) | ||
lint_shell_files | ||
exit 0 | ||
;; | ||
-m|--markdown) | ||
lint_markdown_files | ||
exit 0 | ||
;; | ||
-y|--yaml) | ||
lint_yaml_files | ||
exit 0 | ||
;; | ||
-C|--cmake) | ||
lint_cmake_files | ||
exit 0 | ||
;; | ||
*) | ||
echo "Unknown option: $1" | ||
print_usage | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
} | ||
|
||
# Check if all linters are installed. | ||
function check_linters_installed() { | ||
echo "Checking linters..." | ||
linters=( | ||
clang-format | ||
shellcheck | ||
cmake-format | ||
markdownlint | ||
yamlfmt | ||
) | ||
|
||
for linter in "${linters[@]}"; do | ||
echo " -> ${linter}..." | ||
if ! command -v "${linter}" &> /dev/null; then | ||
echo "${linter} could not be found." | ||
exit 1 | ||
fi | ||
done | ||
echo "Checking linters finished: all linters installed." | ||
echo "" | ||
} | ||
|
||
# Lint all C++ files in the project. | ||
function lint_cpp_files() { | ||
echo "Linting C++ files..." | ||
|
||
CPP_DIRS=( | ||
"${BASE_DIRS[@]}" | ||
) | ||
find -E "${CPP_DIRS[@]}" -regex '.*\.(h|hpp|hxx|cpp|c|cxx)' | xargs clang-format -i -style=file || echo "clang-format failed." | ||
|
||
echo "Done." | ||
echo "" | ||
} | ||
|
||
# Lint all shell files in the project. | ||
function lint_shell_files() { | ||
echo "Linting shell files..." | ||
|
||
SHELL_DIRS=( | ||
"${BASE_DIRS[@]}" | ||
) | ||
find -E "${SHELL_DIRS[@]}" -regex '.*\.(sh)' | xargs shellcheck || echo "shellcheck failed." | ||
|
||
echo "Done." | ||
echo "" | ||
} | ||
|
||
# Lint all CMake files in the project. | ||
function lint_cmake_files() { | ||
echo "Linting CMake files..." | ||
|
||
CMAKE_DIRS=( | ||
CMakeLists.txt | ||
"${BASE_DIRS[@]}" | ||
cmake | ||
) | ||
find -E "${CMAKE_DIRS[@]}" -regex '.*CMakeLists\.txt' | xargs cmake-format -i || echo "cmake-format failed." | ||
|
||
echo "Done." | ||
echo "" | ||
} | ||
|
||
# Lint all Markdown files in the project. | ||
function lint_markdown_files() { | ||
echo "Linting Markdown files..." | ||
|
||
MD_DIRS=( | ||
README.md | ||
"${BASE_DIRS[@]}" | ||
papers/P2988/README.md | ||
) | ||
find -E "${MD_DIRS[@]}" -regex '.*\.(md)' | xargs markdownlint -f || echo "markdownlint failed." | ||
|
||
echo "Done." | ||
echo "" | ||
} | ||
|
||
# Lint all YAML files in the project. | ||
function lint_yaml_files() { | ||
echo "Linting YAML files..." | ||
|
||
YAML_DIRS=( | ||
.github/ | ||
"${BASE_DIRS[@]}" | ||
) | ||
find -E "${YAML_DIRS[@]}" -regex '.*\.(yml)' | xargs yamlfmt || echo "yamlfmt failed." | ||
|
||
echo "Done." | ||
echo "" | ||
} | ||
|
||
# Lint all files in the project. | ||
function lint_all_files() { | ||
check_linters_installed || exit 1 | ||
|
||
lint_cpp_files || exit 1 | ||
lint_shell_files || exit 1 | ||
lint_cmake_files || exit 1 | ||
lint_markdown_files || exit 1 | ||
lint_yaml_files || exit 1 | ||
|
||
echo "All linters finished." | ||
} | ||
|
||
parse_args "$@" |
Oops, something went wrong.