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 System,
  18. # it breaks nothing since Electron does not use OpenSSL.
  19. args += ['--openssl-no-asm']
  20. subprocess.check_call([sys.executable, configure] + args)
  21. def read_node_config_gypi():
  22. config_gypi = os.path.join(NODE_DIR, 'config.gypi')
  23. with open(config_gypi, 'r') as f:
  24. content = f.read()
  25. return ast.literal_eval(content)
  26. def read_electron_args():
  27. all_gn = os.path.join(ELECTRON_DIR, 'build', 'args', 'all.gn')
  28. args = {}
  29. with open(all_gn, 'r') as f:
  30. for line in f:
  31. if line.startswith('#'):
  32. continue
  33. m = re.match('([\w_]+) = (.+)', line)
  34. if m == None:
  35. continue
  36. args[m.group(1)] = m.group(2)
  37. return args
  38. def main(target_file, target_cpu):
  39. run_node_configure(target_cpu)
  40. config = read_node_config_gypi()
  41. args = read_electron_args()
  42. # Remove the generated config.gypi to make the parallel/test-process-config
  43. # test pass.
  44. os.remove(os.path.join(NODE_DIR, 'config.gypi'))
  45. v = config['variables']
  46. # Electron specific variables:
  47. v['built_with_electron'] = 1
  48. v['node_module_version'] = int(args['node_module_version'])
  49. # Used by certain versions of node-gyp.
  50. v['build_v8_with_gn'] = 'false'
  51. with open(target_file, 'w+') as f:
  52. f.write(pprint.pformat(config, indent=2))
  53. if __name__ == '__main__':
  54. sys.exit(main(*sys.argv[1:]))