summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorReiko Asakura2021-03-13 11:02:55 -0500
committerReiko Asakura2021-03-13 11:02:55 -0500
commitdb45e31fd92dd834c2426a780266d0fb03652e9b (patch)
treec327c6666a2dfeb0382b6c2b4a123011744b4941 /scripts
parentAdd sce_process_preload_disabled flags (diff)
downloadvds-libraries-db45e31fd92dd834c2426a780266d0fb03652e9b.tar.gz
Add lint script for header files
Diffstat (limited to '')
-rw-r--r--scripts/check-header-files.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/scripts/check-header-files.py b/scripts/check-header-files.py
new file mode 100644
index 0000000..c6ee32e
--- /dev/null
+++ b/scripts/check-header-files.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+
+#
+# Copyright (C) 2021 Reiko Asakura. All Rights Reserved.
+#
+# Vita Development Suite Libraries
+#
+
+import sys
+from pathlib import Path
+
+import nids
+
+def check_file(base, f):
+ mode = f.stat().st_mode
+
+ if mode != 0o100644:
+ sys.exit(f'{f} has incorrect permission mode {mode:o}')
+
+ if f.suffix != '.h' or f.stem != Path(f.stem).stem:
+ sys.exit(f'{f} has incorrect file name format')
+
+ text = f.read_bytes().decode()
+
+ if '\r' in text:
+ sys.exit(f'{f} has carriage return')
+
+ if not text.startswith('/*\n\tVita Development Suite Libraries\n*/'):
+ sys.exit(f'{f} has incorrect boilerplate')
+
+ if not text.endswith('\n'):
+ sys.exit(f'{f} does not have trailing line feed')
+
+ include_guard = ('#define _VDSUITE_' + f'{f.relative_to(base)}'
+ .replace('/', '_')
+ .replace('\\', '_')
+ .replace('.', '_')
+ .upper())
+
+ if include_guard not in text:
+ sys.exit(f'{f} has incorrect include guard\n{include_guard}')
+
+nids.iterdir(Path('include'), lambda f: check_file(Path('include'), f))