update.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. parser.add_argument('--msvs', action='store_true',
  22. help='Generate Visual Studio project')
  23. return parser.parse_args()
  24. def update_external_binaries():
  25. uf = os.path.join('script', 'update-external-binaries.py')
  26. subprocess.check_call([sys.executable, uf])
  27. def update_gyp():
  28. # Since gyp doesn't support specify link_settings for each configuration,
  29. # we are not able to link to different libraries in "Debug" and "Release"
  30. # configurations.
  31. # In order to work around this, we decided to generate the configuration
  32. # for twice, one is to generate "Debug" config, the other one to generate
  33. # the "Release" config. And the settings are controlled by the variable
  34. # "libchromiumcontent_component" which is defined before running gyp.
  35. target_arch = get_target_arch()
  36. return (run_gyp(target_arch, 0) or run_gyp(target_arch, 1))
  37. def run_gyp(target_arch, component):
  38. # Update the VS build env.
  39. import_vs_env(target_arch)
  40. env = os.environ.copy()
  41. if PLATFORM == 'linux' and target_arch != get_host_arch():
  42. env['GYP_CROSSCOMPILE'] = '1'
  43. elif PLATFORM == 'win32':
  44. env['GYP_MSVS_VERSION'] = '2015'
  45. python = sys.executable
  46. if sys.platform == 'cygwin':
  47. # Force using win32 python on cygwin.
  48. python = os.path.join('vendor', 'python_26', 'python.exe')
  49. gyp = os.path.join('vendor', 'brightray', 'vendor', 'gyp', 'gyp_main.py')
  50. gyp_pylib = os.path.join(os.path.dirname(gyp), 'pylib')
  51. # Avoid using the old gyp lib in system.
  52. env['PYTHONPATH'] = os.path.pathsep.join([gyp_pylib,
  53. env.get('PYTHONPATH', '')])
  54. # Whether to build for Mac App Store.
  55. if os.environ.has_key('MAS_BUILD'):
  56. mas_build = 1
  57. else:
  58. mas_build = 0
  59. defines = [
  60. '-Dlibchromiumcontent_component={0}'.format(component),
  61. '-Dtarget_arch={0}'.format(target_arch),
  62. '-Dhost_arch={0}'.format(get_host_arch()),
  63. '-Dlibrary=static_library',
  64. '-Dmas_build={0}'.format(mas_build),
  65. ]
  66. # Add the defines passed from command line.
  67. args = parse_args()
  68. for define in [d.strip() for d in args.defines.split(' ')]:
  69. if define:
  70. defines += ['-D' + define]
  71. generator = 'ninja'
  72. if args.msvs:
  73. generator = 'msvs-ninja'
  74. return subprocess.call([python, gyp, '-f', generator, '--depth', '.',
  75. 'electron.gyp', '-Icommon.gypi'] + defines, env=env)
  76. if __name__ == '__main__':
  77. sys.exit(main())