js2c.py 833 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python
  2. import contextlib
  3. import glob
  4. import os
  5. import subprocess
  6. import sys
  7. SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
  8. def main():
  9. natives = os.path.abspath(sys.argv[1])
  10. js_source_files = glob.glob('{0}/*.js'.format(sys.argv[2]))
  11. call_js2c(natives, js_source_files)
  12. def call_js2c(natives, js_source_files):
  13. js2c = os.path.join(SOURCE_ROOT, 'vendor', 'node', 'tools', 'js2c.py')
  14. src_dir = os.path.dirname(js_source_files[0])
  15. with scoped_cwd(src_dir):
  16. subprocess.check_call(
  17. [sys.executable, js2c, natives] +
  18. [os.path.basename(source) for source in js_source_files])
  19. @contextlib.contextmanager
  20. def scoped_cwd(path):
  21. cwd = os.getcwd()
  22. os.chdir(path)
  23. try:
  24. yield
  25. finally:
  26. os.chdir(cwd)
  27. if __name__ == '__main__':
  28. sys.exit(main())