check_pragma_once.py 749 B

1234567891011121314151617181920
  1. import os
  2. import sys
  3. def check_pragma_once_in_dir(path):
  4. for root, dirs, files in os.walk(path):
  5. if 'include/pocketpy/xmacros' in root or 'include/pybind11' in root:
  6. continue
  7. for file in files:
  8. if file.endswith(".c") or file.endswith(".h"):
  9. with open(os.path.join(root, file), "r", encoding='utf-8') as f:
  10. print(f"==> {os.path.join(root, file)}")
  11. text = f.read()
  12. assert text.count("#pragma once") == 1, "#pragma once should appear exactly once"
  13. if __name__ == "__main__":
  14. if len(sys.argv) < 2:
  15. print("Usage: python scripts/check_pragma_once.py <path>")
  16. sys.exit(1)
  17. check_pragma_once_in_dir(sys.argv[1])