aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorlizzie <lizzie@eden-emu.dev>2026-06-04 05:49:07 +0200
committercrueter <crueter@eden-emu.dev>2026-06-04 05:49:07 +0200
commit89199f4d279bff0c664fb9142b1945d0c6d93ee8 (patch)
treef7223e46b4d1ecf0355adc5fc9363bae093dcf89 /tools
parent978d9d935d50fd09af5c6173582b1d63792900bd (diff)
[*] basic in-house cpp linting (#4039)
- add `#pragma once` to remainder files - "correcter" defines (ANDROID), see https://groups.google.com/g/android-ndk/c/cf9_f1SLXls - extra miscelly fixups Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4039 Reviewed-by: MaranBr <maranbr@eden-emu.dev> Reviewed-by: crueter <crueter@eden-emu.dev>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/cpp-lint.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/tools/cpp-lint.sh b/tools/cpp-lint.sh
new file mode 100755
index 0000000000..4c5a6e10dc
--- /dev/null
+++ b/tools/cpp-lint.sh
@@ -0,0 +1,55 @@
+#!/bin/sh -ex
+
+# SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# tools/../
+ROOTDIR=$(CDPATH='' cd -- "$(dirname -- "$0")/../" && pwd)
+BUILD_DIR="$ROOTDIR"/build
+SRC_DIR="$ROOTDIR"/src
+
+die() {
+ echo "-- $*" >&2
+ exit 1
+}
+
+usage() {
+ cat <<EOF
+Usage: $0 [command]
+
+Dumb script that serves as a ad-hoc cpp-linter
+
+Commands:
+ once Check for #pragma once prescence in header files
+ osdef Finds OS defines that are not recommended to use.
+ inchk Check includes being valid/toolchain not being stupid
+EOF
+}
+
+while :; do
+ case "$1" in
+ once)
+ find "$SRC_DIR" -type f -name "*.h" -exec grep -L "#pragma once" {} +
+ break
+ ;;
+ osdef)
+ # not recommended macros
+ PATTERN="ANDROID\|_WIN64\|__linux\|__unix\|APPLE\|__APPLE"
+ strings=("ANDROID" "_WIN64" "__linux" "__unix" "APPLE" "__APPLE" "linux" "unix")
+ for item in "${strings[@]}"; do
+ PATTERN="$PATTERN\|ifdef $item\|($item)"
+ done
+ # if statements for macros that shouldn't be if
+ strings=("_WIN32" "_AIX" "__managarm__" "__unix__" "__linux__" "__FreeBSD__" "__NetBSD__" \
+ "__OpenBSD__" "__DragonFly__" "__redox__" "__HAIKU__" "__OHOS__" "__FIREOS__")
+ for item in "${strings[@]}"; do
+ PATTERN="$PATTERN\|if $item"
+ done
+ find "$SRC_DIR" -type f -name "*.h" -exec grep -nw "$PATTERN" {} + || echo
+ break
+ ;;
+ *) usage ;;
+ esac
+
+ shift
+done