/
Rakefile
179 lines (152 loc) · 3.98 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
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
build_mecab
build_msgpack
build_groonga
archive_name = archive
upload_archive(archive_name)
end
private
def relative_install_prefix
File.join("vendor", "groonga")
end
def absolete_install_prefix
File.join(@top_dir, relative_install_prefix)
end
def msgpack_prefix
File.join(@top_dir, "vendor", "msgpack")
end
def mecab_prefix
File.join(@top_dir, "vendor", "mecab")
end
def groonga_version
ENV["GROONGA_VERSION"] || "4.0.5"
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 build_mecab
download_url = "https://mecab.googlecode.com/files"
mecab_version = "0.996"
mecab_archive_name = "mecab-#{mecab_version}"
sh("curl",
"--silent",
"--remote-name",
"--location",
"--fail",
"#{download_url}/#{mecab_archive_name}.tar.gz")
sh("tar", "xf", "#{mecab_archive_name}.tar.gz")
Dir.chdir(mecab_archive_name) do
sh("./configure",
"--prefix=#{mecab_prefix}")
sh("make")
sh("make", "check")
sh("make", "install")
end
ipadic_version = "2.7.0-20070801"
ipadic_archive_name = "mecab-ipadic-#{ipadic_version}"
sh("curl",
"--silent",
"--remote-name",
"--location",
"--fail",
"#{download_url}/#{ipadic_archive_name}.tar.gz")
sh("tar", "xf", "#{ipadic_archive_name}.tar.gz")
Dir.chdir(ipadic_archive_name) do
sh("./configure",
"--prefix=#{mecab_prefix}")
sh("make")
sh("make", "install")
end
end
def build_msgpack
msgpack_version = "0.5.9"
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("./configure",
"--prefix=#{absolete_install_prefix}")
sh("make", "-j4")
sh("make", "install")
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=#{absolete_install_prefix}",
"--disable-static",
"--disable-document",
"--with-message-pack=#{absolete_install_prefix}",
*configure_args)
sh("make", "-j4")
sh("make", "install")
end
end
def archive
archive_name = "heroku-#{groonga_base_name}.tar.xz"
sh("tar", "cJf", archive_name, relative_install_prefix, 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