forked from ranguba/rroonga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
209 lines (180 loc) · 5.47 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
# -*- coding: utf-8; mode: ruby -*-
#
# Copyright (C) 2009-2015 Kouhei Sutou <[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 version 2.1 as published by the Free Software Foundation.
#
# 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 "find"
require "fileutils"
require "shellwords"
require "pathname"
require "erb"
require "yard"
require "bundler/gem_helper"
require "rake/extensiontask"
require "packnga"
base_dir = File.join(File.dirname(__FILE__))
groonga_ext_dir = File.join(base_dir, "ext", "groonga")
groonga_lib_dir = File.join(base_dir, "lib")
$LOAD_PATH.unshift(groonga_ext_dir)
$LOAD_PATH.unshift(groonga_lib_dir)
ENV["RUBYLIB"] = "#{groonga_lib_dir}:#{groonga_ext_dir}:#{ENV['RUBYLIB']}"
helper = Bundler::GemHelper.new(base_dir)
def helper.version_tag
version
end
helper.install
spec = helper.gemspec
Packnga::DocumentTask.new(spec) do |task|
task.original_language = "en"
task.translate_language = "ja"
end
ranguba_org_dir = Dir.glob("{..,../../www}/ranguba.org").first
Packnga::ReleaseTask.new(spec) do |task|
task.index_html_dir = ranguba_org_dir
end
module YARD
module CodeObjects
class Proxy
alias_method :initialize_original, :initialize
def initialize(namespace, name, type=nil)
name = name.to_s.gsub(/\AGrn(.*)\z/) do
suffix = $1
case suffix
when ""
"Groonga"
when "TableKeySupport"
"Groonga::Table::KeySupport"
else
"Groonga::#{suffix}"
end
end
initialize_original(namespace, name, type)
end
end
end
end
def windows?(platform=nil)
platform ||= RUBY_PLATFORM
platform =~ /mswin(?!ce)|mingw|cygwin|bccwin/
end
def collect_binary_files(binary_dir)
binary_files = []
Find.find(binary_dir) do |name|
next unless File.file?(name)
next if /\.zip\z/i =~ name
binary_files << name
end
binary_files
end
def windows_gem_name(spec, architecture)
"#{spec.name}-#{spec.version}-#{architecture}-mingw32.gem"
end
relative_vendor_dir = "vendor"
relative_binary_dir = File.join("vendor", "local")
vendor_dir = File.join(base_dir, relative_vendor_dir)
binary_dir = File.join(base_dir, relative_binary_dir)
groonga_win32_i386_p = ENV["RROONGA_USE_GROONGA_X64"].nil?
Rake::ExtensionTask.new("groonga", spec) do |ext|
if groonga_win32_i386_p
ext.cross_platform = ["x86-mingw32"]
else
ext.cross_platform = ["x64-mingw32"]
end
if windows?
ext.gem_spec.files += collect_binary_files(relative_binary_dir)
else
ext.cross_compile = true
ext.cross_compiling do |_spec|
if windows?(_spec.platform.to_s)
binary_files = collect_binary_files(relative_binary_dir)
_spec.files += binary_files
end
end
end
end
file "Makefile" => ["extconf.rb", "ext/groonga/extconf.rb"] do
extconf_args = []
if ENV["TRAVIS"]
extconf_args << "--enable-debug-build"
end
ruby("extconf.rb", *extconf_args)
end
desc "Configure"
task :configure => "Makefile"
desc "Run test"
task :test => :configure do
ruby("-rubygems", "test/run-test.rb")
end
namespace :test do
task :install do
gemspec_helper = Rake.application.jeweler.gemspec_helper
ruby("-S gem install --user-install #{gemspec_helper.gem_path}")
gem_spec = Gem.source_index.find_name("rroonga").last
installed_path = gem_spec.full_gem_path
ENV["NO_MAKE"] = "yes"
ruby("-rubygems", "#{installed_path}/test/run-test.rb")
end
end
desc "Remove Groonga binary directory"
namespace :clean do
task :groonga do
rm_rf binary_dir
end
end
windows_architectures = [:x86, :x64]
namespace :build do
namespace :windows do
ruby_versions = "2.1.6:2.2.2:2.3.0"
windows_architectures.each do |architecture|
desc "Build gem for Windows #{architecture}"
task architecture do
build_dir = "tmp/windows"
rm_rf build_dir
mkdir_p build_dir
commands = [
["git", "clone", "file://#{Dir.pwd}/.git", build_dir],
["cd", build_dir],
["gem", "install", "json"],
["bundle"],
["rake", "cross", "native", "gem", "RUBY_CC_VERSION=#{ruby_versions}"],
]
if architecture == :x64
commands.unshift(["export", "RROONGA_USE_GROONGA_X64=true"])
end
raw_commands = commands.collect do |command|
Shellwords.join(command)
end
raw_command_line = raw_commands.join(" && ")
require "rake_compiler_dock"
RakeCompilerDock.sh(raw_command_line)
cp("#{build_dir}/pkg/#{windows_gem_name(spec, architecture)}",
"pkg/")
end
end
end
desc "Build gems for Windows"
build_tasks = windows_architectures.collect do |architecture|
"windows:#{architecture}"
end
task :windows => build_tasks
end
namespace :release do
desc "Push gems for Windows to RubyGems.org"
task :windows do
windows_architectures.each do |architecture|
ruby("-S", "gem", "push", "pkg/#{windows_gem_name(spec, architecture)}")
end
end
end
task :default => :test