forked from groonga/groonga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
256 lines (229 loc) · 6.65 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# -*- ruby -*-
#
# Copyright (C) 2023-2024 Sutou Kouhei <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
require "open-uri"
require "tmpdir"
def sh_capture_output(*command_line)
IO.pipe do |read, write|
output = nil
read_thread = Thread.new do
output = read.read
end
sh(*command_line, out: write)
write.close
read_thread.join
output
end
end
def package
"groonga"
end
def version
ENV["VERSION"] || File.read("base_version")
end
def base_name
"#{package}-#{version}"
end
def archive_format
"tar.gz"
end
def archive_name
"#{base_name}.#{archive_format}"
end
def env_var(name, default=nil)
value = ENV[name] || default
raise "${#{name}} is missing" if value.nil?
value
end
def git_user_name
sh_capture_output("git", "config", "--get", "user.name").chomp
end
def git_user_email
sh_capture_output("git", "config", "--get", "user.email").chomp
end
version = File.read(File.join(__dir__, "base_version"))
namespace :dev do
namespace :version do
desc "Bump version for new development"
task :bump do
File.write("base_version", env_var("NEW_VERSION", version.succ))
end
end
namespace :mruby do
desc "Update vendored mruby"
task :update do
mruby_version = nil
cd("vendor/mruby-source") do
sh("git", "fetch", "--all", "--prune", "--force")
sh("git", "checkout", env_var("MRUBY_VERSION", "master"))
mruby_version = sh_capture_output("git", "describe", "--tags").chomp
end
cd("vendor/mruby") do
File.write("version", mruby_version)
ruby("update.rb", "build_config.rb", "../mruby-source",
out: "sources.am")
end
end
end
end
dist_files = sh_capture_output("git", "ls-files").split("\n").reject do |file|
file.start_with?("packages/")
end
file archive_name => dist_files do
sh("git",
"archive",
"--format=tar",
"--output=#{base_name}.tar",
"--prefix=#{base_name}/",
"HEAD")
sh("git",
"submodule",
"foreach",
"--recursive",
"git " +
"archive " +
"--prefix=#{base_name}/${sm_path}/ " +
"--output=$(basename ${sm_path}).tar " +
"HEAD " +
"&& " +
"tar " +
"--concatenate " +
"--file=${toplevel}/#{base_name}.tar " +
"$(basename ${sm_path}).tar " +
"&& " +
"rm $(basename ${sm_path}).tar")
sh("gzip", "--force", "#{base_name}.tar")
end
desc "Create archive"
task dist: archive_name
namespace :document do
desc "Generate C API document (Run doxygen)"
task :api do
sh("doxygen", "doc/Doxyfile")
end
end
namespace :release do
namespace :version do
desc "Update versions for a new release"
task :update do
new_release_date = env_var("NEW_RELEASE_DATE")
cd("packages") do
ruby("-S",
"rake",
"version:update",
"RELEASE_DATE=#{new_release_date}")
end
sh("git",
"add",
"packages/debian/changelog",
"packages/yum/groonga.spec.in")
sh("git",
"commit",
"-m",
"package: update version info to #{version} (#{new_release_date})")
sh("git", "push")
end
end
namespace :document do
desc "Update document"
task :update do
build_dir = env_var("BUILD_DIR")
groonga_org_path = File.expand_path(env_var("GROONGA_ORG_DIR"))
Dir.mktmpdir do |dir|
sh({"DESTDIR" => dir},
"cmake",
"--build", build_dir,
"--target", "install")
Dir.glob("#{dir}/**/share/doc/groonga/*/") do |doc|
locale = File.basename(doc)
if locale == "en"
groonga_org_docs = File.join(groonga_org_path, "docs")
else
groonga_org_docs = File.join(groonga_org_path, locale, "docs")
end
rm_rf(groonga_org_docs)
mv(doc, groonga_org_docs)
rm_f(File.join(groonga_org_docs, ".buildinfo"))
end
end
end
end
desc "Tag"
task :tag do
latest_news = Dir.glob("doc/source/news/*.*").max do |a, b|
File.basename(a).to_f - File.basename(b).to_f
end
latest_release_note = File.read(latest_news).split(/^## /)[1]
latest_release_note_version = latest_release_note.lines.first[/[\d.]+/]
if latest_release_note_version != version
raise "release note isn't written"
end
changelog = "packages/debian/changelog"
case File.readlines(changelog)[0]
when /\((.+)-1\)/
package_version = $1
unless package_version == version
raise "package version isn't updated: #{package_version}"
end
else
raise "failed to detect deb package version: #{changelog}"
end
sh("git",
"tag",
"v#{version}",
"-a",
"-m",
"Groonga #{version}!!!")
sh("git", "push", "origin", "v#{version}")
end
end
namespace :nfkc do
icu_version = ENV["ICU_VERSION"] || ""
icu_version_hyphen = icu_version.gsub(".", "-")
icu_version_underscore = icu_version.gsub(".", "_")
icu4c_src_tgz = File.basename("icu4c-#{icu_version_underscore}-src.tgz")
file icu4c_src_tgz do
icu4c_src_tgz_uri = "https://github.com/unicode-org/icu/releases/download/"
icu4c_src_tgz_uri += "release-#{icu_version_hyphen}/"
icu4c_src_tgz_uri += icu4c_src_tgz
icu4c_src_tgz_uri = URI(icu4c_src_tgz_uri)
icu4c_src_tgz_uri.open do |input|
File.open(icu4c_src_tgz, "wb") do |output|
IO.copy_stream(input, output)
end
end
end
icu_prefix = "tmp/icu-#{icu_version}/local"
file icu_prefix => icu4c_src_tgz do
rm_rf("tmp")
mkdir_p("tmp")
sh("tar", "xf", icu4c_src_tgz, "-C", "tmp")
absolute_icu_prefix = File.expand_path(icu_prefix)
cd("tmp/icu/source") do
sh("./configure", "--prefix=#{absolute_icu_prefix}")
sh("make", "-j#{Etc.nprocessors}")
sh("make", "install")
end
end
desc "Update NFKC to #{icu_version}"
task update: icu_prefix do
sh({"ICU_HOME" => File.expand_path(icu_prefix)},
FileUtils::RUBY,
"lib/nfkc.rb",
"--source-directory=lib")
end
end