From 00d1961d36a6f8ff4f9a37e6450c683dd940ae3b Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sat, 9 Aug 2025 15:22:30 +0100 Subject: [PATCH] Add scripts for checking formatting, linting etc --- CMakeLists.txt | 2 ++ scripts/build-and-test.sh | 4 ++++ scripts/check-format.sh | 2 ++ scripts/lint.sh | 3 +++ scripts/list-source-files.sh | 6 ++++++ 5 files changed, 17 insertions(+) create mode 100755 scripts/build-and-test.sh create mode 100755 scripts/check-format.sh create mode 100755 scripts/lint.sh create mode 100755 scripts/list-source-files.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index d197524..e66376a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ project(imp LANGUAGES C) option(TESTS "Build tests" ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + function(configure_target target) # Set C standard and compile flags set_target_properties(${target} PROPERTIES diff --git a/scripts/build-and-test.sh b/scripts/build-and-test.sh new file mode 100755 index 0000000..ecf19c8 --- /dev/null +++ b/scripts/build-and-test.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -euo pipefail +cmake --build build +ctest --test-dir build --output-on-failure | grep -v :PASS diff --git a/scripts/check-format.sh b/scripts/check-format.sh new file mode 100755 index 0000000..a6f6ac4 --- /dev/null +++ b/scripts/check-format.sh @@ -0,0 +1,2 @@ +#!/bin/sh +scripts/list-source-files.sh | xargs -n1 clang-format --dry-run --Werror diff --git a/scripts/lint.sh b/scripts/lint.sh new file mode 100755 index 0000000..5e64b2a --- /dev/null +++ b/scripts/lint.sh @@ -0,0 +1,3 @@ +#!/bin/sh +scripts/list-source-files.sh \ + | xargs -n1 clang-tidy -p build --warnings-as-errors='*' diff --git a/scripts/list-source-files.sh b/scripts/list-source-files.sh new file mode 100755 index 0000000..4d27260 --- /dev/null +++ b/scripts/list-source-files.sh @@ -0,0 +1,6 @@ +#!/bin/sh +find . \ + -not \( -path './.git' -prune \) \ + -not \( -path './build' -prune \) \ + -not \( -path './dep' -prune \) \ + -name '*.c' -o -name '*.h'