This repository has been archived by the owner on Oct 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
build.py
executable file
·152 lines (136 loc) · 4.76 KB
/
build.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
#!/usr/bin/env python
import os
import shutil
import stat
import subprocess
import sys
import distutils.spawn
import argparse
import platform
parser = argparse.ArgumentParser(description="v8worker2 build.py")
parser.add_argument('--rebuild', dest='rebuild', action='store_true')
parser.add_argument('--use_ccache', dest='use_ccache', action='store_true')
parser.add_argument('--out_path', nargs=1, dest='out_path', type=str, action='store')
parser.add_argument('--depot_tools_path', nargs=1, dest='depot_tools_path', type=str, action='store')
parser.set_defaults(rebuild=False, use_ccache=False, out_path=None)
args = parser.parse_args()
root_path = os.path.dirname(os.path.realpath(__file__))
prebuilt_path = os.path.join(root_path, "prebuilt")
v8_path = os.path.join(root_path, "v8")
depot_tools = os.path.join(root_path, "depot_tools")
out_path = os.path.join(root_path, "out/")
if args.out_path:
out_path = args.out_path[0]
print("out_path %s" % args.out_path)
v8build_path = os.path.join(out_path, "v8build")
if args.depot_tools_path:
depot_tools = args.depot_tools_path[0]
# To get a list of args
# cd v8 && ../depot_tools/gn args ../out/v8build/ --list
GN_ARGS = """
is_component_build=false
is_debug=false
libcpp_is_static=false
symbol_level=1
treat_warnings_as_errors=false
use_custom_libcxx=false
use_sysroot=false
v8_deprecation_warnings=false
v8_embedder_string="-v8worker2"
v8_enable_gdbjit=false
v8_enable_i18n_support=false
v8_enable_test_features=false
v8_experimental_extra_library_files=[]
v8_extra_library_files=[]
v8_imminent_deprecation_warnings=false
v8_monolithic=true
v8_static_library=false
v8_target_cpu="x64"
v8_untrusted_code_mitigations=false
v8_use_external_startup_data=false
v8_use_snapshot=true
"""
GCLIENT_SOLUTION = [
{ "name" : "v8",
"url" : "https://chromium.googlesource.com/v8/v8.git",
"deps_file" : "DEPS",
"managed" : False,
"custom_deps" : {
# These deps are unnecessary for building.
"v8/test/benchmarks/data" : None,
"v8/testing/gmock" : None,
"v8/test/mozilla/data" : None,
"v8/test/test262/data" : None,
"v8/test/test262/harness" : None,
"v8/test/wasm-js" : None,
"v8/third_party/android_tools" : None,
"v8/third_party/catapult" : None,
"v8/third_party/colorama/src" : None,
"v8/third_party/instrumented_libraries" : None,
"v8/tools/gyp" : None,
"v8/tools/luci-go" : None,
"v8/tools/swarming_client" : None,
},
"custom_vars": {
"build_for_node" : True,
},
},
]
def main():
lib_fn = os.path.join(prebuilt_path, platform_name(), "libv8_monolith.a")
if args.rebuild or not os.path.exists(lib_fn):
print("Rebuilding V8")
lib_fn = Rebuild()
else:
print("Using prebuilt V8 %s" % lib_fn)
WriteProgramConfigFile(lib_fn)
def platform_name():
u = platform.uname()
return (u[0] + "-" + u[4]).lower()
def Rebuild():
env = os.environ.copy()
EnsureDeps(v8_path)
gn_path = os.path.join(depot_tools, "gn")
assert os.path.exists(gn_path)
ninja_path = os.path.join(depot_tools, "ninja")
assert os.path.exists(ninja_path)
gn_args = GN_ARGS.replace('\n', ' ')
if args.use_ccache:
ccache_fn = distutils.spawn.find_executable("ccache")
if ccache_fn:
gn_args += " cc_wrapper=\"%s\"" % ccache_fn
print("Running gn")
subprocess.check_call([gn_path, "gen", v8build_path, "--args=" + gn_args],
cwd=v8_path,
env=env)
print("Running ninja")
subprocess.check_call([ninja_path, "-v", "-C", v8build_path, "v8_monolith"],
cwd=v8_path,
env=env)
lib_fn = os.path.join(v8build_path, "obj/libv8_monolith.a")
return lib_fn
def WriteProgramConfigFile(lib_fn):
assert os.path.exists(lib_fn)
if not os.path.isdir(out_path):
os.makedirs(out_path)
pc_fn = os.path.join(root_path, "v8.pc")
include_dir = os.path.join(v8_path, "include")
with open(pc_fn, 'w+') as f:
f.write("Name: v8\n")
f.write("Description: v8\n")
f.write("Version: xxx\n")
f.write("Cflags: -I%s\n" % include_dir)
f.write("Libs: %s\n" % lib_fn)
print("Wrote %s" % pc_fn)
def EnsureDeps(v8_path):
# Now call gclient sync.
spec = "solutions = %s" % GCLIENT_SOLUTION
print("Fetching dependencies.")
env = os.environ.copy()
# gclient needs to have depot_tools in the PATH.
env["PATH"] = depot_tools + os.pathsep + env["PATH"]
subprocess.check_call(["gclient", "sync", "--spec", spec],
cwd=root_path,
env=env)
if __name__ == "__main__":
main()