You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

  1. #! /usr/bin/env python
  2. """Freeze importlib for use as the implementation of import."""
  3. import marshal
  4. header = """/* Auto-generated by Python/freeze_importlib.py */"""
  5. def main(input_path, output_path):
  6. with open(input_path, 'r', encoding='utf-8') as input_file:
  7. source = input_file.read()
  8. code = compile(source, '<frozen importlib._bootstrap>', 'exec')
  9. lines = [header]
  10. lines.append('unsigned char _Py_M__importlib[] = {')
  11. data = marshal.dumps(code)
  12. # Code from Tools/freeze/makefreeze.py:writecode()
  13. for i in range(0, len(data), 16):
  14. line = [' ']
  15. for c in data[i:i+16]:
  16. line.append('%d,' % c)
  17. lines.append(''.join(line))
  18. lines.append('};\n')
  19. with open(output_path, 'w', encoding='utf-8') as output_file:
  20. output_file.write('\n'.join(lines))
  21. output_file.write('/* Mercurial binary marker: \x00 */')
  22. if __name__ == '__main__':
  23. import sys
  24. args = sys.argv[1:]
  25. if len(args) != 2:
  26. print('Need to specify input and output file paths', file=sys.stderr)
  27. sys.exit(1)
  28. main(*args)