Skip to content

Commit df58a81

Browse files
committed
Wrap vendor:mysql tasks with a platform argument
1 parent 0eade9f commit df58a81

File tree

2 files changed

+57
-32
lines changed

2 files changed

+57
-32
lines changed

tasks/compile.rake

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
1414
if RUBY_PLATFORM =~ /mswin|mingw/ then
1515
Rake::Task['vendor:mysql'].invoke
1616
# Expand the path because the build dir is 3-4 levels deep in tmp/platform/version/
17-
connector_dir = File.expand_path("../../vendor/#{CONNECTOR_DIR}", __FILE__)
17+
connector_dir = File.expand_path("../../vendor/#{vendor_mysql_dir}", __FILE__)
1818
ext.config_options = [ "--with-mysql-dir=#{connector_dir}" ]
1919
else
20+
Rake::Task['vendor:mysql'].invoke('x86')
21+
Rake::Task['vendor:mysql'].invoke('x64')
2022
ext.cross_compile = true
2123
ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60', 'x64-mingw32']
2224
ext.cross_config_options = {
23-
'x86-mingw32' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/mysql-connector-c-#{CONNECTOR_VERSION}-win32", __FILE__) ],
24-
'x86-mswin32-60' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/mysql-connector-c-#{CONNECTOR_VERSION}-win32", __FILE__) ],
25-
'x64-mingw32' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/mysql-connector-c-#{CONNECTOR_VERSION}-winx64", __FILE__) ],
25+
'x86-mingw32' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/#{vendor_mysql_dir('x86')}", __FILE__) ],
26+
'x86-mswin32-60' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/#{vendor_mysql_dir('x86')}", __FILE__) ],
27+
'x64-mingw32' => [ "--with-mysql-dir=" + File.expand_path("../../vendor/#{vendor_mysql_dir('x64')}", __FILE__) ],
2628
}
2729

2830
ext.cross_compiling do |spec|
2931
Rake::Task['lib/mysql2/mysql2.rb'].invoke
30-
Rake::Task['vendor:mysql'].invoke(spec.platform)
3132
spec.files << 'lib/mysql2/mysql2.rb'
3233
spec.files << 'vendor/libmysql.dll'
3334
spec.post_install_message = <<-POST_INSTALL_MESSAGE
@@ -41,7 +42,7 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
4142
At the time of building this gem, the necessary DLL files were available
4243
in the following download:
4344
44-
http://dev.mysql.com/get/Downloads/Connector-C/#{CONNECTOR_ZIP}/from/pick
45+
#{vendor_mysql_url(spec.platform)}
4546
4647
And put lib\\libmysql.dll file in your Ruby bin directory, for example C:\\Ruby\\bin
4748

tasks/vendor_mysql.rake

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,60 @@
11
require 'rake/clean'
22
require 'rake/extensioncompiler'
33

4-
CONNECTOR_VERSION = "6.1.5" #"mysql-connector-c-6.1.5-win32.zip"
5-
CONNECTOR_PLATFORM = RUBY_PLATFORM =~ /x64/ ? "winx64" : "win32"
6-
CONNECTOR_DIR = "mysql-connector-c-#{CONNECTOR_VERSION}-#{CONNECTOR_PLATFORM}"
7-
CONNECTOR_ZIP = "mysql-connector-c-#{CONNECTOR_VERSION}-#{CONNECTOR_PLATFORM}.zip"
8-
9-
# download mysql library and headers
10-
directory "vendor"
11-
12-
file "vendor/#{CONNECTOR_ZIP}" => ["vendor"] do |t|
13-
url = "http://cdn.mysql.com/Downloads/Connector-C/#{CONNECTOR_ZIP}"
14-
when_writing "downloading #{t.name}" do
15-
cd File.dirname(t.name) do
16-
sh "curl -C - -O #{url} || wget -c #{url}"
4+
CONNECTOR_VERSION = "6.1.5" # NOTE: Track the upstream version from time to time
5+
6+
def vendor_mysql_platform(platform=nil)
7+
platform ||= RUBY_PLATFORM
8+
platform =~ /x64/ ? "winx64" : "win32"
9+
end
10+
11+
def vendor_mysql_dir(*args)
12+
"mysql-connector-c-#{CONNECTOR_VERSION}-#{vendor_mysql_platform(*args)}"
13+
end
14+
15+
def vendor_mysql_zip(*args)
16+
"#{vendor_mysql_dir(*args)}.zip"
17+
end
18+
19+
def vendor_mysql_url(*args)
20+
"http://cdn.mysql.com/Downloads/Connector-C/#{vendor_mysql_zip(*args)}"
21+
end
22+
23+
# vendor:mysql
24+
task "vendor:mysql", [:platform] do |t, args|
25+
puts "vendor:mysql for #{vendor_mysql_dir(args[:platform])}"
26+
27+
# download mysql library and headers
28+
directory "vendor"
29+
30+
file "vendor/#{vendor_mysql_zip(args[:platform])}" => ["vendor"] do |t|
31+
url = vendor_mysql_url(args[:platform])
32+
when_writing "downloading #{t.name}" do
33+
cd "vendor" do
34+
sh "curl", "-C", "-", "-O", url do |ok, res|
35+
sh "wget", "-c", url if ! ok
36+
end
37+
end
1738
end
1839
end
19-
end
2040

21-
file "vendor/#{CONNECTOR_DIR}/include/mysql.h" => ["vendor/#{CONNECTOR_ZIP}"] do |t|
22-
full_file = File.expand_path(t.prerequisites.last)
23-
when_writing "creating #{t.name}" do
24-
cd "vendor" do
25-
sh "unzip -uq #{full_file} #{CONNECTOR_DIR}/bin/** #{CONNECTOR_DIR}/include/** #{CONNECTOR_DIR}/lib/**"
41+
file "vendor/#{vendor_mysql_dir(args[:platform])}/include/mysql.h" => ["vendor/#{vendor_mysql_zip(args[:platform])}"] do |t|
42+
full_file = File.expand_path(t.prerequisites.last)
43+
when_writing "creating #{t.name}" do
44+
cd "vendor" do
45+
sh "unzip", "-uq", full_file,
46+
"#{vendor_mysql_dir(args[:platform])}/bin/**",
47+
"#{vendor_mysql_dir(args[:platform])}/include/**",
48+
"#{vendor_mysql_dir(args[:platform])}/lib/**"
49+
end
50+
# update file timestamp to avoid Rake perform this extraction again.
51+
touch t.name
2652
end
27-
# update file timestamp to avoid Rake perform this extraction again.
28-
touch t.name
2953
end
30-
end
3154

32-
# clobber expanded packages
33-
CLOBBER.include("vendor/#{CONNECTOR_DIR}")
55+
# clobber expanded packages
56+
CLOBBER.include("vendor/#{vendor_mysql_dir(args[:platform])}")
3457

35-
# vendor:mysql
36-
task 'vendor:mysql' => "vendor/#{CONNECTOR_DIR}/include/mysql.h"
58+
Rake::Task["vendor/#{vendor_mysql_dir(args[:platform])}/include/mysql.h"].invoke
59+
Rake::Task["vendor:mysql"].reenable # allow task to be invoked again (with another platform)
60+
end

0 commit comments

Comments
 (0)