tiny_tds 1.3.0 → 2.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,52 @@
1
+ # encoding: UTF-8
2
+ require 'mini_portile2'
3
+ require 'fileutils'
4
+ require 'rbconfig'
5
+
6
+ module Ports
7
+ class Recipe < MiniPortile
8
+ def cook
9
+ checkpoint = "ports/#{name}-#{version}-#{host}.installed"
10
+
11
+ unless File.exist? checkpoint
12
+ super
13
+ FileUtils.touch checkpoint
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def configure_defaults
20
+ [
21
+ "--host=#{@host}",
22
+ '--disable-static',
23
+ '--enable-shared'
24
+ ]
25
+ end
26
+
27
+ def windows?
28
+ host =~ /mswin|mingw32/
29
+ end
30
+
31
+ def system_host
32
+ RbConfig::CONFIG['host']
33
+ end
34
+
35
+ def cross_build?
36
+ host != system_host
37
+ end
38
+
39
+ def get_patches(libname, version)
40
+ patches = []
41
+
42
+ patch_path = File.expand_path(
43
+ File.join('..','..','..','patches',libname,version),
44
+ __FILE__
45
+ )
46
+
47
+ patches.concat(Dir[File.join(patch_path, '*.patch')].sort)
48
+ patches.concat(Dir[File.join(patch_path, '*.diff')].sort)
49
+ end
50
+ end
51
+ end
52
+
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']
data/tasks/test.rake ADDED
@@ -0,0 +1,9 @@
1
+ # encoding: UTF-8
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+
@@ -10,9 +10,9 @@ fi
10
10
  wget https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz
11
11
  tar -xzf openssl-$OPENSSL_VERSION.tar.gz
12
12
  cd openssl-$OPENSSL_VERSION
13
- ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
13
+ ./config --prefix=/opt/local --openssldir=/opt/local
14
14
  make
15
- make install
15
+ make install_sw install_ssldirs
16
16
  cd ..
17
17
  rm -rf openssl-$OPENSSL_VERSION
18
18
  rm openssl-$OPENSSL_VERSION.tar.gz
data/test/bin/setup.sh CHANGED
@@ -3,7 +3,7 @@
3
3
  set -x
4
4
  set -e
5
5
 
6
- tag=1.4
6
+ tag=2.0
7
7
 
8
8
  docker pull metaskills/mssql-server-linux-tinytds:$tag
9
9
 
data/test/gem_test.rb ADDED
@@ -0,0 +1,179 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+ require 'tiny_tds/gem'
4
+
5
+ class GemTest < MiniTest::Spec
6
+ gem_root ||= File.expand_path '../..', __FILE__
7
+
8
+ describe TinyTds::Gem do
9
+
10
+ # We're going to muck with some system globals so lets make sure
11
+ # they get set back later
12
+ original_host = RbConfig::CONFIG['host']
13
+ original_pwd = Dir.pwd
14
+
15
+ after do
16
+ RbConfig::CONFIG['host'] = original_host
17
+ Dir.chdir original_pwd
18
+ end
19
+
20
+ describe '#root_path' do
21
+ let(:root_path) { TinyTds::Gem.root_path }
22
+
23
+ it 'should be the root path' do
24
+ root_path.must_equal gem_root
25
+ end
26
+
27
+ it 'should be the root path no matter the cwd' do
28
+ Dir.chdir '/'
29
+
30
+ root_path.must_equal gem_root
31
+ end
32
+ end
33
+
34
+ describe '#ports_root_path' do
35
+ let(:ports_root_path) { TinyTds::Gem.ports_root_path }
36
+
37
+ it 'should be the ports path' do
38
+ ports_root_path.must_equal File.join(gem_root,'ports')
39
+ end
40
+
41
+ it 'should be the ports path no matter the cwd' do
42
+ Dir.chdir '/'
43
+
44
+ ports_root_path.must_equal File.join(gem_root,'ports')
45
+ end
46
+ end
47
+
48
+ describe '#ports_bin_paths' do
49
+ let(:ports_bin_paths) { TinyTds::Gem.ports_bin_paths }
50
+
51
+ describe 'when the ports directories exist' do
52
+ let(:fake_bin_paths) do
53
+ ports_host_root = File.join(gem_root, 'ports', 'fake-host-with-dirs')
54
+ [
55
+ File.join('a','bin'),
56
+ File.join('a','inner','bin'),
57
+ File.join('b','bin')
58
+ ].map do |p|
59
+ File.join(ports_host_root, p)
60
+ end
61
+ end
62
+
63
+ before do
64
+ RbConfig::CONFIG['host'] = 'fake-host-with-dirs'
65
+ fake_bin_paths.each do |path|
66
+ FileUtils.mkdir_p(path)
67
+ end
68
+ end
69
+
70
+ after do
71
+ FileUtils.remove_entry_secure(
72
+ File.join(gem_root, 'ports', 'fake-host-with-dirs'), true
73
+ )
74
+ end
75
+
76
+ it 'should return all the bin directories' do
77
+ ports_bin_paths.sort.must_equal fake_bin_paths.sort
78
+ end
79
+
80
+ it 'should return all the bin directories regardless of cwd' do
81
+ Dir.chdir '/'
82
+ ports_bin_paths.sort.must_equal fake_bin_paths.sort
83
+ end
84
+ end
85
+
86
+ describe 'when the ports directories are missing' do
87
+ before do
88
+ RbConfig::CONFIG['host'] = 'fake-host-without-dirs'
89
+ end
90
+
91
+ it 'should return no directories' do
92
+ ports_bin_paths.must_be_empty
93
+ end
94
+
95
+ it 'should return no directories regardless of cwd' do
96
+ Dir.chdir '/'
97
+ ports_bin_paths.must_be_empty
98
+ end
99
+ end
100
+ end
101
+
102
+ describe '#ports_lib_paths' do
103
+ let(:ports_lib_paths) { TinyTds::Gem.ports_lib_paths }
104
+
105
+ describe 'when the ports directories exist' do
106
+ let(:fake_lib_paths) do
107
+ ports_host_root = File.join(gem_root, 'ports', 'fake-host-with-dirs')
108
+ [
109
+ File.join('a','lib'),
110
+ File.join('a','inner','lib'),
111
+ File.join('b','lib')
112
+ ].map do |p|
113
+ File.join(ports_host_root, p)
114
+ end
115
+ end
116
+
117
+ before do
118
+ RbConfig::CONFIG['host'] = 'fake-host-with-dirs'
119
+ fake_lib_paths.each do |path|
120
+ FileUtils.mkdir_p(path)
121
+ end
122
+ end
123
+
124
+ after do
125
+ FileUtils.remove_entry_secure(
126
+ File.join(gem_root, 'ports', 'fake-host-with-dirs'), true
127
+ )
128
+ end
129
+
130
+ it 'should return all the lib directories' do
131
+ ports_lib_paths.sort.must_equal fake_lib_paths.sort
132
+ end
133
+
134
+ it 'should return all the lib directories regardless of cwd' do
135
+ Dir.chdir '/'
136
+ ports_lib_paths.sort.must_equal fake_lib_paths.sort
137
+ end
138
+ end
139
+
140
+ describe 'when the ports directories are missing' do
141
+ before do
142
+ RbConfig::CONFIG['host'] = 'fake-host-without-dirs'
143
+ end
144
+
145
+
146
+ it 'should return no directories' do
147
+ ports_lib_paths.must_be_empty
148
+ end
149
+
150
+ it 'should return no directories regardless of cwd' do
151
+ Dir.chdir '/'
152
+ ports_lib_paths.must_be_empty
153
+ end
154
+ end
155
+ end
156
+
157
+ describe '#ports_host' do
158
+ {
159
+ 'i686-pc-linux-gnu' => 'i686-pc-linux-gnu',
160
+ 'x86_64-pc-linux-gnu' => 'x86_64-pc-linux-gnu',
161
+ 'i686-w64-mingw32' => 'i686-w64-mingw32',
162
+ 'x86_64-w64-mingw32' => 'x86_64-w64-mingw32',
163
+ # consolidate this host to our build w64-mingw32 arch
164
+ 'i686-pc-mingw32' => 'i686-w64-mingw32'
165
+ }.each do |host,expected|
166
+ describe "on a #{host} architecture" do
167
+ before do
168
+ RbConfig::CONFIG['host'] = host
169
+ end
170
+
171
+ it "should return a #{expected} ports host" do
172
+ TinyTds::Gem.ports_host.must_equal expected
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end
179
+
data/test/result_test.rb CHANGED
@@ -135,10 +135,10 @@ class ResultTest < TinyTds::TestCase
135
135
  text = 'test affected rows sql'
136
136
  @client.execute("DELETE FROM [datatypes]").do
137
137
  afrows = @client.execute("SELECT @@ROWCOUNT AS AffectedRows").each.first['AffectedRows']
138
- assert_instance_of Fixnum, afrows
138
+ ['Fixnum', 'Integer'].must_include afrows.class.name
139
139
  @client.execute("INSERT INTO [datatypes] ([varchar_50]) VALUES ('#{text}')").do
140
140
  pk1 = @client.execute(@client.identity_sql).each.first['Ident']
141
- assert_instance_of Fixnum, pk1, 'we it be able to CAST to bigint'
141
+ ['Fixnum', 'Integer'].must_include pk1.class.name, 'we it be able to CAST to bigint'
142
142
  @client.execute("UPDATE [datatypes] SET [varchar_50] = NULL WHERE [varchar_50] = '#{text}'").do
143
143
  afrows = @client.execute("SELECT @@ROWCOUNT AS AffectedRows").each.first['AffectedRows']
144
144
  assert_equal 1, afrows
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_tds
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Collins
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-03-18 00:00:00.000000000 Z
13
+ date: 2017-07-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mini_portile2
@@ -113,6 +113,7 @@ files:
113
113
  - ".gitignore"
114
114
  - ".rubocop.yml"
115
115
  - ".travis.yml"
116
+ - BACKERS.md
116
117
  - CHANGELOG
117
118
  - CODE_OF_CONDUCT.md
118
119
  - Gemfile
@@ -138,9 +139,19 @@ files:
138
139
  - lib/tiny_tds/bin.rb
139
140
  - lib/tiny_tds/client.rb
140
141
  - lib/tiny_tds/error.rb
142
+ - lib/tiny_tds/gem.rb
141
143
  - lib/tiny_tds/result.rb
142
144
  - lib/tiny_tds/version.rb
143
- - ports/patches/freetds/1.00.27/0001-mingw_missing_inet_pton.diff
145
+ - patches/freetds/1.00.27/0001-mingw_missing_inet_pton.diff
146
+ - patches/libiconv/1.14/1-avoid-gets-error.patch
147
+ - tasks/native_gem.rake
148
+ - tasks/package.rake
149
+ - tasks/ports.rake
150
+ - tasks/ports/freetds.rb
151
+ - tasks/ports/libiconv.rb
152
+ - tasks/ports/openssl.rb
153
+ - tasks/ports/recipe.rb
154
+ - tasks/test.rake
144
155
  - test/appveyor/dbsetup.ps1
145
156
  - test/appveyor/dbsetup.sql
146
157
  - test/benchmark/query.rb
@@ -150,6 +161,7 @@ files:
150
161
  - test/bin/install-openssl.sh
151
162
  - test/bin/setup.sh
152
163
  - test/client_test.rb
164
+ - test/gem_test.rb
153
165
  - test/result_test.rb
154
166
  - test/schema/1px.gif
155
167
  - test/schema/sqlserver_2000.sql
@@ -179,9 +191,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
191
  version: 2.0.0
180
192
  required_rubygems_version: !ruby/object:Gem::Requirement
181
193
  requirements:
182
- - - ">="
194
+ - - ">"
183
195
  - !ruby/object:Gem::Version
184
- version: '0'
196
+ version: 1.3.1
185
197
  requirements: []
186
198
  rubyforge_project:
187
199
  rubygems_version: 2.6.8
@@ -198,6 +210,7 @@ test_files:
198
210
  - test/bin/install-openssl.sh
199
211
  - test/bin/setup.sh
200
212
  - test/client_test.rb
213
+ - test/gem_test.rb
201
214
  - test/result_test.rb
202
215
  - test/schema/1px.gif
203
216
  - test/schema/sqlserver_2000.sql
@@ -210,3 +223,4 @@ test_files:
210
223
  - test/schema_test.rb
211
224
  - test/test_helper.rb
212
225
  - test/thread_test.rb
226
+ has_rdoc: