ci: Add an errno.h check to CI
Add a very simple check that verifies that new error numbers are added
according to the errno.h file in newlib, in order to maintain
compatibility with it.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
diff --git a/.github/workflows/errno.yml b/.github/workflows/errno.yml
new file mode 100644
index 0000000..3e6beff
--- /dev/null
+++ b/.github/workflows/errno.yml
@@ -0,0 +1,20 @@
+name: Error numbers
+on:
+ pull_request:
+ paths:
+ - 'lib/libc/minimal/include/errno.h'
+
+jobs:
+ check-errno:
+ runs-on: ubuntu-latest
+ container:
+ image: zephyrprojectrtos/ci:v0.17.1
+
+ steps:
+ - name: checkout
+ uses: actions/checkout@v2
+
+ - name: Run errno.py
+ run: |
+ export ZEPHYR_BASE=${PWD}
+ ./scripts/ci/errno.py
diff --git a/scripts/ci/errno.py b/scripts/ci/errno.py
new file mode 100755
index 0000000..a7d0063
--- /dev/null
+++ b/scripts/ci/errno.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2021 Nordic Semiconductor NA
+#
+# SPDX-License-Identifier: Apache-2.0
+
+"""Check minimal libc error numbers against newlib.
+
+This script loads the errno.h included in Zephyr's minimal libc and checks its
+contents against the SDK's newlib errno.h. This is done to ensure that both C
+libraries are aligned at all times.
+"""
+
+
+import os
+from pathlib import Path
+import re
+import sys
+
+def parse_errno(path):
+ with open(path, 'r') as f:
+ r = re.compile(r'^\s*#define\s+([A-Z]+)\s+([0-9]+)')
+ errnos = []
+ for line in f:
+ m = r.match(line)
+ if m:
+ errnos.append(m.groups())
+
+ return errnos
+
+def main():
+
+ minimal = Path("lib/libc/minimal/include/errno.h")
+ newlib = Path("arm-zephyr-eabi/arm-zephyr-eabi/include/sys/errno.h")
+
+ try:
+ minimal = os.environ['ZEPHYR_BASE'] / minimal
+ newlib = os.environ['ZEPHYR_SDK_INSTALL_DIR'] / newlib
+ except KeyError as e:
+ print(f'Environment variable missing: {e}', file=sys.stderr)
+ sys.exit(1)
+
+ minimal = parse_errno(minimal)
+ newlib = parse_errno(newlib)
+
+ for e in minimal:
+ if e[0] not in [x[0] for x in newlib] or e[1] != next(
+ filter(lambda _e: _e[0] == e[0], newlib))[1]:
+ print('Invalid entry in errno.h:', file=sys.stderr)
+ print(f'{e[0]} (with value {e[1]})', file=sys.stderr)
+ sys.exit(1)
+
+ print('errno.h validated correctly')
+
+if __name__ == "__main__":
+ main()