9 from lib.config import get_target_arch, PLATFORM
10 from lib.util import get_host_arch, import_vs_env
13 SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
19 if PLATFORM != 'win32' and platform.architecture()[0] != '64bit':
20 print 'Electron is required to be built on a 64bit machine'
23 update_external_binaries()
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()
36 def update_external_binaries():
37 uf = os.path.join('script', 'update-external-binaries.py')
38 subprocess.check_call([sys.executable, uf])
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"
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))
53 def run_gyp(target_arch, component):
54 # Update the VS build env.
55 import_vs_env(target_arch)
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'):
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),
85 # Add the defines passed from command line.
87 for define in [d.strip() for d in args.defines.split(' ')]:
89 defines += ['-D' + define]
93 generator = 'msvs-ninja'
95 return subprocess.call([python, gyp, '-f', generator, '--depth', '.',
96 'electron.gyp', '-Icommon.gypi'] + defines, env=env)
99 if __name__ == '__main__':