generate_node_defines.py 915 B

12345678910111213141516171819202122232425262728293031323334
  1. import os
  2. import re
  3. import sys
  4. DEFINE_EXTRACT_REGEX = re.compile(r'^ *# *define (\w*)', re.MULTILINE)
  5. def main(out_dir, headers):
  6. defines = []
  7. for filename in headers:
  8. with open(filename, 'r') as f:
  9. content = f.read()
  10. defines += read_defines(content)
  11. push_and_undef = ''
  12. for define in defines:
  13. push_and_undef += '#pragma push_macro("%s")\n' % define
  14. push_and_undef += '#undef %s\n' % define
  15. with open(os.path.join(out_dir, 'push_and_undef_node_defines.h'), 'w') as o:
  16. o.write(push_and_undef)
  17. pop = ''
  18. for define in defines:
  19. pop += '#pragma pop_macro("%s")\n' % define
  20. with open(os.path.join(out_dir, 'pop_node_defines.h'), 'w') as o:
  21. o.write(pop)
  22. def read_defines(content):
  23. defines = []
  24. for match in DEFINE_EXTRACT_REGEX.finditer(content):
  25. defines.append(match.group(1))
  26. return defines
  27. if __name__ == '__main__':
  28. main(sys.argv[1], sys.argv[2:])