|
1 | 1 | require 'rake/clean'
|
2 | 2 | require 'rake/extensioncompiler'
|
3 | 3 |
|
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 |
17 | 38 | end
|
18 | 39 | end
|
19 |
| -end |
20 | 40 |
|
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 |
26 | 52 | end
|
27 |
| - # update file timestamp to avoid Rake perform this extraction again. |
28 |
| - touch t.name |
29 | 53 | end
|
30 |
| -end |
31 | 54 |
|
32 |
| -# clobber expanded packages |
33 |
| -CLOBBER.include("vendor/#{CONNECTOR_DIR}") |
| 55 | + # clobber expanded packages |
| 56 | + CLOBBER.include("vendor/#{vendor_mysql_dir(args[:platform])}") |
34 | 57 |
|
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