generate-config-gypi.py 2.2 KB

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