-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
238 lines (205 loc) · 5.93 KB
/
Rakefile
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
require "octokit"
task :default => :build
class GroongaBuilder
include Rake::DSL
def initialize
@top_dir = Dir.pwd
@github_token = ENV["GITHUB_TOKEN"]
if @github_token.nil?
raise "must set GITHUB_TOKEN environment variable"
end
end
def run
ensure_release
setup_environment_variables
build_mecab
build_msgpack
build_lz4
build_groonga
archive_name = archive
upload_archive(archive_name)
end
private
def relative_install_prefix
File.join("vendor", "groonga")
end
def absolute_install_prefix
File.join(@top_dir, relative_install_prefix)
end
def relative_mecab_prefix
File.join("vendor", "mecab")
end
def absolute_mecab_prefix
File.join(@top_dir, relative_mecab_prefix)
end
def mecab_config
File.join(absolute_mecab_prefix, "bin", "mecab-config")
end
def groonga_version
ENV["GROONGA_VERSION"] || "8.0.4"
end
def groonga_base_name
"groonga-#{groonga_version}"
end
def groonga_tag_name
"v#{groonga_version}"
end
def github_groonga_repository
"groonga/groonga"
end
def client
@client ||= Octokit::Client.new(:access_token => @github_token)
end
def find_release
releases = client.releases(github_groonga_repository)
releases.find do |release|
release.tag_name == groonga_tag_name
end
end
def release_exist?
not find_release.nil?
end
def ensure_release
return if release_exist?
client.create_release(github_groonga_repository, groonga_tag_name)
end
def setup_environment_variables
ENV["PKG_CONFIG_PATH"] =
File.join(absolute_install_prefix, "lib", "pkgconfig")
path = ENV["PATH"].split(File::PATH_SEPARATOR)
path += [File.join(absolute_install_prefix, "bin")]
ENV["PATH"] = path.join(File::PATH_SEPARATOR)
end
def build_mecab
mecab_version = "0.996"
mecab_archive_name = "mecab-#{mecab_version}"
sh("curl",
"--silent",
"--location",
"--fail",
"--output",
"#{mecab_archive_name}.tar.gz",
"https://drive.google.com/uc?export=download&id=0B4y35FiV1wh7cENtOXlicTFaRUE")
sh("tar", "xf", "#{mecab_archive_name}.tar.gz")
Dir.chdir(mecab_archive_name) do
sh("./configure",
"--prefix=#{absolute_mecab_prefix}")
sh("make")
sh("make", "check")
sh("make", "install")
end
naist_jdic_version = "0.6.3b-20111013"
naist_jdic_archive_name = "mecab-naist-jdic-#{naist_jdic_version}"
sh("curl",
"--silent",
"--remote-name",
"--location",
"--fail",
"http://iij.dl.sourceforge.jp/naist-jdic/53500/#{naist_jdic_archive_name}.tar.gz")
sh("tar", "xf", "#{naist_jdic_archive_name}.tar.gz")
Dir.chdir(naist_jdic_archive_name) do
sh("./configure",
"--prefix=#{absolute_mecab_prefix}",
"--with-mecab-config=#{mecab_config}",
"--with-charset=utf8")
sh("make")
sh("make", "install-data")
end
mecab_rc_path = File.join(absolute_mecab_prefix, "etc", "mecabrc")
mecab_rc_content = File.open(mecab_rc_path, "r") do |mecab_rc|
mecab_rc.read
end
naist_jdic_dir = File.join(absolute_mecab_prefix, "lib", "mecab", "dic", "naist-jdic")
File.open(mecab_rc_path, "w") do |mecab_rc|
mecab_rc.print(mecab_rc_content.gsub(/^dicdir\s*=.+$/,
"dicdir = #{naist_jdic_dir}"))
end
end
def build_msgpack
cmake_version = "3.11.4"
cmake_archive_name = "cmake-#{cmake_version}-Linux-x86_64"
sh("curl",
"--silent",
"--remote-name",
"--location",
"--fail",
"https://cmake.org/files/v#{cmake_version.sub(/.[0-9]\z/, "")}/#{cmake_archive_name}.tar.gz")
sh("tar", "xf", "#{cmake_archive_name}.tar.gz")
msgpack_version = "3.0.1"
msgpack_archive_name = "msgpack-#{msgpack_version}"
sh("curl",
"--silent",
"--remote-name",
"--location",
"--fail",
"https://github.com/msgpack/msgpack-c/releases/download/cpp-#{msgpack_version}/#{msgpack_archive_name}.tar.gz")
sh("tar", "xf", "#{msgpack_archive_name}.tar.gz")
Dir.chdir(msgpack_archive_name) do
sh("./../#{cmake_archive_name}/bin/cmake",
"-DCMAKE_INSTALL_PREFIX=#{absolute_install_prefix}",
".")
sh("make", "-j4")
sh("make", "install")
end
end
def build_lz4
lz4_version = "1.8.2"
lz4_archive_name = "lz4-#{lz4_version}"
sh("curl",
"--silent",
"--remote-name",
"--remote-header-name",
"--location",
"--fail",
"https://github.com/lz4/lz4/archive/v#{lz4_version}.tar.gz")
sh("tar", "xf", "#{lz4_archive_name}.tar.gz")
Dir.chdir(lz4_archive_name) do
sh("make", "install", "PREFIX=#{absolute_install_prefix}")
end
end
def build_groonga
archive_name = "#{groonga_base_name}.tar.gz"
sh("curl",
"--silent",
"--remote-name",
"--location",
"--fail",
"http://packages.groonga.org/source/groonga/#{archive_name}")
sh("tar", "xf", archive_name)
Dir.chdir(groonga_base_name) do
configure_args = []
if ENV["DEBUG"] == "yes"
configure_args << "--enable-debug"
end
sh("./configure",
"--prefix=#{absolute_install_prefix}",
"--disable-static",
"--disable-document",
"--with-message-pack=#{absolute_install_prefix}",
"--with-mecab-config=#{mecab_config}",
"--with-lz4",
"--enable-mruby",
*configure_args)
sh("make")
sh("make", "install")
end
end
def archive
archive_name = "heroku-#{groonga_base_name}.tar.xz"
sh("tar", "cJf", archive_name,
relative_install_prefix,
relative_mecab_prefix)
archive_name
end
def upload_archive(archive_name)
release = find_release
options = {
:content_type => "application/x-xz",
}
client.upload_asset(release.url, archive_name, options)
end
end
task :build do
builder = GroongaBuilder.new
builder.run
end