generate-config-gypi.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import ast
  4. import os
  5. import pprint
  6. import re
  7. import subprocess
  8. import sys
  9. ELECTRON_DIR = os.path.abspath(os.path.join(__file__, '..', '..'))
  10. NODE_DIR = os.path.join(ELECTRON_DIR, '..', 'third_party', 'electron_node')
  11. def run_node_configure(target_cpu):
  12. configure = os.path.join(NODE_DIR, 'configure.py')
  13. args = ['--dest-cpu', target_cpu]
  14. # Enabled in Chromium's V8.
  15. if target_cpu == 'arm64' or target_cpu == 'x64':
  16. args += ['--experimental-enable-pointer-compression']
  17. # Work around "No acceptable ASM compiler found" error on some Windows
  18. # machines, it breaks nothing since Electron does not use OpenSSL.
  19. if sys.platform == 'win32':
  20. args += ['--openssl-no-asm']
  21. subprocess.check_call([sys.executable, configure] + args)
  22. def read_node_config_gypi():
  23. config_gypi = os.path.join(NODE_DIR, 'config.gypi')
  24. with open(config_gypi, 'r') as f:
  25. content = f.read()
  26. return ast.literal_eval(content)
  27. def read_electron_args():
  28. all_gn = os.path.join(ELECTRON_DIR, 'build', 'args', 'all.gn')
  29. args = {}
  30. with open(all_gn, 'r') as f:
  31. for line in f:
  32. if line.startswith('#'):
  33. continue
  34. m = re.match('([\w_]+) = (.+)', line)
  35. if m == None:
  36. continue
  37. args[m.group(1)] = m.group(2)
  38. return args
  39. def main(target_file, target_cpu):
  40. run_node_configure(target_cpu)
  41. config = read_node_config_gypi()
  42. args = read_electron_args()
  43. # Remove the generated config.gypi to make the parallel/test-process-config
  44. # test pass.
  45. os.remove(os.path.join(NODE_DIR, 'config.gypi'))
  46. v = config['variables']
  47. # Electron specific variables:
  48. v['built_with_electron'] = 1
  49. v['node_module_version'] = int(args['node_module_version'])
  50. # Used by certain versions of node-gyp.
  51. v['build_v8_with_gn'] = 'false'
  52. with open(target_file, 'w+') as f:
  53. f.write(pprint.pformat(config, indent=2))
  54. if __name__ == '__main__':
  55. sys.exit(main(*sys.argv[1:]))