check_odr_test.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright 2019 Hans Dembinski, Henry Schreiner
  2. #
  3. # Distributed under the Boost Software License, Version 1.0.
  4. # (See accompanying file LICENSE_1_0.txt
  5. # or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. import os
  7. import sys
  8. import re
  9. this_path = os.path.dirname(__file__)
  10. all_headers = set()
  11. include_path = os.path.join(this_path, "..", "include")
  12. for root, dirs, files in os.walk(include_path):
  13. for fn in files:
  14. fn = os.path.join(root, fn)
  15. assert fn.startswith(include_path)
  16. fn = fn[len(include_path) + 1 :]
  17. all_headers.add(fn)
  18. def get_headers(filename):
  19. with open(filename) as f:
  20. for hdr in re.findall('^#include [<"]([^>"]+)[>"]', f.read(), re.MULTILINE):
  21. if not hdr.startswith("boost/histogram"):
  22. continue
  23. yield hdr.replace("/", os.path.sep) # adapt the paths for Windows
  24. included_headers = set()
  25. unread_headers = set()
  26. for hdr in get_headers(os.path.join(this_path, "odr_test.cpp")):
  27. unread_headers.add(hdr)
  28. while unread_headers:
  29. included_headers.update(unread_headers)
  30. for hdr in tuple(unread_headers): # copy needed because unread_headers is modified
  31. unread_headers.remove(hdr)
  32. for hdr2 in get_headers(os.path.join(include_path, hdr)):
  33. if hdr2 not in included_headers:
  34. unread_headers.add(hdr2)
  35. diff = sorted(all_headers - set(included_headers))
  36. if not diff:
  37. sys.exit(0)
  38. print("Header not included in odr_test.cpp:")
  39. for fn in diff:
  40. print(fn)
  41. sys.exit(1)