This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
/
builder.rb
106 lines (93 loc) · 3.12 KB
/
builder.rb
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
unless $:.include? File.expand_path("../../../lib", __FILE__)
$:.unshift File.expand_path("../../../lib", __FILE__)
end
require 'mkmf'
require 'rbconfig'
require 'shellwords'
require 'libv8/version'
require File.expand_path '../arch', __FILE__
module Libv8
class Builder
include Libv8::Arch
def gn_args
%W(clang_use_chrome_plugins=false
linux_use_bundled_binutils=false
use_custom_libcxx=false
use_sysroot=false
is_debug=#{debug_build? ? 'true' : 'false'}
symbol_level=#{debug_build? ? '-1' : '0'}
is_component_build=false
v8_monolithic=true
v8_use_external_startup_data=false
target_cpu="#{libv8_arch}"
v8_target_cpu="#{libv8_arch}"
treat_warnings_as_errors=false
icu_use_data_file=false).join(' ')
end
def generate_gn_args
system "gn gen out.gn/libv8 --args='#{gn_args}'"
end
def debug_build?
enable_config('debug') || Libv8::VERSION.include?('beta')
end
def build_libv8!
setup_python!
setup_build_deps!
Dir.chdir(File.expand_path('../../../vendor/v8', __FILE__)) do
puts 'Beginning compilation. This will take some time.'
generate_gn_args
system 'ninja -v -C out.gn/libv8 v8_monolith'
end
return $?.exitstatus
end
def setup_python!
# If python v2 cannot be found in PATH,
# create a symbolic link to python2 the current directory and put it
# at the head of PATH. That way all commands that inherit this environment
# will use ./python -> python2
if python_version !~ /^2/
unless system 'which python2 2>&1 > /dev/null'
fail "libv8 requires python 2 to be installed in order to build, but it is currently #{python_version}"
end
`ln -fs #{`which python2`.chomp} python`
ENV['PATH'] = "#{File.expand_path '.'}:#{ENV['PATH']}"
end
end
##
# The release tag to checkout. If this is version 4.5.95.0 of the libv8 gem,
# then this will be 4.5.95
#
def source_version
Libv8::VERSION.gsub(/\.[^.]+$/, '')
end
##
# Checkout all of the V8 source and its dependencies using the
# chromium depot tools.
#
# https://chromium.googlesource.com/v8/v8.git#Getting-the-Code
#
def setup_build_deps!
ENV['PATH'] = "#{File.expand_path('../../../vendor/depot_tools', __FILE__)}:#{ENV['PATH']}"
Dir.chdir(File.expand_path('../../../vendor', __FILE__)) do
unless Dir.exists?('v8') || File.exists?('.gclient')
system "fetch v8" or fail "unable to fetch v8 source"
end
Dir.chdir('v8') do
system 'git fetch origin'
unless system "git checkout #{source_version}"
fail "unable to checkout source for v8 #{source_version}"
end
system "gclient sync" or fail "could not sync v8 build dependencies"
end
end
end
private
def python_version
if system 'which python 2>&1 > /dev/null'
`python -c 'import platform; print(platform.python_version())'`.chomp
else
"not available"
end
end
end
end