-
Notifications
You must be signed in to change notification settings - Fork 13
/
mroonga.rb
205 lines (178 loc) · 5.91 KB
/
mroonga.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
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
class Mroonga < Formula
homepage "https://mroonga.org/"
url "https://packages.groonga.org/source/mroonga/mroonga-12.04.tar.gz"
sha256 "152a124bfaee16bbfe73e7fb4b2222323727b418c5736daf8ba7040b55bb455f"
license "LGPLv2+"
head "https://github.com/mroonga/mroonga.git", branch: "master"
depends_on "bison" => :build
depends_on "cmake" => :build
depends_on "ninja" => :build
depends_on "pkg-config" => :build
option "with-homebrew-mysql", "Use MySQL installed by Homebrew."
option "[email protected]", "Use [email protected] installed by Homebrew."
option "with-homebrew-mariadb", "Use MariaDB installed by Homebrew."
option "with-mysql-source=PATH", "MySQL source directory. You can't use this option with use-homebrew-mysql, use-homebrew-mysql56 and use-homebrew-mariadb"
option "with-mysql-build=PATH", "MySQL build directory (default: guess from with-mysql-source)"
option "with-mysql-config=PATH", "mysql_config path (default: guess from with-mysql-source)"
option "with-debug[=full]", "Build with debug option"
option "with-default-tokenizer=TOKENIZER", "Specify the default fulltext tokenizer like with-default-tokenizer=TokenMecab (default: TokenBigram)"
depends_on "groonga"
if build.with?("homebrew-mysql")
depends_on "mysql"
elsif build.with?("[email protected]")
depends_on "[email protected]"
elsif build.with?("homebrew-mariadb")
depends_on "mariadb"
end
def install
if build.with?("homebrew-mysql")
mysql_formula_name = "mysql"
elsif build.with?("[email protected]")
mysql_formula_name = "[email protected]"
elsif build.with?("homebrew-mariadb")
mysql_formula_name = "mariadb"
else
mysql_formula_name = nil
end
if mysql_formula_name
build_formula(mysql_formula_name) do |formula|
Dir.chdir(buildpath.to_s) do
install_mroonga(formula.buildpath.to_s,
(formula.prefix + "bin" + "mysql_config").to_s)
end
end
else
mysql_source_path = option_value("--with-mysql-source")
if mysql_source_path.nil?
raise "--with-homebrew-mysql, [email protected], --with-homebrew-mariadb or --with-mysql-source=PATH is required"
end
install_mroonga(mysql_source_path, nil)
end
end
test do
end
def caveats
<<~EOS
To confirm successfuly installed, run the following command
and confirm that 'Mroonga' is in the list:
mysql> SHOW PLUGINS;
+---------+--------+----------------+---------------+---------+
| Name | Status | Type | Library | License |
+---------+--------+----------------+---------------+---------+
| ... | ... | ... | ... | ... |
| Mroonga | ACTIVE | STORAGE ENGINE | ha_mroonga.so | GPL |
+---------+--------+----------------+---------------+---------+
XX rows in set (0.00 sec)
To install Mroonga plugin manually, run the following command:
mysql -uroot < '#{install_sql_path}'
To uninstall Mroonga plugin, run the following command:
mysql -uroot < '#{uninstall_sql_path}'
EOS
end
private
module Patchable
def patches
file_content = path.open do |file|
file.read
end
data_index = file_content.index(/^__END__$/)
if data_index.nil?
# Prevent NoMethodError
return defined?(super) ? super : []
end
data = path.open
data.seek(data_index + "__END__\n".size)
data
end
end
module DryInstallable
def install(options={})
if options[:dry_run]
catch do |tag|
@dry_install_tag = tag
begin
super()
ensure
@dry_install_tag = tag
end
end
else
super()
end
end
private
def system(*args)
if args == ["make", "install"] and @dry_install_tag
throw @dry_install_tag
end
super
end
end
def build_formula(name)
formula = Formula[name]
formula.extend(Patchable)
formula.extend(DryInstallable)
base_logs = logs
formula.singleton_class.define_method(:logs) do
base_logs
end
formula.brew do
formula.patch
formula.install(:dry_run => true)
yield formula
end
end
def build_cmake_args(mysql_source_path, mysql_config_path)
cmake_args = std_cmake_args
cmake_args << "-DMYSQL_SOURCE_DIR=#{mysql_source_path}"
mysql_config = option_value("--with-mysql-config")
mysql_config ||= mysql_config_path
if mysql_config
cmake_args << "-DMYSQL_CONFIG=#{mysql_config}"
end
mysql_build_path = option_value("--with-mysql-build")
if mysql_build_path
cmake_args << "-DMYSQL_BUILD_DIR=#{mysql_build_path}"
end
debug = option_value("--with-debug")
case debug
when true
cmake_args << "-DWITH_DEBUG=ON"
when "full"
cmake_args << "-DWITH_DEBUG_FULL=ON"
end
default_tokenizer = option_value("--with-default-tokenizer")
if default_tokenizer
cmake_args << "-DMRN_DEFAULT_TOKENIZER=#{default_tokenizer}"
end
cmake_args
end
def install_mroonga(mysql_source_path, mysql_config_path)
cmake_args = build_cmake_args(mysql_source_path, mysql_config_path)
mkdir "build" do
system("cmake", "..", "-G", "Ninja", *cmake_args)
with_env("DESTDIR" => "#{Dir.pwd}/stage") do
system("ninja", "install")
end
(lib/"plugin").install(Dir["stage/**/lib/plugin/*"])
data_path.install(Dir["stage/**/share/mroonga/*"])
end
system("mysql -uroot < '#{install_sql_path}' || true")
end
def data_path
prefix + "share/mroonga"
end
def install_sql_path
data_path + "install.sql"
end
def uninstall_sql_path
data_path + "uninstall.sql"
end
def option_value(search_key)
build.used_options.each do |option|
key, value = option.to_s.split(/=/, 2)
return value || true if key == search_key
end
nil
end
end