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