2013-06-19 06:32:41 +00:00
|
|
|
#!/usr/bin/env python
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2013-06-19 06:32:41 +00:00
|
|
|
import argparse
|
2017-05-09 20:38:14 +00:00
|
|
|
import errno
|
2013-06-19 06:32:41 +00:00
|
|
|
import os
|
2017-05-22 16:27:32 +00:00
|
|
|
import re
|
2015-07-03 02:01:44 +00:00
|
|
|
import subprocess
|
2013-06-19 06:32:41 +00:00
|
|
|
import sys
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2017-11-21 10:22:31 +00:00
|
|
|
from lib.config import BASE_URL, PLATFORM, MIPS64EL_SYSROOT_URL, \
|
|
|
|
MIPS64EL_GCC, MIPS64EL_GCC_URL, enable_verbose_mode, \
|
2017-05-22 16:27:32 +00:00
|
|
|
is_verbose_mode, get_target_arch
|
2017-05-25 21:53:42 +00:00
|
|
|
from lib.util import execute, execute_stdout, get_electron_version, \
|
2017-11-21 10:22:31 +00:00
|
|
|
scoped_cwd, download, update_node_modules
|
2013-07-01 07:21:27 +00:00
|
|
|
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2013-06-19 06:32:41 +00:00
|
|
|
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor')
|
2017-05-09 20:38:14 +00:00
|
|
|
DOWNLOAD_DIR = os.path.join(VENDOR_DIR, 'download')
|
2013-07-01 07:21:27 +00:00
|
|
|
PYTHON_26_URL = 'https://chromium.googlesource.com/chromium/deps/python_26'
|
2015-07-02 14:34:05 +00:00
|
|
|
|
2013-06-19 06:32:41 +00:00
|
|
|
def main():
|
|
|
|
os.chdir(SOURCE_ROOT)
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2013-06-19 06:32:41 +00:00
|
|
|
args = parse_args()
|
2016-05-02 12:19:16 +00:00
|
|
|
defines = args_to_defines(args)
|
2015-04-11 09:30:52 +00:00
|
|
|
if not args.yes and PLATFORM != 'win32':
|
2015-03-17 07:19:49 +00:00
|
|
|
check_root()
|
2014-08-12 12:23:59 +00:00
|
|
|
if args.verbose:
|
2014-12-08 17:03:48 +00:00
|
|
|
enable_verbose_mode()
|
2014-12-12 02:33:39 +00:00
|
|
|
if sys.platform == 'cygwin':
|
|
|
|
update_win32_python()
|
2013-07-01 08:12:31 +00:00
|
|
|
|
2016-05-02 07:45:48 +00:00
|
|
|
update_submodules()
|
|
|
|
|
2016-05-02 07:04:50 +00:00
|
|
|
libcc_source_path = args.libcc_source_path
|
|
|
|
libcc_shared_library_path = args.libcc_shared_library_path
|
|
|
|
libcc_static_library_path = args.libcc_static_library_path
|
|
|
|
|
2017-11-21 10:22:31 +00:00
|
|
|
if args.target_arch == 'mips64el':
|
|
|
|
download_mips64el_toolchain()
|
|
|
|
|
2018-04-02 20:54:39 +00:00
|
|
|
if args.target_arch.startswith('arm'):
|
|
|
|
download_native_mksnapshot(args.target_arch)
|
|
|
|
|
2016-05-02 07:04:50 +00:00
|
|
|
# Redirect to use local libchromiumcontent build.
|
2017-08-11 17:17:55 +00:00
|
|
|
if args.build_release_libcc or args.build_debug_libcc:
|
2018-04-06 12:22:15 +00:00
|
|
|
build_libchromiumcontent(args.verbose, args.target_arch,
|
2017-08-11 17:17:55 +00:00
|
|
|
args.build_debug_libcc, args.update_libcc)
|
2017-05-09 20:38:14 +00:00
|
|
|
dist_dir = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'dist', 'main')
|
2016-05-02 07:04:50 +00:00
|
|
|
libcc_source_path = os.path.join(dist_dir, 'src')
|
|
|
|
libcc_shared_library_path = os.path.join(dist_dir, 'shared_library')
|
|
|
|
libcc_static_library_path = os.path.join(dist_dir, 'static_library')
|
|
|
|
|
2016-05-03 00:38:15 +00:00
|
|
|
if PLATFORM != 'win32':
|
2016-05-19 01:14:57 +00:00
|
|
|
if not args.disable_clang and args.clang_dir == '':
|
|
|
|
# Download prebuilt clang binaries.
|
|
|
|
update_clang()
|
2015-07-01 06:27:15 +00:00
|
|
|
|
2015-07-03 14:52:26 +00:00
|
|
|
setup_python_libs()
|
2015-07-02 02:56:56 +00:00
|
|
|
update_node_modules('.')
|
2017-05-09 20:38:14 +00:00
|
|
|
setup_libchromiumcontent(args.dev, args.target_arch, args.url,
|
|
|
|
libcc_source_path, libcc_shared_library_path,
|
|
|
|
libcc_static_library_path)
|
2015-07-02 02:56:56 +00:00
|
|
|
|
2017-11-21 10:22:31 +00:00
|
|
|
if PLATFORM == 'linux' and args.target_arch != 'mips64el':
|
2016-03-08 15:05:32 +00:00
|
|
|
download_sysroot(args.target_arch)
|
2015-07-01 09:22:40 +00:00
|
|
|
|
2014-06-25 01:05:10 +00:00
|
|
|
create_chrome_version_h()
|
2013-07-02 01:16:56 +00:00
|
|
|
touch_config_gypi()
|
2016-07-26 10:24:58 +00:00
|
|
|
run_update(defines, args.msvs)
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2014-08-12 12:28:18 +00:00
|
|
|
|
2013-06-19 06:32:41 +00:00
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser(description='Bootstrap this project')
|
2013-07-01 08:12:31 +00:00
|
|
|
parser.add_argument('-u', '--url',
|
2013-06-19 06:32:41 +00:00
|
|
|
help='The base URL from which to download '
|
|
|
|
'libchromiumcontent (i.e., the URL you passed to '
|
|
|
|
'libchromiumcontent\'s script/upload script',
|
|
|
|
default=BASE_URL,
|
|
|
|
required=False)
|
2014-08-12 12:23:59 +00:00
|
|
|
parser.add_argument('-v', '--verbose',
|
|
|
|
action='store_true',
|
|
|
|
help='Prints the output of the subprocesses')
|
2015-04-07 15:40:36 +00:00
|
|
|
parser.add_argument('-d', '--dev', action='store_true',
|
|
|
|
help='Do not download static_library build')
|
2015-03-17 07:19:49 +00:00
|
|
|
parser.add_argument('-y', '--yes', '--assume-yes',
|
|
|
|
action='store_true',
|
|
|
|
help='Run non-interactively by assuming "yes" to all ' \
|
|
|
|
'prompts.')
|
2016-07-26 08:38:31 +00:00
|
|
|
parser.add_argument('--msvs', action='store_true',
|
|
|
|
help='Generate Visual Studio project')
|
2015-04-11 10:26:15 +00:00
|
|
|
parser.add_argument('--target_arch', default=get_target_arch(),
|
2015-04-11 08:59:44 +00:00
|
|
|
help='Manually specify the arch to build for')
|
2016-05-02 11:06:21 +00:00
|
|
|
parser.add_argument('--clang_dir', default='', help='Path to clang binaries')
|
|
|
|
parser.add_argument('--disable_clang', action='store_true',
|
|
|
|
help='Use compilers other than clang for building')
|
2017-08-11 17:17:55 +00:00
|
|
|
build_libcc = parser.add_mutually_exclusive_group()
|
|
|
|
build_libcc.add_argument('--build_release_libcc', action='store_true',
|
|
|
|
help='Build release version of libchromiumcontent')
|
|
|
|
build_libcc.add_argument('--build_debug_libcc', action='store_true',
|
|
|
|
help='Build debug version of libchromiumcontent')
|
|
|
|
parser.add_argument('--update_libcc', default=False,
|
|
|
|
action='store_true', help=('force gclient invocation to '
|
|
|
|
'update libchromiumcontent'))
|
2015-11-08 07:18:22 +00:00
|
|
|
parser.add_argument('--libcc_source_path', required=False,
|
2015-11-09 10:24:32 +00:00
|
|
|
help='The source path of libchromiumcontent. ' \
|
|
|
|
'NOTE: All options of libchromiumcontent are ' \
|
|
|
|
'required OR let electron choose it')
|
2015-11-08 07:18:22 +00:00
|
|
|
parser.add_argument('--libcc_shared_library_path', required=False,
|
2015-11-09 10:24:32 +00:00
|
|
|
help='The shared library path of libchromiumcontent.')
|
2015-11-08 07:18:22 +00:00
|
|
|
parser.add_argument('--libcc_static_library_path', required=False,
|
2015-11-09 10:24:32 +00:00
|
|
|
help='The static library path of libchromiumcontent.')
|
2016-08-10 21:46:41 +00:00
|
|
|
parser.add_argument('--defines', default='',
|
|
|
|
help='The build variables passed to gyp')
|
2018-04-30 15:03:43 +00:00
|
|
|
parser.add_argument('--cc_wrapper',
|
|
|
|
help='Sets cc_wrapper for build. E.g. $(which sccache)')
|
2013-06-19 06:32:41 +00:00
|
|
|
return parser.parse_args()
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2015-04-11 08:59:44 +00:00
|
|
|
|
2016-05-02 12:19:16 +00:00
|
|
|
def args_to_defines(args):
|
2016-08-10 21:46:41 +00:00
|
|
|
defines = args.defines
|
2016-05-02 12:19:16 +00:00
|
|
|
if args.disable_clang:
|
|
|
|
defines += ' clang=0'
|
|
|
|
if args.clang_dir:
|
|
|
|
defines += ' make_clang_dir=' + args.clang_dir
|
|
|
|
defines += ' clang_use_chrome_plugins=0'
|
2018-04-30 15:03:43 +00:00
|
|
|
if args.cc_wrapper is not None:
|
|
|
|
defines += ' cc_wrapper=' + args.cc_wrapper
|
2016-05-02 12:19:16 +00:00
|
|
|
return defines
|
|
|
|
|
|
|
|
|
2015-03-17 07:01:33 +00:00
|
|
|
def check_root():
|
|
|
|
if os.geteuid() == 0:
|
|
|
|
print "We suggest not running this as root, unless you're really sure."
|
|
|
|
choice = raw_input("Do you want to continue? [y/N]: ")
|
|
|
|
if choice not in ('y', 'Y'):
|
|
|
|
sys.exit(0)
|
|
|
|
|
2014-08-12 12:28:18 +00:00
|
|
|
|
2013-06-19 06:32:41 +00:00
|
|
|
def update_submodules():
|
2016-05-15 01:33:23 +00:00
|
|
|
execute_stdout(['git', 'submodule', 'sync', '--recursive'])
|
2014-12-07 23:47:05 +00:00
|
|
|
execute_stdout(['git', 'submodule', 'update', '--init', '--recursive'])
|
2013-06-19 06:32:41 +00:00
|
|
|
|
|
|
|
|
2015-07-03 14:52:26 +00:00
|
|
|
def setup_python_libs():
|
|
|
|
for lib in ('requests', 'boto'):
|
|
|
|
with scoped_cwd(os.path.join(VENDOR_DIR, lib)):
|
|
|
|
execute_stdout([sys.executable, 'setup.py', 'build'])
|
2015-07-03 06:23:42 +00:00
|
|
|
|
|
|
|
|
2017-05-09 20:38:14 +00:00
|
|
|
def setup_libchromiumcontent(is_dev, target_arch, url,
|
|
|
|
libcc_source_path,
|
|
|
|
libcc_shared_library_path,
|
|
|
|
libcc_static_library_path):
|
|
|
|
target_dir = os.path.join(DOWNLOAD_DIR, 'libchromiumcontent')
|
2017-11-22 02:27:21 +00:00
|
|
|
script = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script',
|
|
|
|
'download')
|
2017-05-22 16:27:32 +00:00
|
|
|
args = ['-f', '-c', get_libchromiumcontent_commit(), '--target_arch',
|
|
|
|
target_arch, url, target_dir]
|
2017-05-09 20:38:14 +00:00
|
|
|
if (libcc_source_path != None and
|
|
|
|
libcc_shared_library_path != None and
|
|
|
|
libcc_static_library_path != None):
|
|
|
|
args += ['--libcc_source_path', libcc_source_path,
|
|
|
|
'--libcc_shared_library_path', libcc_shared_library_path,
|
|
|
|
'--libcc_static_library_path', libcc_static_library_path]
|
|
|
|
mkdir_p(target_dir)
|
|
|
|
else:
|
|
|
|
mkdir_p(DOWNLOAD_DIR)
|
|
|
|
if is_dev:
|
2017-11-22 02:27:21 +00:00
|
|
|
subprocess.check_call([sys.executable, script] + args)
|
2017-05-09 20:38:14 +00:00
|
|
|
else:
|
2017-11-22 02:27:21 +00:00
|
|
|
subprocess.check_call([sys.executable, script, '-s'] + args)
|
2017-05-09 20:38:14 +00:00
|
|
|
|
2013-06-19 06:32:41 +00:00
|
|
|
|
2013-07-01 07:21:27 +00:00
|
|
|
def update_win32_python():
|
|
|
|
with scoped_cwd(VENDOR_DIR):
|
|
|
|
if not os.path.exists('python_26'):
|
2014-12-07 23:47:05 +00:00
|
|
|
execute_stdout(['git', 'clone', PYTHON_26_URL])
|
2013-07-01 07:21:27 +00:00
|
|
|
|
2015-07-01 06:27:15 +00:00
|
|
|
|
2018-04-06 12:22:15 +00:00
|
|
|
def build_libchromiumcontent(verbose, target_arch, debug,
|
2017-08-11 17:17:55 +00:00
|
|
|
force_update):
|
2016-06-14 18:49:54 +00:00
|
|
|
args = [sys.executable,
|
|
|
|
os.path.join(SOURCE_ROOT, 'script', 'build-libchromiumcontent.py')]
|
2017-08-11 17:17:55 +00:00
|
|
|
if debug:
|
|
|
|
args += ['-d']
|
|
|
|
if force_update:
|
|
|
|
args += ['--force-update']
|
2016-05-02 07:38:58 +00:00
|
|
|
if verbose:
|
2016-05-02 07:04:50 +00:00
|
|
|
args += ['-v']
|
|
|
|
execute_stdout(args + ['--target_arch', target_arch])
|
|
|
|
|
|
|
|
|
2015-07-01 06:27:15 +00:00
|
|
|
def update_clang():
|
|
|
|
execute_stdout([os.path.join(SOURCE_ROOT, 'script', 'update-clang.sh')])
|
|
|
|
|
|
|
|
|
2016-03-08 15:05:32 +00:00
|
|
|
def download_sysroot(target_arch):
|
|
|
|
if target_arch == 'ia32':
|
2016-03-10 11:54:45 +00:00
|
|
|
target_arch = 'i386'
|
2016-03-08 15:05:32 +00:00
|
|
|
if target_arch == 'x64':
|
|
|
|
target_arch = 'amd64'
|
2016-04-07 06:45:20 +00:00
|
|
|
execute_stdout([sys.executable,
|
|
|
|
os.path.join(SOURCE_ROOT, 'script', 'install-sysroot.py'),
|
2017-05-22 07:52:40 +00:00
|
|
|
'--arch', target_arch],
|
|
|
|
cwd=VENDOR_DIR)
|
2015-07-01 09:22:40 +00:00
|
|
|
|
2017-11-21 10:22:31 +00:00
|
|
|
|
|
|
|
def download_mips64el_toolchain():
|
|
|
|
# Download sysroot image.
|
2017-11-22 02:27:21 +00:00
|
|
|
if not os.path.exists(os.path.join(VENDOR_DIR,
|
|
|
|
'debian_jessie_mips64-sysroot')):
|
2017-11-21 10:22:31 +00:00
|
|
|
tar_name = 'debian_jessie_mips64-sysroot.tar.bz2'
|
|
|
|
download(tar_name, MIPS64EL_SYSROOT_URL,
|
|
|
|
os.path.join(SOURCE_ROOT, tar_name))
|
|
|
|
subprocess.call(['tar', '-jxf', tar_name, '-C', VENDOR_DIR])
|
|
|
|
os.remove(tar_name)
|
|
|
|
# Download toolchain.
|
|
|
|
if not os.path.exists(os.path.join(VENDOR_DIR, MIPS64EL_GCC)):
|
|
|
|
tar_name = MIPS64EL_GCC + '.tar.gz'
|
|
|
|
download(tar_name, MIPS64EL_GCC_URL, os.path.join(SOURCE_ROOT, tar_name))
|
|
|
|
subprocess.check_call(['tar', '-xf', tar_name, '-C', VENDOR_DIR])
|
|
|
|
os.remove(tar_name)
|
|
|
|
|
2018-04-02 20:54:39 +00:00
|
|
|
def download_native_mksnapshot(arch):
|
|
|
|
if not os.path.exists(os.path.join(VENDOR_DIR,
|
|
|
|
'native_mksnapshot')):
|
|
|
|
tar_name = 'native-mksnapshot.tar.bz2'
|
|
|
|
url = '{0}/linux/{1}/{2}/{3}'.format(BASE_URL, arch,
|
|
|
|
get_libchromiumcontent_commit(), tar_name)
|
|
|
|
download(tar_name, url, os.path.join(SOURCE_ROOT, tar_name))
|
|
|
|
subprocess.call(['tar', '-jxf', tar_name, '-C', VENDOR_DIR])
|
|
|
|
os.remove(tar_name)
|
2017-11-21 10:22:31 +00:00
|
|
|
|
2014-06-25 01:05:10 +00:00
|
|
|
def create_chrome_version_h():
|
2017-05-09 20:38:14 +00:00
|
|
|
version_file = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'VERSION')
|
2014-06-25 01:05:10 +00:00
|
|
|
target_file = os.path.join(SOURCE_ROOT, 'atom', 'common', 'chrome_version.h')
|
|
|
|
template_file = os.path.join(SOURCE_ROOT, 'script', 'chrome_version.h.in')
|
|
|
|
|
|
|
|
with open(version_file, 'r') as f:
|
|
|
|
version = f.read()
|
|
|
|
with open(template_file, 'r') as f:
|
|
|
|
template = f.read()
|
2015-09-07 18:55:02 +00:00
|
|
|
content = template.replace('{PLACEHOLDER}', version.strip())
|
|
|
|
|
|
|
|
# We update the file only if the content has changed (ignoring line ending
|
|
|
|
# differences).
|
|
|
|
should_write = True
|
|
|
|
if os.path.isfile(target_file):
|
|
|
|
with open(target_file, 'r') as f:
|
|
|
|
should_write = f.read().replace('r', '') != content.replace('r', '')
|
|
|
|
if should_write:
|
|
|
|
with open(target_file, 'w') as f:
|
2014-06-25 01:05:10 +00:00
|
|
|
f.write(content)
|
|
|
|
|
|
|
|
|
2013-07-02 01:16:56 +00:00
|
|
|
def touch_config_gypi():
|
|
|
|
config_gypi = os.path.join(SOURCE_ROOT, 'vendor', 'node', 'config.gypi')
|
2013-07-02 14:32:14 +00:00
|
|
|
with open(config_gypi, 'w+') as f:
|
2015-12-08 03:14:30 +00:00
|
|
|
content = "\n{'variables':{}}"
|
2013-07-02 14:32:14 +00:00
|
|
|
if f.read() != content:
|
|
|
|
f.write(content)
|
2013-07-02 01:16:56 +00:00
|
|
|
|
|
|
|
|
2016-07-26 10:24:58 +00:00
|
|
|
def run_update(defines, msvs):
|
2016-07-26 08:38:31 +00:00
|
|
|
args = [sys.executable, os.path.join(SOURCE_ROOT, 'script', 'update.py')]
|
|
|
|
if defines:
|
|
|
|
args += ['--defines', defines]
|
|
|
|
if msvs:
|
|
|
|
args += ['--msvs']
|
|
|
|
|
2016-07-26 10:24:58 +00:00
|
|
|
execute_stdout(args)
|
2013-06-19 06:32:41 +00:00
|
|
|
|
|
|
|
|
2017-05-22 16:27:32 +00:00
|
|
|
def get_libchromiumcontent_commit():
|
|
|
|
commit = os.getenv('LIBCHROMIUMCONTENT_COMMIT')
|
|
|
|
if commit:
|
|
|
|
return commit
|
|
|
|
|
|
|
|
# Extract full SHA-1 of libcc submodule commit
|
|
|
|
output = execute(['git', 'submodule', 'status', 'vendor/libchromiumcontent'])
|
|
|
|
commit = re.split('^(?:\s*)([a-f0-9]{40})(?:\s+)', output)[1]
|
|
|
|
return commit
|
|
|
|
|
|
|
|
|
2017-05-09 20:38:14 +00:00
|
|
|
def mkdir_p(path):
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
2013-06-19 06:32:41 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|