From 8c8c5f13cf622fe9c96c649cdaec6386f52175c7 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 3 Mar 2025 19:54:39 +0800 Subject: [PATCH] add a new util script --- .github/workflows/main.yml | 1 + scripts/check_pragma_once.py | 20 ++++++++++++++++++++ src/compiler/compiler.c | 1 - 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 scripts/check_pragma_once.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c6f931bc..bd143fc5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -70,6 +70,7 @@ jobs: if: github.ref == 'refs/heads/main' - name: Compile and Test run: | + python scripts/check_pragma_once.py include mkdir -p output/x86_64 python cmake_build.py python scripts/run_tests.py diff --git a/scripts/check_pragma_once.py b/scripts/check_pragma_once.py new file mode 100644 index 00000000..5f3ac335 --- /dev/null +++ b/scripts/check_pragma_once.py @@ -0,0 +1,20 @@ +import os +import sys + +def check_pragma_once_in_dir(path): + for root, dirs, files in os.walk(path): + if 'include/pocketpy/xmacros' in root or 'include/pybind11' in root: + continue + for file in files: + if file.endswith(".c") or file.endswith(".h"): + with open(os.path.join(root, file), "r", encoding='utf-8') as f: + print(f"==> {os.path.join(root, file)}") + text = f.read() + assert text.count("#pragma once") == 1, "#pragma once should appear exactly once" + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("Usage: python scripts/check_pragma_once.py ") + sys.exit(1) + + check_pragma_once_in_dir(sys.argv[1]) \ No newline at end of file diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index a7edeb52..f8db639b 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -2858,7 +2858,6 @@ const static PrattRule rules[TK__COUNT__] = { }; // clang-format on -#undef static_assert_expr_size #undef vtcall #undef vtemit_ #undef vtemit_del