generate_node_version_header.py 705 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python3
  2. import re
  3. import sys
  4. node_version_file = sys.argv[1]
  5. out_file = sys.argv[2]
  6. NMV = None
  7. if len(sys.argv) > 3:
  8. NMV = sys.argv[3]
  9. with open(node_version_file, 'r', encoding='utf-8') as in_file, \
  10. open(out_file, 'w', encoding='utf-8') as out_file:
  11. changed = False
  12. contents = in_file.read()
  13. new_contents = re.sub(
  14. r'^#define NODE_MODULE_VERSION [0-9]+$',
  15. '#define NODE_MODULE_VERSION ' + NMV,
  16. contents,
  17. flags=re.MULTILINE)
  18. changed = contents != new_contents
  19. if not changed and NMV is not None:
  20. raise Exception("Did not modify the NMV from nodes value, this value MUST "
  21. "differ from node")
  22. out_file.writelines(new_contents)