forked from ranguba/rroonga
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
202 lines (180 loc) · 5.49 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
# -*- coding: utf-8; mode: ruby -*-
#
# Copyright (C) 2009-2011 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
require 'English'
require 'find'
require 'fileutils'
require 'pathname'
require 'erb'
require 'rubygems'
require 'rubygems/package_task'
require 'yard'
require 'jeweler'
require 'rake/extensiontask'
require 'packnga'
if YAML.const_defined?(:ENGINE)
begin
YAML::ENGINE.yamler = "psych"
rescue LoadError
end
end
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']}"
def guess_version(groonga_ext_dir)
version = {}
File.open(File.join(groonga_ext_dir, "rb-grn.h")) do |rb_grn_h|
rb_grn_h.each_line do |line|
case line
when /\A#define RB_GRN_([A-Z]+)_VERSION (\d+)/
version[$1.downcase] = $2
end
end
end
[version["major"], version["minor"], version["micro"]].join(".")
end
def cleanup_white_space(entry)
entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
end
ENV["VERSION"] ||= guess_version(groonga_ext_dir)
version = ENV["VERSION"].dup
spec = nil
Jeweler::Tasks.new do |_spec|
spec = _spec
spec.name = "rroonga"
spec.version = version
spec.rubyforge_project = "groonga"
spec.homepage = "http://groonga.rubyforge.org/"
authors = File.join(base_dir, "AUTHORS")
spec.authors = File.readlines(authors).collect do |line|
if /\s*<[^<>]*>$/ =~ line
$PREMATCH
else
nil
end
end.compact
spec.email = [
]
entries = File.read("README.textile").split(/^h2\.\s(.*)$/)
description = cleanup_white_space(entries[entries.index("Description") + 1])
spec.summary, spec.description, = description.split(/\n\n+/, 3)
spec.license = "LGPLv2"
spec.files = FileList["{lib,benchmark,misc}/**/*.rb",
"bin/*",
"*.rb",
"example/*.rb",
"Rakefile",
"Gemfile",
"ext/**/*"]
spec.test_files = FileList["test/**/*.rb"]
end
Rake::Task["release"].prerequisites.clear
Jeweler::RubygemsDotOrgTasks.new do
end
Gem::PackageTask.new(spec) do |pkg|
pkg.need_tar_gz = true
end
document_task = Packnga::DocumentTask.new(spec) do |t|
t.yard do |yard_task|
yard_task.files += FileList["ext/**/*.c"]
yard_task.options += ["--markup", "textile"]
end
end
namespace :reference do
namespace :publication do
task :keep_compatible do
File.open(document_task.htaccess, "a") do |file|
file.puts("Redirect permanent /#{spec.name}/text/TUTORIAL_ja_rdoc.html " +
"#{spec.homepage}#{spec.name}/ja/file.tutorial.html")
end
end
task :generate => :keep_compatible
end
end
Packnga::ReleaseTask.new(spec) do |task|
end
module YARD
module CodeObjects
class Proxy
alias_method :initialize_original, :initialize
def initialize(namespace, name)
name = name.gsub(/\AGrn(.*)\z/) do
suffix = $1
case suffix
when ""
"Groonga"
when "TableKeySupport"
"Groonga::Table::KeySupport"
else
"Groonga::#{suffix}"
end
end
initialize_original(namespace, name)
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
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["GROONGA32"] == "yes"
Rake::ExtensionTask.new("groonga", spec) do |ext|
if groonga_win32_i386_p
ext.cross_platform = ["x86-mingw32", "i386-mswin32"]
else
ext.cross_platform = ["x64-mingw32"]
# ext.cross_platform << "x64-mswin64" # We need to build with VC++ 2010. :<
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)
_spec.files += collect_binary_files(relative_binary_dir)
end
end
end
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