tiny_tds 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/tiny_tds.rb CHANGED
@@ -1,61 +1,42 @@
1
- # encoding: UTF-8
2
- require 'date'
3
- require 'bigdecimal'
4
- require 'rational'
1
+ require "date"
2
+ require "bigdecimal"
5
3
 
6
- require 'tiny_tds/version'
7
- require 'tiny_tds/error'
8
- require 'tiny_tds/client'
9
- require 'tiny_tds/result'
10
- require 'tiny_tds/gem'
4
+ require "tiny_tds/version"
5
+ require "tiny_tds/error"
6
+ require "tiny_tds/client"
7
+ require "tiny_tds/result"
8
+ require "tiny_tds/gem"
11
9
 
12
- # Support multiple ruby versions, fat binaries under Windows.
13
- if RUBY_PLATFORM =~ /mingw|mswin/ && RUBY_VERSION =~ /(\d+.\d+)/
14
- ver = Regexp.last_match(1)
10
+ module TinyTds
11
+ # Is this file part of a fat binary gem with bundled freetds?
12
+ # This path must be enabled by add_dll_directory on Windows.
13
+ gplat = ::Gem::Platform.local
14
+ FREETDS_LIB_PATH = Dir[File.expand_path("../ports/#{gplat.cpu}-#{gplat.os}*/lib", __dir__)].first
15
15
 
16
16
  add_dll_path = proc do |path, &block|
17
- begin
18
- require 'ruby_installer/runtime'
19
- RubyInstaller::Runtime.add_dll_directory(path, &block)
20
- rescue LoadError
21
- old_path = ENV['PATH']
22
- ENV['PATH'] = "#{path};#{old_path}"
17
+ if RUBY_PLATFORM =~ /(mswin|mingw)/i && path
23
18
  begin
19
+ require "ruby_installer/runtime"
20
+ RubyInstaller::Runtime.add_dll_directory(path, &block)
21
+ rescue LoadError
22
+ old_path = ENV["PATH"]
23
+ ENV["PATH"] = "#{path};#{old_path}"
24
24
  block.call
25
- ensure
26
- ENV['PATH'] = old_path
27
- end
28
- end
29
- end
30
-
31
- add_dll_paths = proc do |paths, &block|
32
- if path=paths.shift
33
- add_dll_path.call(path) do
34
- add_dll_paths.call(paths, &block)
25
+ ENV["PATH"] = old_path
35
26
  end
36
27
  else
28
+ # libsybdb is found by a relative rpath in the cross compiled extension dll
29
+ # or by the system library loader
37
30
  block.call
38
31
  end
39
32
  end
40
33
 
41
- # Temporary add bin directories for DLL search, so that freetds DLLs can be found.
42
- add_dll_paths.call( TinyTds::Gem.ports_bin_paths ) do
43
- begin
44
- require "tiny_tds/#{ver}/tiny_tds"
45
- rescue LoadError
46
- require 'tiny_tds/tiny_tds'
47
- end
48
- end
49
- else
50
- # Load dependent shared libraries into the process, so that they are already present,
51
- # when tiny_tds.so is loaded. This ensures, that shared libraries are loaded even when
52
- # the path is different between build and run time (e.g. Heroku).
53
- ports_libs = File.join(TinyTds::Gem.ports_root_path,
54
- "#{RbConfig::CONFIG['host']}/lib/*.so")
55
- Dir[ports_libs].each do |lib|
56
- require 'fiddle'
57
- Fiddle.dlopen(lib)
34
+ add_dll_path.call(FREETDS_LIB_PATH) do
35
+ # Try the <major>.<minor> subdirectory for fat binary gems
36
+ major_minor = RUBY_VERSION[/^(\d+\.\d+)/] or
37
+ raise "Oops, can't extract the major/minor version from #{RUBY_VERSION.dump}"
38
+ require "tiny_tds/#{major_minor}/tiny_tds"
39
+ rescue LoadError
40
+ require "tiny_tds/tiny_tds"
58
41
  end
59
-
60
- require 'tiny_tds/tiny_tds'
61
42
  end
@@ -1,23 +1,16 @@
1
- # encoding: UTF-8
1
+ CrossLibraries.each do |xlib|
2
+ platform = xlib.platform
2
3
 
3
- desc 'Build the native binary gems using rake-compiler-dock'
4
- task 'gem:native' => ['ports:cross'] do
5
- require 'rake_compiler_dock'
4
+ desc "Build fat binary gem for platform #{platform}"
5
+ task "gem:native:#{platform}" do
6
+ require "rake_compiler_dock"
6
7
 
7
- # make sure to install our bundle
8
- sh "bundle package --all" # Avoid repeated downloads of gems by using gem files from the host.
9
-
10
- GEM_PLATFORM_HOSTS.each do |plat, meta|
11
- RakeCompilerDock.sh "bundle --local && RUBY_CC_VERSION=#{meta[:ruby_versions]} rake native:#{plat} gem", platform: plat
8
+ RakeCompilerDock.sh <<-EOT, platform: platform
9
+ bundle install &&
10
+ rake native:#{platform} pkg/#{SPEC.full_name}-#{platform}.gem MAKEOPTS=-j`nproc` RUBY_CC_VERSION=#{RakeCompilerDock.set_ruby_cc_version("~> 2.7", "~> 3.0")} MAKEFLAGS="V=1"
11
+ EOT
12
12
  end
13
- end
14
-
15
- # assumes you are in a container provided by Rake compiler
16
- # if not, use the task above
17
- task 'gem:for_platform', [:gem_platform] do |_task, args|
18
- args.with_defaults(gem_platform: RbConfig::CONFIG["arch"])
19
13
 
20
- sh "bundle install"
21
- Rake::Task["ports:compile"].invoke(GEM_PLATFORM_HOSTS[args.gem_platform][:host], args.gem_platform)
22
- sh "RUBY_CC_VERSION=#{GEM_PLATFORM_HOSTS[args.gem_platform][:ruby_versions]} rake native:#{args.gem_platform} gem"
14
+ desc "Build the native binary gems"
15
+ multitask "gem:native" => "gem:native:#{platform}"
23
16
  end
data/tasks/package.rake CHANGED
@@ -1,8 +1,6 @@
1
- # encoding: UTF-8
2
- require 'rubygems/package_task'
1
+ require "rubygems/package_task"
3
2
 
4
3
  Gem::PackageTask.new(SPEC) do |pkg|
5
4
  pkg.need_tar = false
6
5
  pkg.need_zip = false
7
6
  end
8
-
data/tasks/ports.rake CHANGED
@@ -1,108 +1,24 @@
1
- # encoding: UTF-8
2
- require 'mini_portile2'
3
- require 'fileutils'
4
- require_relative 'ports/libiconv'
5
- require_relative 'ports/openssl'
6
- require_relative 'ports/freetds'
7
- require_relative '../ext/tiny_tds/extconsts'
1
+ require_relative "../ext/tiny_tds/extconsts"
8
2
 
9
3
  namespace :ports do
10
4
  libraries_to_compile = {
11
- openssl: Ports::Openssl.new(OPENSSL_VERSION),
12
- libiconv: Ports::Libiconv.new(ICONV_VERSION),
13
- freetds: Ports::Freetds.new(FREETDS_VERSION)
5
+ openssl: OPENSSL_VERSION,
6
+ libiconv: ICONV_VERSION,
7
+ freetds: FREETDS_VERSION
14
8
  }
15
9
 
16
- directory "ports"
17
- CLEAN.include "ports/*mingw*"
18
- CLEAN.include "ports/*.installed"
19
-
20
- task :openssl, [:host, :gem_platform] do |_task, args|
21
- args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
22
-
23
- libraries_to_compile[:openssl].files = [OPENSSL_SOURCE_URI]
24
- libraries_to_compile[:openssl].host = args.host
25
- libraries_to_compile[:openssl].gem_platform = args.gem_platform
26
-
27
- libraries_to_compile[:openssl].cook
28
- libraries_to_compile[:openssl].activate
29
- end
30
-
31
- task :libiconv, [:host, :gem_platform] do |_task, args|
32
- args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
33
-
34
- libraries_to_compile[:libiconv].files = [ICONV_SOURCE_URI]
35
- libraries_to_compile[:libiconv].host = args.host
36
- libraries_to_compile[:libiconv].gem_platform = args.gem_platform
37
- libraries_to_compile[:libiconv].cook
38
- libraries_to_compile[:libiconv].activate
39
- end
40
-
41
- task :freetds, [:host, :gem_platform] do |_task, args|
42
- args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
43
-
44
- libraries_to_compile[:freetds].files = [FREETDS_SOURCE_URI]
45
- libraries_to_compile[:freetds].host = args.host
46
- libraries_to_compile[:freetds].gem_platform = args.gem_platform
47
-
48
- if libraries_to_compile[:openssl]
49
- # freetds doesn't have an option that will provide an rpath
50
- # so we do it manually
51
- ENV['OPENSSL_CFLAGS'] = "-Wl,-rpath -Wl,#{libraries_to_compile[:openssl].path}/lib64"
52
- # Add the pkgconfig file with MSYS2'ish path, to prefer our ports build
53
- # over MSYS2 system OpenSSL.
54
- ENV['PKG_CONFIG_PATH'] = "#{libraries_to_compile[:openssl].path.gsub(/^(\w):/i) { "/" + $1.downcase }}/lib64/pkgconfig:#{ENV['PKG_CONFIG_PATH']}"
55
- libraries_to_compile[:freetds].configure_options << "--with-openssl=#{libraries_to_compile[:openssl].path}"
56
- end
57
-
58
- if libraries_to_compile[:libiconv]
59
- libraries_to_compile[:freetds].configure_options << "--with-libiconv-prefix=#{libraries_to_compile[:libiconv].path}"
60
- end
61
-
62
- libraries_to_compile[:freetds].cook
63
- libraries_to_compile[:freetds].activate
64
- end
65
-
66
- task :compile, [:host, :gem_platform] do |_task, args|
67
- args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
68
-
69
- puts "Compiling ports for #{args.host} (Ruby platform #{args.gem_platform}) ..."
70
-
71
- libraries_to_compile.keys.each do |lib|
72
- Rake::Task["ports:#{lib}"].invoke(args.host, args.gem_platform)
73
- end
74
- end
75
-
76
- desc 'Build the ports windows binaries via rake-compiler-dock'
77
- task 'cross' do
78
- require 'rake_compiler_dock'
79
-
80
- # build the ports for all our cross compile hosts
81
- GEM_PLATFORM_HOSTS.each do |gem_platform, meta|
82
- # make sure to install our bundle
83
- build = ['bundle']
84
- build << "RUBY_CC_VERSION=#{meta[:ruby_versions]} rake ports:compile[#{meta[:host]},#{gem_platform}] MAKE='make -j`nproc`'"
85
- RakeCompilerDock.sh build.join(' && '), platform: gem_platform
86
- end
87
- end
88
-
89
10
  desc "Notes the actual versions for the compiled ports into a file"
90
11
  task "version_file", [:gem_platform] do |_task, args|
91
12
  args.with_defaults(gem_platform: RbConfig::CONFIG["arch"])
92
13
 
93
14
  ports_version = {}
94
15
 
95
- libraries_to_compile.each do |library, library_recipe|
96
- ports_version[library] = library_recipe.version
16
+ libraries_to_compile.each do |library, version|
17
+ ports_version[library] = version
97
18
  end
98
19
 
99
20
  ports_version[:platform] = args.gem_platform
100
21
 
101
- File.open(".ports_versions", "w") do |f|
102
- f.write ports_version
103
- end
22
+ File.write(".ports_versions", ports_version)
104
23
  end
105
24
  end
106
-
107
- desc 'Build ports and activate libraries for the current architecture.'
108
- task :ports => ['ports:compile']
data/tasks/test.rake CHANGED
@@ -1,9 +1,7 @@
1
- # encoding: UTF-8
2
- require 'rake/testtask'
1
+ require "rake/testtask"
3
2
 
4
3
  Rake::TestTask.new do |t|
5
- t.libs << 'test'
6
- t.test_files = FileList['test/**/*_test.rb']
4
+ t.libs << "test"
5
+ t.test_files = FileList["test/**/*_test.rb"]
7
6
  t.verbose = true
8
7
  end
9
-
@@ -10,11 +10,9 @@ fi
10
10
  wget http://www.freetds.org/files/stable/freetds-$FREETDS_VERSION.tar.gz
11
11
  tar -xzf freetds-$FREETDS_VERSION.tar.gz
12
12
  cd freetds-$FREETDS_VERSION
13
- ./configure --prefix=/opt/local \
14
- --with-openssl=/opt/local \
15
- --with-tdsver=7.3
13
+ ./configure
16
14
  make
17
- make install
15
+ sudo make install
18
16
  cd ..
19
17
  rm -rf freetds-$FREETDS_VERSION
20
18
  rm freetds-$FREETDS_VERSION.tar.gz
@@ -0,0 +1,10 @@
1
+ $gemVersion = (Get-Content VERSION).Trim()
2
+ $gemToUnpack = "./tiny_tds-$gemVersion-$env:RUBY_ARCHITECTURE.gem"
3
+
4
+ Write-Host "Looking to unpack $gemToUnpack"
5
+ gem unpack --target ./tmp "$gemToUnpack"
6
+
7
+ # Restore precompiled code
8
+ $source = (Resolve-Path ".\tmp\tiny_tds-$gemVersion-$env:RUBY_ARCHITECTURE\lib\tiny_tds").Path
9
+ $destination = (Resolve-Path ".\lib\tiny_tds").Path
10
+ Get-ChildItem $source -Recurse -Exclude "*.rb" | Copy-Item -Destination {Join-Path $destination $_.FullName.Substring($source.length)}