2013-06-24 11:24:30 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2016-05-02 15:19:16 +03:00
|
|
|
import argparse
|
2013-09-27 06:21:27 +04:00
|
|
|
import os
|
2015-06-10 09:11:34 +03:00
|
|
|
import platform
|
2013-06-24 11:24:30 +04:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2015-07-02 10:10:05 +03:00
|
|
|
from lib.config import get_target_arch, PLATFORM
|
2016-05-10 06:44:56 +03:00
|
|
|
from lib.util import get_host_arch, import_vs_env
|
2014-08-03 19:13:04 +04:00
|
|
|
|
2013-06-24 11:24:30 +04:00
|
|
|
|
2013-07-01 11:49:52 +04:00
|
|
|
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
2013-06-24 11:24:30 +04:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
os.chdir(SOURCE_ROOT)
|
|
|
|
|
2015-07-03 13:03:52 +03:00
|
|
|
if PLATFORM != 'win32' and platform.architecture()[0] != '64bit':
|
2015-07-01 11:51:06 +03:00
|
|
|
print 'Electron is required to be built on a 64bit machine'
|
|
|
|
return 1
|
|
|
|
|
2014-05-18 19:35:07 +04:00
|
|
|
update_external_binaries()
|
2015-04-02 18:03:23 +03:00
|
|
|
return update_gyp()
|
2013-06-24 11:24:30 +04:00
|
|
|
|
|
|
|
|
2016-05-02 15:19:16 +03:00
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser(description='Update build configurations')
|
|
|
|
parser.add_argument('--defines', default='',
|
2016-08-11 00:46:41 +03:00
|
|
|
help='The build variables passed to gyp')
|
2018-03-05 21:19:19 +03:00
|
|
|
group = parser.add_mutually_exclusive_group(required=False)
|
|
|
|
group.add_argument('--msvs', action='store_true',
|
2016-07-26 11:38:31 +03:00
|
|
|
help='Generate Visual Studio project')
|
2018-03-05 21:19:19 +03:00
|
|
|
group.add_argument('--xcode', action='store_true',
|
|
|
|
help='Generate XCode project')
|
2016-05-02 15:19:16 +03:00
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
2014-05-18 19:35:07 +04:00
|
|
|
def update_external_binaries():
|
|
|
|
uf = os.path.join('script', 'update-external-binaries.py')
|
2014-05-18 19:03:46 +04:00
|
|
|
subprocess.check_call([sys.executable, uf])
|
2013-06-28 12:12:40 +04:00
|
|
|
|
2013-06-24 11:24:30 +04:00
|
|
|
|
|
|
|
def update_gyp():
|
2015-04-02 18:03:23 +03:00
|
|
|
# Since gyp doesn't support specify link_settings for each configuration,
|
|
|
|
# we are not able to link to different libraries in "Debug" and "Release"
|
|
|
|
# configurations.
|
|
|
|
# In order to work around this, we decided to generate the configuration
|
|
|
|
# for twice, one is to generate "Debug" config, the other one to generate
|
|
|
|
# the "Release" config. And the settings are controlled by the variable
|
|
|
|
# "libchromiumcontent_component" which is defined before running gyp.
|
2015-04-11 12:58:19 +03:00
|
|
|
target_arch = get_target_arch()
|
2015-04-02 18:03:23 +03:00
|
|
|
return (run_gyp(target_arch, 0) or run_gyp(target_arch, 1))
|
|
|
|
|
|
|
|
|
|
|
|
def run_gyp(target_arch, component):
|
2016-05-10 06:44:56 +03:00
|
|
|
# Update the VS build env.
|
|
|
|
import_vs_env(target_arch)
|
|
|
|
|
2015-07-02 10:10:05 +03:00
|
|
|
env = os.environ.copy()
|
|
|
|
if PLATFORM == 'linux' and target_arch != get_host_arch():
|
|
|
|
env['GYP_CROSSCOMPILE'] = '1'
|
2015-07-03 05:01:44 +03:00
|
|
|
elif PLATFORM == 'win32':
|
2018-03-13 08:21:09 +03:00
|
|
|
env['GYP_MSVS_VERSION'] = '2017'
|
2015-04-02 18:03:23 +03:00
|
|
|
python = sys.executable
|
|
|
|
if sys.platform == 'cygwin':
|
|
|
|
# Force using win32 python on cygwin.
|
|
|
|
python = os.path.join('vendor', 'python_26', 'python.exe')
|
2017-05-09 23:38:14 +03:00
|
|
|
gyp = os.path.join('vendor', 'gyp', 'gyp_main.py')
|
2015-07-03 06:59:34 +03:00
|
|
|
gyp_pylib = os.path.join(os.path.dirname(gyp), 'pylib')
|
|
|
|
# Avoid using the old gyp lib in system.
|
|
|
|
env['PYTHONPATH'] = os.path.pathsep.join([gyp_pylib,
|
|
|
|
env.get('PYTHONPATH', '')])
|
2015-09-28 09:52:55 +03:00
|
|
|
# Whether to build for Mac App Store.
|
|
|
|
if os.environ.has_key('MAS_BUILD'):
|
|
|
|
mas_build = 1
|
|
|
|
else:
|
|
|
|
mas_build = 0
|
2016-05-02 15:19:16 +03:00
|
|
|
|
2015-04-08 14:19:40 +03:00
|
|
|
defines = [
|
|
|
|
'-Dlibchromiumcontent_component={0}'.format(component),
|
|
|
|
'-Dtarget_arch={0}'.format(target_arch),
|
2015-07-01 12:17:44 +03:00
|
|
|
'-Dhost_arch={0}'.format(get_host_arch()),
|
2015-04-08 14:19:40 +03:00
|
|
|
'-Dlibrary=static_library',
|
2015-09-28 09:52:55 +03:00
|
|
|
'-Dmas_build={0}'.format(mas_build),
|
2015-04-08 14:19:40 +03:00
|
|
|
]
|
2016-05-02 15:19:16 +03:00
|
|
|
|
|
|
|
# Add the defines passed from command line.
|
|
|
|
args = parse_args()
|
|
|
|
for define in [d.strip() for d in args.defines.split(' ')]:
|
|
|
|
if define:
|
|
|
|
defines += ['-D' + define]
|
|
|
|
|
2016-07-26 11:38:31 +03:00
|
|
|
generator = 'ninja'
|
|
|
|
if args.msvs:
|
|
|
|
generator = 'msvs-ninja'
|
2018-03-05 21:19:19 +03:00
|
|
|
elif args.xcode:
|
|
|
|
generator = 'xcode-ninja'
|
2016-07-26 11:38:31 +03:00
|
|
|
|
|
|
|
return subprocess.call([python, gyp, '-f', generator, '--depth', '.',
|
2016-03-31 19:23:04 +03:00
|
|
|
'electron.gyp', '-Icommon.gypi'] + defines, env=env)
|
2013-06-24 11:24:30 +04:00
|
|
|
|
2015-06-10 09:11:34 +03:00
|
|
|
|
2013-06-24 11:24:30 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|