Quick hack from mysql gem.

Added vendored MySQL.
This commit is contained in:
Luis Lavena 2010-08-11 23:40:55 +08:00 committed by Brian Lopez
parent 5fb043b4da
commit db64470831
4 changed files with 64 additions and 6 deletions

2
.gitignore vendored
View File

@ -7,3 +7,5 @@ Makefile
*.rbc
mkmf.log
pkg/
tmp
vendor

View File

@ -20,8 +20,6 @@ end
require 'rake'
require 'spec/rake/spectask'
gem 'rake-compiler', '~> 0.7.1'
require "rake/extensiontask"
desc "Run all examples with RCov"
Spec::Rake::SpecTask.new('spec:rcov') do |t|
@ -36,7 +34,5 @@ Spec::Rake::SpecTask.new('spec') do |t|
t.spec_opts << '--options' << 'spec/spec.opts'
end
Rake::ExtensionTask.new("mysql2", JEWELER.gemspec) do |ext|
ext.lib_dir = File.join 'lib', 'mysql2'
end
Rake::Task[:spec].prerequisites << :compile
# Load custom tasks
Dir['tasks/*.rake'].sort.each { |f| load f }

19
tasks/compile.rake Normal file
View File

@ -0,0 +1,19 @@
gem 'rake-compiler', '~> 0.7.1'
require "rake/extensiontask"
MYSQL_VERSION = "5.1.49"
MYSQL_MIRROR = ENV['MYSQL_MIRROR'] || "http://mysql.localhost.net.ar"
Rake::ExtensionTask.new("mysql2", JEWELER.gemspec) do |ext|
# reference where the vendored MySQL got extracted
mysql_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', "mysql-#{MYSQL_VERSION}-win32"))
# automatically add build options to avoid need of manual input
if RUBY_PLATFORM =~ /mswin|mingw/ then
ext.config_options << "--with-mysql-include=#{mysql_lib}/include"
ext.config_options << "--with-mysql-lib=#{mysql_lib}/lib/opt"
end
ext.lib_dir = File.join 'lib', 'mysql2'
end
Rake::Task[:spec].prerequisites << :compile

41
tasks/vendor_mysql.rake Normal file
View File

@ -0,0 +1,41 @@
require 'rake/clean'
require 'rake/extensioncompiler'
# download mysql library and headers
directory "vendor"
file "vendor/mysql-noinstall-#{MYSQL_VERSION}-win32.zip" => ['vendor'] do |t|
base_version = MYSQL_VERSION.gsub(/\.[0-9]+$/, '')
url = "http://dev.mysql.com/get/Downloads/MySQL-#{base_version}/#{File.basename(t.name)}/from/#{MYSQL_MIRROR}/"
when_writing "downloading #{t.name}" do
cd File.dirname(t.name) do
sh "wget -c #{url} || curl -C - -O #{url}"
end
end
end
file "vendor/mysql-#{MYSQL_VERSION}-win32/include/mysql.h" => ["vendor/mysql-noinstall-#{MYSQL_VERSION}-win32.zip"] do |t|
full_file = File.expand_path(t.prerequisites.last)
when_writing "creating #{t.name}" do
cd "vendor" do
sh "unzip #{full_file} mysql-#{MYSQL_VERSION}-win32/bin/** mysql-#{MYSQL_VERSION}-win32/include/** mysql-#{MYSQL_VERSION}-win32/lib/**"
end
# update file timestamp to avoid Rake perform this extraction again.
touch t.name
end
end
# clobber expanded packages
CLOBBER.include("vendor/mysql-#{MYSQL_VERSION}-win32")
# vendor:mysql
task 'vendor:mysql' => ["vendor/mysql-#{MYSQL_VERSION}-win32/include/mysql.h"]
# hook into cross compilation vendored mysql dependency
if RUBY_PLATFORM =~ /mingw|mswin/ then
Rake::Task['compile'].prerequisites.unshift 'vendor:mysql'
else
if Rake::Task.tasks.map {|t| t.name }.include? 'cross'
Rake::Task['cross'].prerequisites.unshift 'vendor:mysql'
end
end