generate-config-gypi.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env python3
  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, will be disabled on 32bit via
  15. # common.gypi rules
  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. # Enable whole-program optimization for electron native modules.
  21. if sys.platform == "win32":
  22. args += ['--with-ltcg']
  23. subprocess.check_call([sys.executable, configure] + args)
  24. def read_node_config_gypi():
  25. config_gypi = os.path.join(NODE_DIR, 'config.gypi')
  26. with open(config_gypi, 'r') as f:
  27. content = f.read()
  28. return ast.literal_eval(content)
  29. def read_electron_args():
  30. all_gn = os.path.join(ELECTRON_DIR, 'build', 'args', 'all.gn')
  31. args = {}
  32. with open(all_gn, 'r') as f:
  33. for line in f:
  34. if line.startswith('#'):
  35. continue
  36. m = re.match('([\w_]+) = (.+)', line)
  37. if m == None:
  38. continue
  39. args[m.group(1)] = m.group(2)
  40. return args
  41. def main(target_file, target_cpu):
  42. run_node_configure(target_cpu)
  43. config = read_node_config_gypi()
  44. args = read_electron_args()
  45. # Remove the generated config.gypi to make the parallel/test-process-config
  46. # test pass.
  47. os.remove(os.path.join(NODE_DIR, 'config.gypi'))
  48. v = config['variables']
  49. # Electron specific variables:
  50. v['built_with_electron'] = 1
  51. v['node_module_version'] = int(args['node_module_version'])
  52. # Used by certain versions of node-gyp.
  53. v['build_v8_with_gn'] = 'false'
  54. with open(target_file, 'w+') as f:
  55. f.write(pprint.pformat(config, indent=2))
  56. if __name__ == '__main__':
  57. sys.exit(main(sys.argv[1], sys.argv[2]))