/
bootstrap.py
executable file
·282 lines (230 loc) · 9.99 KB
/
bootstrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/env python
import argparse
import errno
import os
import re
import subprocess
import sys
from lib.config import BASE_URL, PLATFORM, MIPS64EL_SYSROOT_URL, \
MIPS64EL_GCC, MIPS64EL_GCC_URL, enable_verbose_mode, \
is_verbose_mode, get_target_arch
from lib.util import execute, execute_stdout, get_electron_version, \
scoped_cwd, download, update_node_modules
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor')
DOWNLOAD_DIR = os.path.join(VENDOR_DIR, 'download')
PYTHON_26_URL = 'https://chromium.googlesource.com/chromium/deps/python_26'
def main():
os.chdir(SOURCE_ROOT)
args = parse_args()
defines = args_to_defines(args)
if not args.yes and PLATFORM != 'win32':
check_root()
if args.verbose:
enable_verbose_mode()
if sys.platform == 'cygwin':
update_win32_python()
update_submodules()
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
if args.target_arch == 'mips64el':
download_mips64el_toolchain()
# Redirect to use local libchromiumcontent build.
if args.build_release_libcc or args.build_debug_libcc:
build_libchromiumcontent(args.verbose, args.target_arch, defines,
args.build_debug_libcc, args.update_libcc)
dist_dir = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'dist', 'main')
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')
if PLATFORM != 'win32':
if not args.disable_clang and args.clang_dir == '':
# Download prebuilt clang binaries.
update_clang()
setup_python_libs()
update_node_modules('.')
setup_libchromiumcontent(args.dev, args.target_arch, args.url,
libcc_source_path, libcc_shared_library_path,
libcc_static_library_path)
if PLATFORM == 'linux' and args.target_arch != 'mips64el':
download_sysroot(args.target_arch)
create_chrome_version_h()
touch_config_gypi()
run_update(defines, args.msvs)
def parse_args():
parser = argparse.ArgumentParser(description='Bootstrap this project')
parser.add_argument('-u', '--url',
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)
parser.add_argument('-v', '--verbose',
action='store_true',
help='Prints the output of the subprocesses')
parser.add_argument('-d', '--dev', action='store_true',
help='Do not download static_library build')
parser.add_argument('-y', '--yes', '--assume-yes',
action='store_true',
help='Run non-interactively by assuming "yes" to all ' \
'prompts.')
parser.add_argument('--msvs', action='store_true',
help='Generate Visual Studio project')
parser.add_argument('--target_arch', default=get_target_arch(),
help='Manually specify the arch to build for')
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')
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'))
parser.add_argument('--libcc_source_path', required=False,
help='The source path of libchromiumcontent. ' \
'NOTE: All options of libchromiumcontent are ' \
'required OR let electron choose it')
parser.add_argument('--libcc_shared_library_path', required=False,
help='The shared library path of libchromiumcontent.')
parser.add_argument('--libcc_static_library_path', required=False,
help='The static library path of libchromiumcontent.')
parser.add_argument('--defines', default='',
help='The build variables passed to gyp')
return parser.parse_args()
def args_to_defines(args):
defines = args.defines
if args.disable_clang:
defines += ' clang=0'
if args.clang_dir:
defines += ' make_clang_dir=' + args.clang_dir
defines += ' clang_use_chrome_plugins=0'
return defines
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)
def update_submodules():
execute_stdout(['git', 'submodule', 'sync', '--recursive'])
execute_stdout(['git', 'submodule', 'update', '--init', '--recursive'])
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'])
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')
script = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script',
'download')
args = ['-f', '-c', get_libchromiumcontent_commit(), '--target_arch',
target_arch, url, target_dir]
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:
subprocess.check_call([sys.executable, script] + args)
else:
subprocess.check_call([sys.executable, script, '-s'] + args)
def update_win32_python():
with scoped_cwd(VENDOR_DIR):
if not os.path.exists('python_26'):
execute_stdout(['git', 'clone', PYTHON_26_URL])
def build_libchromiumcontent(verbose, target_arch, defines, debug,
force_update):
args = [sys.executable,
os.path.join(SOURCE_ROOT, 'script', 'build-libchromiumcontent.py')]
if debug:
args += ['-d']
if force_update:
args += ['--force-update']
if verbose:
args += ['-v']
if defines:
args += ['--defines', defines]
execute_stdout(args + ['--target_arch', target_arch])
def update_clang():
execute_stdout([os.path.join(SOURCE_ROOT, 'script', 'update-clang.sh')])
def download_sysroot(target_arch):
if target_arch == 'ia32':
target_arch = 'i386'
if target_arch == 'x64':
target_arch = 'amd64'
execute_stdout([sys.executable,
os.path.join(SOURCE_ROOT, 'script', 'install-sysroot.py'),
'--arch', target_arch],
cwd=VENDOR_DIR)
def download_mips64el_toolchain():
# Download sysroot image.
if not os.path.exists(os.path.join(VENDOR_DIR,
'debian_jessie_mips64-sysroot')):
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)
def create_chrome_version_h():
version_file = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'VERSION')
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()
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:
f.write(content)
def touch_config_gypi():
config_gypi = os.path.join(SOURCE_ROOT, 'vendor', 'node', 'config.gypi')
with open(config_gypi, 'w+') as f:
content = "\n{'variables':{}}"
if f.read() != content:
f.write(content)
def run_update(defines, msvs):
args = [sys.executable, os.path.join(SOURCE_ROOT, 'script', 'update.py')]
if defines:
args += ['--defines', defines]
if msvs:
args += ['--msvs']
execute_stdout(args)
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
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as e:
if e.errno != errno.EEXIST:
raise
if __name__ == '__main__':
sys.exit(main())