update.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env python
  2. import argparse
  3. import os
  4. import platform
  5. import subprocess
  6. import sys
  7. from lib.config import get_target_arch, PLATFORM
  8. from lib.util import get_host_arch, import_vs_env
  9. SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
  10. def main():
  11. os.chdir(SOURCE_ROOT)
  12. if PLATFORM != 'win32' and platform.architecture()[0] != '64bit':
  13. print 'Electron is required to be built on a 64bit machine'
  14. return 1
  15. update_external_binaries()
  16. return update_gyp()
  17. def parse_args():
  18. parser = argparse.ArgumentParser(description='Update build configurations')
  19. parser.add_argument('--defines', default='',
  20. help='The build variables passed to gyp')
  21. group = parser.add_mutually_exclusive_group(required=False)
  22. group.add_argument('--msvs', action='store_true',
  23. help='Generate Visual Studio project')
  24. group.add_argument('--xcode', action='store_true',
  25. help='Generate XCode project')
  26. return parser.parse_args()
  27. def update_external_binaries():
  28. uf = os.path.join('script', 'update-external-binaries.py')
  29. subprocess.check_call([sys.executable, uf])
  30. def update_gyp():
  31. # Since gyp doesn't support specify link_settings for each configuration,
  32. # we are not able to link to different libraries in "Debug" and "Release"
  33. # configurations.
  34. # In order to work around this, we decided to generate the configuration
  35. # for twice, one is to generate "Debug" config, the other one to generate
  36. # the "Release" config. And the settings are controlled by the variable
  37. # "libchromiumcontent_component" which is defined before running gyp.
  38. target_arch = get_target_arch()
  39. return (run_gyp(target_arch, 0) or run_gyp(target_arch, 1))
  40. def run_gyp(target_arch, component):
  41. # Update the VS build env.
  42. import_vs_env(target_arch)
  43. env = os.environ.copy()
  44. if PLATFORM == 'linux' and target_arch != get_host_arch():
  45. env['GYP_CROSSCOMPILE'] = '1'
  46. elif PLATFORM == 'win32':
  47. env['GYP_MSVS_VERSION'] = '2017'
  48. python = sys.executable
  49. if sys.platform == 'cygwin':
  50. # Force using win32 python on cygwin.
  51. python = os.path.join('vendor', 'python_26', 'python.exe')
  52. gyp = os.path.join('vendor', 'gyp', 'gyp_main.py')
  53. gyp_pylib = os.path.join(os.path.dirname(gyp), 'pylib')
  54. # Avoid using the old gyp lib in system.
  55. env['PYTHONPATH'] = os.path.pathsep.join([gyp_pylib,
  56. env.get('PYTHONPATH', '')])
  57. # Whether to build for Mac App Store.
  58. if os.environ.has_key('MAS_BUILD'):
  59. mas_build = 1
  60. else:
  61. mas_build = 0
  62. defines = [
  63. '-Dlibchromiumcontent_component={0}'.format(component),
  64. '-Dtarget_arch={0}'.format(target_arch),
  65. '-Dhost_arch={0}'.format(get_host_arch()),
  66. '-Dlibrary=static_library',
  67. '-Dmas_build={0}'.format(mas_build),
  68. ]
  69. # Add the defines passed from command line.
  70. args = parse_args()
  71. for define in [d.strip() for d in args.defines.split(' ')]:
  72. if define:
  73. defines += ['-D' + define]
  74. generator = 'ninja'
  75. if args.msvs:
  76. generator = 'msvs-ninja'
  77. elif args.xcode:
  78. generator = 'xcode-ninja'
  79. return subprocess.call([python, gyp, '-f', generator, '--depth', '.',
  80. 'electron.gyp', '-Icommon.gypi'] + defines, env=env)
  81. if __name__ == '__main__':
  82. sys.exit(main())