tiny_tds 1.3.0-x64-mingw32 → 2.0.0.pre1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/lib/tiny_tds.rb CHANGED
@@ -7,6 +7,7 @@ require 'tiny_tds/version'
7
7
  require 'tiny_tds/error'
8
8
  require 'tiny_tds/client'
9
9
  require 'tiny_tds/result'
10
+ require 'tiny_tds/gem'
10
11
 
11
12
  # Support multiple ruby versions, fat binaries under Windows.
12
13
  if RUBY_PLATFORM =~ /mingw|mswin/ && RUBY_VERSION =~ /(\d+.\d+)/
@@ -14,9 +15,12 @@ if RUBY_PLATFORM =~ /mingw|mswin/ && RUBY_VERSION =~ /(\d+.\d+)/
14
15
  # Set the PATH environment variable, so that the DLLs can be found.
15
16
  old_path = ENV['PATH']
16
17
  begin
17
- # Do the same host consolidation as in extconf.rb
18
- ports_dir = RbConfig::CONFIG['host'].gsub('i686-pc-mingw32', 'i686-w64-mingw32')
19
- ENV['PATH'] = "#{File.expand_path("../../ports/#{ports_dir}/bin", __FILE__)};#{old_path}"
18
+ ENV['PATH'] = [
19
+ TinyTds::Gem.ports_bin_paths,
20
+ TinyTds::Gem.ports_lib_paths,
21
+ old_path
22
+ ].flatten.join File::PATH_SEPARATOR
23
+
20
24
  require "tiny_tds/#{ver}/tiny_tds"
21
25
  rescue LoadError
22
26
  require 'tiny_tds/tiny_tds'
@@ -27,7 +31,8 @@ else
27
31
  # Load dependent shared libraries into the process, so that they are already present,
28
32
  # when tiny_tds.so is loaded. This ensures, that shared libraries are loaded even when
29
33
  # the path is different between build and run time (e.g. Heroku).
30
- ports_libs = File.expand_path("../../ports/#{RbConfig::CONFIG['host']}/lib/*.so", __FILE__)
34
+ ports_libs = File.join(TinyTds::Gem.ports_root_path,
35
+ "#{RbConfig::CONFIG['host']}/lib/*.so")
31
36
  Dir[ports_libs].each do |lib|
32
37
  require 'fiddle'
33
38
  Fiddle.dlopen(lib)
data/lib/tiny_tds/bin.rb CHANGED
@@ -1,40 +1,39 @@
1
1
  require_relative './version'
2
+ require_relative './gem'
2
3
  require 'shellwords'
3
4
 
4
5
  module TinyTds
5
6
  class Bin
6
7
 
7
- ROOT = File.expand_path '../../..', __FILE__
8
- PATHS = ENV['PATH'].split File::PATH_SEPARATOR
9
- EXTS = (ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']) | ['.exe']
10
-
11
8
  attr_reader :name
12
9
 
13
10
  class << self
14
-
15
11
  def exe(name, *args)
16
12
  bin = new(name)
17
13
  puts bin.info unless args.any? { |x| x == '-q' }
18
14
  bin.run(*args)
19
15
  end
20
-
21
16
  end
22
17
 
23
18
  def initialize(name)
19
+ @root = Gem.root_path
20
+ @exts = (ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']) | ['.exe']
21
+
24
22
  @name = name
25
23
  @binstub = find_bin
26
24
  @exefile = find_exe
27
25
  end
28
26
 
29
27
  def run(*args)
30
- return nil unless path
31
- Kernel.system Shellwords.join(args.unshift(path))
32
- $CHILD_STATUS.to_i
28
+ with_ports_paths do
29
+ return nil unless path
30
+ Kernel.system Shellwords.join(args.unshift(path))
31
+ $CHILD_STATUS.to_i
32
+ end
33
33
  end
34
34
 
35
35
  def path
36
- return @path if defined?(@path)
37
- @path = @exefile && File.exist?(@exefile) ? @exefile : which
36
+ @path ||= @exefile && File.exist?(@exefile) ? @exefile : which
38
37
  end
39
38
 
40
39
  def info
@@ -43,22 +42,43 @@ module TinyTds
43
42
 
44
43
  private
45
44
 
45
+ def search_paths
46
+ ENV['PATH'].split File::PATH_SEPARATOR
47
+ end
48
+
49
+ def with_ports_paths
50
+ old_path = ENV['PATH']
51
+
52
+ begin
53
+ ENV['PATH'] = [
54
+ Gem.ports_bin_paths,
55
+ old_path
56
+ ].flatten.join File::PATH_SEPARATOR
57
+
58
+ yield if block_given?
59
+ ensure
60
+ ENV['PATH'] = old_path
61
+ end
62
+ end
63
+
46
64
  def find_bin
47
- File.join ROOT, 'bin', name
65
+ File.join @root, 'bin', name
48
66
  end
49
67
 
50
68
  def find_exe
51
- EXTS.each do |ext|
52
- f = File.join ROOT, 'exe', "#{name}#{ext}"
53
- return f if File.exist?(f)
69
+ Gem.ports_bin_paths.each do |bin|
70
+ @exts.each do |ext|
71
+ f = File.join bin, "#{name}#{ext}"
72
+ return f if File.exist?(f)
73
+ end
54
74
  end
55
75
  nil
56
76
  end
57
77
 
58
78
  def which
59
- PATHS.each do |path|
60
- EXTS.each do |ext|
61
- exe = File.expand_path File.join(path, "#{name}#{ext}"), ROOT
79
+ search_paths.each do |path|
80
+ @exts.each do |ext|
81
+ exe = File.expand_path File.join(path, "#{name}#{ext}"), @root
62
82
  next if exe == @binstub
63
83
  next unless File.executable?(exe)
64
84
  next unless binary?(exe)
@@ -80,6 +100,5 @@ module TinyTds
80
100
  s = s.encode('US-ASCII', undef: :replace).split(//)
81
101
  ((s.size - s.grep(' '..'~').size) / s.size.to_f) > 0.30
82
102
  end
83
-
84
103
  end
85
104
  end
@@ -0,0 +1,32 @@
1
+ require 'rbconfig'
2
+
3
+ module TinyTds
4
+ module Gem
5
+ class << self
6
+ def root_path
7
+ File.expand_path '../../..', __FILE__
8
+ end
9
+
10
+ def ports_root_path
11
+ File.join(root_path,'ports')
12
+ end
13
+
14
+ def ports_bin_paths
15
+ Dir.glob(File.join(ports_root_path,ports_host,'**','bin'))
16
+ end
17
+
18
+ def ports_lib_paths
19
+ Dir.glob(File.join(ports_root_path,ports_host,'**','lib'))
20
+ end
21
+
22
+ def ports_host
23
+ h = RbConfig::CONFIG['host']
24
+
25
+ # Our fat binary builds with a i686-w64-mingw32 toolchain
26
+ # but ruby for windows x32-mingw32 reports i686-pc-mingw32
27
+ # so correct the host here
28
+ h.gsub('i686-pc-mingw32', 'i686-w64-mingw32')
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,17 @@
1
+ --- a/srclib/stdio.in.h 2017-01-22 01:23:00.000000000 -0400
2
+ +++ b/srclib/stdio.in.h 2017-01-22 01:24:00.000000000 -0400
3
+ @@ -695,8 +695,14 @@
4
+ /* It is very rare that the developer ever has full control of stdin,
5
+ so any use of gets warrants an unconditional warning. Assume it is
6
+ always declared, since it is required by C89. */
7
+ +#if defined(__GLIBC__) && !defined(__UCLIBC__)
8
+ +# ifdef __GLIBC_PREREQ
9
+ +# if !__GLIBC_PREREQ(2, 16)
10
+ _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
11
+ +# endif
12
+ +# endif
13
+ +#endif
14
+ #endif
15
+
16
+
17
+ #if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+
3
+ desc 'Build the windows binary gems per rake-compiler-dock'
4
+ task 'gem:windows' => ['ports:cross'] do
5
+ require 'rake_compiler_dock'
6
+
7
+ # make sure to install our bundle
8
+ build = ['bundle']
9
+
10
+ # and finally build the native gem
11
+ build << 'rake cross native gem RUBY_CC_VERSION=2.4.0:2.3.0:2.2.2:2.1.6:2.0.0 CFLAGS="-Wall"'
12
+
13
+ RakeCompilerDock.sh build.join(' && ')
14
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems/package_task'
3
+
4
+ Gem::PackageTask.new(SPEC) do |pkg|
5
+ pkg.need_tar = false
6
+ pkg.need_zip = false
7
+ end
8
+
data/tasks/ports.rake ADDED
@@ -0,0 +1,84 @@
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'
8
+
9
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE if defined? OpenSSL
10
+
11
+ namespace :ports do
12
+ openssl = Ports::Openssl.new(OPENSSL_VERSION)
13
+ libiconv = Ports::Libiconv.new(ICONV_VERSION)
14
+ freetds = Ports::Freetds.new(FREETDS_VERSION)
15
+
16
+ directory "ports"
17
+
18
+ task :openssl, [:host] do |task, args|
19
+ args.with_defaults(host: RbConfig::CONFIG['host'])
20
+
21
+ openssl.files = [OPENSSL_SOURCE_URI]
22
+ openssl.host = args.host
23
+ openssl.cook
24
+ openssl.activate
25
+ end
26
+
27
+ task :libiconv, [:host] do |task, args|
28
+ args.with_defaults(host: RbConfig::CONFIG['host'])
29
+
30
+ libiconv.files = [ICONV_SOURCE_URI]
31
+ libiconv.host = args.host
32
+ libiconv.cook
33
+ libiconv.activate
34
+ end
35
+
36
+ task :freetds, [:host] do |task, args|
37
+ args.with_defaults(host: RbConfig::CONFIG['host'])
38
+
39
+ freetds.files = [FREETDS_SOURCE_URI]
40
+ freetds.host = args.host
41
+
42
+ if openssl
43
+ # freetds doesn't have an option that will provide an rpath
44
+ # so we do it manually
45
+ ENV['OPENSSL_CFLAGS'] = "-Wl,-rpath -Wl,#{openssl.path}/lib"
46
+ freetds.configure_options << "--with-openssl=#{openssl.path}"
47
+ end
48
+
49
+ if libiconv
50
+ freetds.configure_options << "--with-libiconv-prefix=#{libiconv.path}"
51
+ end
52
+
53
+ freetds.cook
54
+ freetds.activate
55
+ end
56
+
57
+ task :compile, [:host] do |task,args|
58
+ args.with_defaults(host: RbConfig::CONFIG['host'])
59
+
60
+ puts "Compiling ports for #{args.host}..."
61
+
62
+ ['openssl','libiconv','freetds'].each do |lib|
63
+ Rake::Task["ports:#{lib}"].invoke(args.host)
64
+ end
65
+ end
66
+
67
+ desc 'Build the ports windows binaries via rake-compiler-dock'
68
+ task 'cross' do
69
+ require 'rake_compiler_dock'
70
+
71
+ # make sure to install our bundle
72
+ build = ['bundle']
73
+
74
+ # build the ports for all our cross compile hosts
75
+ GEM_PLATFORM_HOSTS.each do |gem_platform, host|
76
+ build << "rake ports:compile[#{host}]"
77
+ end
78
+
79
+ RakeCompilerDock.sh build.join(' && ')
80
+ end
81
+ end
82
+
83
+ desc 'Build ports and activate libraries for the current architecture.'
84
+ task :ports => ['ports:compile']
@@ -0,0 +1,37 @@
1
+ require_relative './recipe'
2
+
3
+ module Ports
4
+ class Freetds < Recipe
5
+ def initialize(version)
6
+ super('freetds', version)
7
+
8
+ set_patches
9
+ end
10
+
11
+ private
12
+
13
+ def configure_defaults
14
+ opts = super
15
+
16
+ opts << '--with-pic'
17
+ opts << '--disable-odbc'
18
+
19
+ if version =~ /0\.91/
20
+ opts << '--with-tdsver=7.1'
21
+ else
22
+ opts << '--with-tdsver=7.3'
23
+ end
24
+
25
+ if windows?
26
+ opts << '--sysconfdir=C:\Sites'
27
+ opts << '--enable-sspi'
28
+ end
29
+
30
+ opts
31
+ end
32
+
33
+ def set_patches
34
+ self.patch_files.concat get_patches(name, version)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,43 @@
1
+ require_relative './recipe'
2
+
3
+ module Ports
4
+ class Libiconv < Recipe
5
+ def initialize(version)
6
+ super('libiconv', version)
7
+
8
+ set_patches
9
+ end
10
+
11
+ def cook
12
+ chdir_for_build do
13
+ super
14
+ end
15
+ self
16
+ end
17
+
18
+ private
19
+
20
+ # When using rake-compiler-dock on Windows, the underlying Virtualbox shared
21
+ # folders don't support symlinks, but libiconv expects it for a build on
22
+ # Linux. We work around this limitation by using the temp dir for cooking.
23
+ def chdir_for_build
24
+ build_dir = ENV['RCD_HOST_RUBY_PLATFORM'].to_s =~ /mingw|mswin|cygwin/ ? '/tmp' : '.'
25
+ Dir.chdir(build_dir) do
26
+ yield
27
+ end
28
+ end
29
+
30
+ def configure_defaults
31
+ [
32
+ "--host=#{@host}",
33
+ '--disable-static',
34
+ '--enable-shared',
35
+ 'CFLAGS=-fPIC -O2'
36
+ ]
37
+ end
38
+
39
+ def set_patches
40
+ self.patch_files.concat get_patches(name, version)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,75 @@
1
+ require_relative './recipe'
2
+
3
+ module Ports
4
+ class Openssl < Recipe
5
+ def initialize(version)
6
+ super('openssl', version)
7
+
8
+ set_patches
9
+ end
10
+
11
+ def configure
12
+ return if configured?
13
+
14
+ md5_file = File.join(tmp_path, 'configure.md5')
15
+ digest = Digest::MD5.hexdigest(computed_options.to_s)
16
+ File.open(md5_file, "w") { |f| f.write digest }
17
+
18
+ # Windows doesn't recognize the shebang so always explicitly use sh
19
+ execute('configure', "sh -c \"./Configure #{computed_options.join(' ')}\"")
20
+ end
21
+
22
+ def install
23
+ unless installed?
24
+ execute('install', %Q(#{make_cmd} install_sw install_ssldirs))
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def execute(action, command, options={})
31
+ prev_path = ENV['PATH']
32
+ if host =~ /mingw/
33
+ git_perl = 'C:/Program Files/Git/usr/bin'
34
+ if File.directory?(git_perl)
35
+ ENV['PATH'] = "#{git_perl}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
36
+ ENV['PERL'] = 'perl'
37
+ end
38
+ end
39
+
40
+ super
41
+ ENV['PATH'] = prev_path
42
+ end
43
+
44
+ def configure_defaults
45
+ opts = [
46
+ 'shared',
47
+ target_arch
48
+ ]
49
+
50
+ if cross_build?
51
+ opts << "--cross-compile-prefix=#{host}-"
52
+ end
53
+
54
+ opts
55
+ end
56
+
57
+ def target_arch
58
+ if windows?
59
+ arch = ''
60
+ arch = '64' if host=~ /x86_64/
61
+
62
+ "mingw#{arch}"
63
+ else
64
+ arch = 'x32'
65
+ arch = 'x86_64' if host=~ /x86_64/
66
+
67
+ "linux-#{arch}"
68
+ end
69
+ end
70
+
71
+ def set_patches
72
+ self.patch_files.concat get_patches(name, version)
73
+ end
74
+ end
75
+ end