1
1
unless $:. include? File . expand_path ( "../../../lib" , __FILE__ )
2
2
$:. unshift File . expand_path ( "../../../lib" , __FILE__ )
3
3
end
4
+ require 'fileutils'
4
5
require 'mkmf'
5
6
require 'rbconfig'
6
7
require 'shellwords'
@@ -35,8 +36,11 @@ def debug_build?
35
36
end
36
37
37
38
def build_libv8!
39
+ setup_depot_tools!
38
40
setup_python!
39
41
setup_build_deps!
42
+ setup_ninja!
43
+ setup_gn!
40
44
Dir . chdir ( File . expand_path ( '../../../vendor/v8' , __FILE__ ) ) do
41
45
puts 'Beginning compilation. This will take some time.'
42
46
generate_gn_args
@@ -46,6 +50,10 @@ def build_libv8!
46
50
return $?. exitstatus
47
51
end
48
52
53
+ def setup_depot_tools!
54
+ ENV [ 'PATH' ] = "#{ File . expand_path ( '../../../vendor/depot_tools' , __FILE__ ) } :#{ ENV [ 'PATH' ] } "
55
+ end
56
+
49
57
def setup_python!
50
58
# If python v2 cannot be found in PATH,
51
59
# create a symbolic link to python2 the current directory and put it
@@ -58,6 +66,19 @@ def setup_python!
58
66
`ln -fs #{ `which python2` . chomp } python`
59
67
ENV [ 'PATH' ] = "#{ File . expand_path '.' } :#{ ENV [ 'PATH' ] } "
60
68
end
69
+
70
+ if arch_ppc64?
71
+ unless system 'which python3 2>&1 > /dev/null'
72
+ fail "libv8 requires python 3 to be installed in order to build"
73
+ end
74
+
75
+ # Because infra/3pp/tools/cpython3/linux-ppc64le@version:3.8.0.chromium.8 CIPD is not yet available
76
+ # fallback to host's python3
77
+ ENV [ 'VPYTHON_BYPASS' ] = 'manually managed python not supported by chrome operations'
78
+
79
+ # stub the CIPD cpython3 with host's python3
80
+ FileUtils . symlink ( `which python3` . chomp , File . expand_path ( "../../../vendor/depot_tools/python3" , __FILE__ ) , force : true )
81
+ end
61
82
end
62
83
63
84
##
@@ -75,8 +96,6 @@ def source_version
75
96
# https://chromium.googlesource.com/v8/v8.git#Getting-the-Code
76
97
#
77
98
def setup_build_deps!
78
- ENV [ 'PATH' ] = "#{ File . expand_path ( '../../../vendor/depot_tools' , __FILE__ ) } :#{ ENV [ 'PATH' ] } "
79
-
80
99
Dir . chdir ( File . expand_path ( '../../../vendor' , __FILE__ ) ) do
81
100
unless Dir . exists? ( 'v8' ) || File . exists? ( '.gclient' )
82
101
system "fetch v8" or fail "unable to fetch v8 source"
@@ -92,8 +111,63 @@ def setup_build_deps!
92
111
end
93
112
end
94
113
114
+ ##
115
+ # Build ninja for linux ppc64le
116
+ #
117
+ def setup_ninja!
118
+ return unless arch_ppc64?
119
+
120
+ ninja_filepath = File . expand_path ( "../../../vendor/depot_tools/ninja-linux-ppc64le" , __FILE__ )
121
+ return if File . exists? ( ninja_filepath )
122
+
123
+ Dir . chdir ( "/tmp" ) do
124
+ FileUtils . rm_rf ( "ninja" )
125
+ system "git clone https://github.com/ninja-build/ninja.git -b v1.8.2" or fail "unable to git clone ninja repository"
126
+ end
127
+
128
+ Dir . chdir ( "/tmp/ninja" ) do
129
+ system "python2 ./configure.py --bootstrap" or fail "unable to build ninja"
130
+ FileUtils . mv ( File . expand_path ( "#{ Dir . pwd } /ninja" ) , ninja_filepath )
131
+ end
132
+
133
+ patch_filepath = File . expand_path ( "../../../vendor/patches/0001-support-ninja-ppc64le.patch" , __FILE__ )
134
+ Dir . chdir ( File . expand_path ( '../../../vendor/depot_tools' , __FILE__ ) ) do
135
+ system "patch -p1 < #{ patch_filepath } " or fail "unable to patch depot_tools/ninja"
136
+ end
137
+ end
138
+
139
+ ##
140
+ # Build gn for linux ppc64le
141
+ # Upstream issue: https://bugs.chromium.org/p/chromium/issues/detail?id=1076455
142
+ # TODO: Remove once upstream has supported ppc64le
143
+ #
144
+ def setup_gn!
145
+ return unless arch_ppc64?
146
+
147
+ gn_filepath = File . expand_path ( "../../../vendor/depot_tools/gn-linux-ppc64le" , __FILE__ )
148
+ return if File . exists? ( gn_filepath )
149
+
150
+ Dir . chdir ( "/tmp" ) do
151
+ FileUtils . rm_rf ( "gn" )
152
+ system "git clone https://gn.googlesource.com/gn" or fail "unable to git clone gn repository"
153
+ end
154
+
155
+ Dir . chdir ( "/tmp/gn" ) do
156
+ system "python2 build/gen.py"
157
+ fail "unable to prepare gn for compilation" unless File . exists? ( File . expand_path ( "#{ Dir . pwd } /out/build.ninja" ) )
158
+ system "ninja -C out" or fail "unable to build gn"
159
+ FileUtils . mv ( File . expand_path ( "#{ Dir . pwd } /out/gn" ) , gn_filepath )
160
+ FileUtils . rm_f ( File . expand_path ( "../../../vendor/depot_tools/gn" , __FILE__ ) )
161
+ FileUtils . symlink ( gn_filepath , File . expand_path ( "../../../vendor/depot_tools/gn" , __FILE__ ) , force : true )
162
+ end
163
+ end
164
+
95
165
private
96
166
167
+ def arch_ppc64?
168
+ libv8_arch == "ppc64"
169
+ end
170
+
97
171
def python_version
98
172
if system 'which python 2>&1 > /dev/null'
99
173
`python -c 'import platform; print(platform.python_version())'` . chomp
0 commit comments