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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73bd4951846ceec174df8db2ffe067964ff3028f
4
- data.tar.gz: 4a3cfac3894fbbab3c5bac96466c150b4cfebc9b
3
+ metadata.gz: d610f8a144b7d69dc557b7754e5d8cb249663a40
4
+ data.tar.gz: e503544545922b8f044aad93f301dc1d96d518a8
5
5
  SHA512:
6
- metadata.gz: af3973c153331fdd890d60cffdba2e1e06535111bdddaeb1c212dd81894bbcc9d71fb11896c5b8e25a465f39978234d1413dbd219271e8b4e0618e9a5a8c591e
7
- data.tar.gz: 15805114c789ede730c1d1bce7e798b9bd67584facbc1f37341beeee311ca59d014e0796a4b3cc78ea4579815f6185792122b0af69ce52c06825e99d196e9bcf
6
+ metadata.gz: 379ad79e11421917921c79f39f3cdf2c95ac1fd42a53be43842b4a9b331f752de85c9edffe734d2d43bd0d0ec49ebb901d33d1d9f1abf2135e1e7cc93849c110
7
+ data.tar.gz: bb35d5094c95e79a7a0d9218c5f091a2ce550e035a19ead43304c178b4921066740da755300668268a762ce7e23ada6aec66c18e4f1def389408d1fac0b24600
data/.travis.yml CHANGED
@@ -4,6 +4,7 @@ services:
4
4
  - docker
5
5
  env:
6
6
  global:
7
+ - PATH=/opt/local/bin:$PATH
7
8
  - TESTOPTS="-v"
8
9
  - TINYTDS_UNIT_HOST=localhost
9
10
  rvm:
@@ -11,15 +12,11 @@ rvm:
11
12
  - 2.2.5
12
13
  - 2.3.1
13
14
  before_install:
14
- - export PATH=/opt/local/bin:$PATH
15
15
  - docker info
16
- - sudo ./test/bin/setup.sh
17
16
  - sudo ./test/bin/install-openssl.sh
18
- - openssl version
19
17
  - sudo ./test/bin/install-freetds.sh
20
- - tsql -C
18
+ - sudo ./test/bin/setup.sh
21
19
  install:
22
- - export PATH=/opt/local/bin:$PATH
23
20
  - gem install bundler
24
21
  - bundle --version
25
22
  - bundle install
data/BACKERS.md ADDED
@@ -0,0 +1,32 @@
1
+ # Backers
2
+
3
+ You can join in supporting TinyTDS and the Rails SQL Server Adapter development by [pledging on Patreon](https://www.patreon.com/metaskills)! Backers in the same pledge level appear in the order of pledge date.
4
+
5
+ ### $2000
6
+
7
+ [It could be you!](https://www.patreon.com/bePatron?c=765225&rid=1611218)
8
+
9
+
10
+ ### $500
11
+
12
+ [It could be you!](https://www.patreon.com/bePatron?c=765225&rid=1611209)
13
+
14
+
15
+ ### $250
16
+
17
+ [It could be you!](https://www.patreon.com/bePatron?c=765225&rid=1611199)
18
+
19
+
20
+ ### $100
21
+
22
+ [It could be you!](https://www.patreon.com/bePatron?c=765225&rid=1611196)
23
+
24
+
25
+ ### $50+
26
+
27
+ [It could be you!](https://www.patreon.com/bePatron?c=765225&rid=1611186)
28
+
29
+
30
+ ### $10+
31
+
32
+ [It could be you!](https://www.patreon.com/bePatron?c=765225&rid=1611149)
data/Gemfile CHANGED
@@ -3,5 +3,8 @@ gemspec
3
3
 
4
4
  group :development do
5
5
  gem 'rake-compiler-dock', github: 'rake-compiler/rake-compiler-dock'
6
- gem 'byebug'
6
+ end
7
+
8
+ group :test do
9
+ gem 'minitest'
7
10
  end
data/README.md CHANGED
@@ -8,6 +8,13 @@
8
8
  * [![Dependency Status](https://dependencyci.com/github/rails-sqlserver/tiny_tds/badge)](https://dependencyci.com/github/rails-sqlserver/tiny_tds) - Dependency Status
9
9
  * [![Gitter chat](https://img.shields.io/badge/%E2%8A%AA%20GITTER%20-JOIN%20CHAT%20%E2%86%92-brightgreen.svg?style=flat)](https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter) - Community
10
10
 
11
+ ## Supporting TinyTDS/Adapter
12
+
13
+ Both TinyTDS and the Rails SQL Server Adapter are MIT-licensed open source projects. Its ongoing development is made possible thanks to the support by these awesome [backers](https://github.com/rails-sqlserver/tiny_tds/blob/master/BACKERS.md). If you'd like to join them, check out our [Patreon Campaign](https://www.patreon.com/metaskills).
14
+
15
+
16
+ ## About TinyTDS
17
+
11
18
  The TinyTDS gem is meant to serve the extremely common use-case of connecting, querying and iterating over results to Microsoft SQL Server or Sybase databases from Ruby using the FreeTDS's DB-Library API.
12
19
 
13
20
  TinyTDS offers automatic casting to Ruby primitives along with proper encoding support. It converts all SQL Server datatypes to native Ruby primitives while supporting :utc or :local time zones for time-like types. To date it is the only Ruby client library that allows client encoding options, defaulting to UTF-8, while connecting to SQL Server. It also properly encodes all string and binary data. The motivation for TinyTDS is to become the de-facto low level connection mode for the SQL Server Adapter for ActiveRecord.
@@ -45,21 +52,18 @@ $ make install
45
52
  If none exist, our native extension will use MiniPortile to install any missing dependencies listed above for your specific platform. These dependencies will be built and linked within the installed TinyTDS gem. Please read the MiniPortile and/or Windows sections at the end of this file for advanced configuration options past the following:
46
53
 
47
54
  ```
48
- --enable-system-freetds / --disable-system-freetds
49
- --enable-system-iconv / --disable-system-iconv
50
- --enable-system-openssl / --disable-system-openssl
51
- Force use of system or builtin freetds/iconv/openssl library.
52
- Default is to prefer system libraries and fallback to builtin.
53
-
54
55
  --with-freetds-dir=DIR
55
56
  Use the freetds library placed under DIR.
57
+ ```
56
58
 
57
- --enable-lookup
58
- Search for freetds through all paths in the PATH environment variable.
59
59
 
60
- --enable-cross-build
61
- Do cross-build.
62
- ```
60
+ ## Getting Started
61
+
62
+ Optionally, Microsoft has done a great job writing some articles on how to get started with SQL Server and Ruby using TinyTDS. Please checkout one of the following posts that match your platform.
63
+
64
+ * [SQL Server on a Mac](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby/mac)
65
+ * [SQL Server on RHEL](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby/rhel)
66
+ * [SQL Server on Ubuntu](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby/ubuntu)
63
67
 
64
68
 
65
69
  ## FreeTDS Compatibility & Configuration
@@ -387,19 +391,6 @@ This is possible using FreeTDS version 0.95 or higher. You must use the `use_utf
387
391
  The default is true and since FreeTDS v1.0 would do this as well.
388
392
 
389
393
 
390
- ## Using MiniPortile
391
-
392
- MiniPortile is a minimalistic implementation of a port/recipe system. <https://github.com/luislavena/mini_portile>
393
-
394
- The TinyTDS project uses MiniPortile so that we can easily install a local version of FreeTDS and supporting libraries to link against when building a test version of TinyTDS. This same system is also used when installing TinyTDS with Rubygems and building native extensions. It is possible to build TinyTDS with a specific version of FreeTDS using the `TINYTDS_FREETDS_VERSION` environment variable. Here are some exampbles of possible values.
395
-
396
- ```
397
- $ rake TDSVER='7.1' TINYTDS_FREETDS_VERSION='0.95' -- --disable-system-freetds --disable-system-iconv
398
- ```
399
-
400
- To find out more about the FreeTDS release system [visit this thread](http://lists.ibiblio.org/pipermail/freetds/2012q1/027756.html) on their mailing list. You can also browse thier FTP server [ftp://ftp.astron.com/pub/freetds/](ftp://ftp.astron.com/pub/freetds/) for version number strings.
401
-
402
-
403
394
  ## Compiling Gems for Windows
404
395
 
405
396
  For the convenience of Windows users, TinyTDS ships pre-compiled gems for Ruby 2.0, 2.1, 2.2, and 2.3 on Windows. In order to generate these gems, [rake-compiler-dock](https://github.com/rake-compiler/rake-compiler-dock) is used. This project provides a [Docker image](https://registry.hub.docker.com/u/larskanis/rake-compiler-dock/) with rvm, cross-compilers and a number of different target versions of Ruby.
@@ -447,13 +438,20 @@ CREATE USER [tinytds] FOR LOGIN [tinytds];
447
438
  EXEC sp_addrolemember N'db_owner', N'tinytds';
448
439
  ```
449
440
 
450
- From here you can now run the tests. This assumes you have both Ruby & the needed FreeTDS installed.
441
+ From here you can build and run tests against an installed version of FreeTDS.
451
442
 
452
443
  ```shell
453
444
  $ bundle install
454
445
  $ bundle exec rake
455
446
  ```
456
447
 
448
+ If you don't have FreeTDS installed on your system you can let the MiniPortile build tasks build and link all the dependencies for you.
449
+ ```shell
450
+ $ bundle install
451
+ $ bundle exec rake ports build
452
+ $ bundle exec rake ports test
453
+ ```
454
+
457
455
  Examples us using enviornment variables to customize the test task.
458
456
 
459
457
  ```
@@ -463,13 +461,6 @@ $ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_SCHEMA=sqlserver_azure
463
461
  $ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_UNIT_PORT=5000 TINYTDS_SCHEMA=sybase_ase
464
462
  ```
465
463
 
466
- If you do not want to use MiniPortile to compile a local project version of FreeTDS and instead use your local system version, use the `TINYTDS_SKIP_PORTS` environment variable. This will ignore any port tasks and will instead build and link to your system's FreeTDS installation as a normal gem install would.
467
-
468
- ```
469
- $ rake TINYTDS_SKIP_PORTS=1
470
- ```
471
-
472
-
473
464
  ## Help & Support
474
465
 
475
466
  * Github Source: http://github.com/rails-sqlserver/tiny_tds
data/Rakefile CHANGED
@@ -1,107 +1,50 @@
1
1
  # encoding: UTF-8
2
+ require 'rbconfig'
2
3
  require 'rake'
3
4
  require 'rake/clean'
4
- require 'rbconfig'
5
- require 'rake/testtask'
6
5
  require 'rake/extensiontask'
7
- require 'rubygems/package_task'
8
6
  require_relative './ext/tiny_tds/extconsts'
9
7
 
10
- def test_libs
11
- %w(lib test)
12
- end
13
-
14
- def test_files
15
- if ENV['TEST_FILES']
16
- ENV['TEST_FILES'].split(',').map(&:strip).sort
17
- else
18
- Dir.glob('test/**/*_test.rb').sort
19
- end
20
- end
21
-
22
- def add_file_to_gem(spec, relative_path)
23
- target_path = File.join gem_build_path(spec), relative_path
24
- target_dir = File.dirname(target_path)
25
- mkdir_p target_dir
26
- rm_f target_path
27
- safe_ln relative_path, target_path
28
- spec.files += [relative_path]
29
- end
30
-
31
- def gem_build_path(spec)
32
- File.join 'pkg', spec.full_name
33
- end
34
-
35
- gemspec = Gem::Specification.load(File.expand_path('../tiny_tds.gemspec', __FILE__))
36
-
37
- Rake::TestTask.new do |t|
38
- t.libs = test_libs
39
- t.test_files = test_files
40
- t.verbose = true
41
- end
42
-
43
- Gem::PackageTask.new(gemspec) do |pkg|
44
- pkg.need_tar = false
45
- pkg.need_zip = false
46
- end
47
-
48
- task :compile
8
+ SPEC = Gem::Specification.load(File.expand_path('../tiny_tds.gemspec', __FILE__))
9
+ GEM_PLATFORM_HOSTS = {
10
+ 'x86-mingw32' => 'i686-w64-mingw32',
11
+ 'x64-mingw32' => 'x86_64-w64-mingw32'
12
+ }
49
13
 
50
- task build: [:clean, :compile]
51
- task(:build_quietly) { capture_stds { Rake::Task[:build].invoke } }
14
+ # Add our project specific files to clean for a rebuild
15
+ CLEAN.include FileList["{ext,lib}/**/*.{so,#{RbConfig::CONFIG['DLEXT']},o}"],
16
+ FileList["exe/*"]
52
17
 
53
- task default: [:build, :test]
18
+ # Clobber all our temp files and ports files including .install files
19
+ # and archives
20
+ CLOBBER.include FileList["tmp/**/*"],
21
+ FileList["ports/**/*"].exclude(%r{^ports/archives})
54
22
 
55
23
  Dir['tasks/*.rake'].sort.each { |f| load f }
56
24
 
57
- Rake::ExtensionTask.new('tiny_tds', gemspec) do |ext|
25
+ Rake::ExtensionTask.new('tiny_tds', SPEC) do |ext|
58
26
  ext.lib_dir = 'lib/tiny_tds'
59
27
  ext.cross_compile = true
60
- ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
61
- ext.cross_config_options += %w(--disable-lookup --enable-cross-build)
28
+ ext.cross_platform = GEM_PLATFORM_HOSTS.keys
29
+
62
30
  # Add dependent DLLs to the cross gems
63
31
  ext.cross_compiling do |spec|
64
- platform_host_map = {
65
- 'x86-mingw32' => 'i686-w64-mingw32',
66
- 'x64-mingw32' => 'x86_64-w64-mingw32'
67
- }
32
+ platform_host_map = GEM_PLATFORM_HOSTS
68
33
  gemplat = spec.platform.to_s
69
34
  host = platform_host_map[gemplat]
70
- dlls = [
71
- "libcrypto32-#{OPENSSL_VERSION}-#{host}.dll",
72
- "libssl32-#{OPENSSL_VERSION}-#{host}.dll",
73
- 'libiconv-2.dll',
74
- 'libsybdb-5.dll'
75
- ]
35
+
76
36
  # We don't need the sources in a fat binary gem
77
37
  spec.files = spec.files.reject { |f| f =~ %r{^ports\/archives/} }
78
- spec.files += dlls.map { |dll| "ports/#{host}/bin/#{File.basename(dll)}" }
38
+
39
+ # Make sure to include the ports binaries and libraries
40
+ spec.files += FileList["ports/#{host}/**/**/{bin,lib}/*"].exclude do |f|
41
+ File.directory? f
42
+ end
43
+
79
44
  spec.files += Dir.glob('exe/*')
80
45
  end
81
46
  end
82
47
 
83
- # Bundle the freetds sources to avoid download while gem install.
84
- task gem_build_path(gemspec) do
85
- add_file_to_gem gemspec, "ports/archives/freetds-#{FREETDS_VERSION}.tar.bz2"
86
- end
87
-
88
- desc 'Build the windows binary gems per rake-compiler-dock'
89
- task 'gem:windows' do
90
- require 'rake_compiler_dock'
91
- RakeCompilerDock.sh <<-EOT
92
- bundle && rake cross native gem RUBY_CC_VERSION=2.4.0:2.3.0:2.2.2:2.1.6:2.0.0 CFLAGS="-Wall"
93
- EOT
94
- end
48
+ task build: [:clean, :compile]
49
+ task default: [:build, :test]
95
50
 
96
- def capture_stds
97
- pstdout = $stdout
98
- $stdout = StringIO.new
99
- pstderr = $stderr
100
- $stderr = StringIO.new
101
- yield
102
- $stdout.string
103
- $stderr.string
104
- ensure
105
- $stdout = pstdout
106
- $stderr = pstderr
107
- end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 2.0.0.pre1
data/appveyor.yml CHANGED
@@ -9,12 +9,15 @@ skip_branch_with_pr: true
9
9
  matrix:
10
10
  fast_finish: true
11
11
  install:
12
+ # Output debugging info
12
13
  - ps: Update-AppveyorBuild -Version "$(Get-Content $env:appveyor_build_folder\VERSION).$env:appveyor_build_number"
13
14
  - perl --version
14
15
  - ruby --version
15
16
  - gem --version
17
+
18
+ # Set up project prerequisits
16
19
  - bundle install
17
- - bundle exec rake build
20
+ - bundle exec rake ports
18
21
  build: off
19
22
  branches:
20
23
  except:
@@ -26,13 +29,13 @@ test_script:
26
29
  - ps: Start-Service 'MSSQL$SQL2014'
27
30
  - timeout /t 4 /nobreak > NUL
28
31
  - sqlcmd -S ".\SQL2014" -U sa -P Password12! -i %APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.sql
29
- - bundle exec rake TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2014" TINYTDS_SCHEMA=sqlserver_2014 TDSVER=7.1
30
- - bundle exec rake TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2014" TINYTDS_SCHEMA=sqlserver_2014
32
+ - bundle exec rake ports build test TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2014" TINYTDS_SCHEMA=sqlserver_2014 TDSVER=7.1
33
+ - bundle exec rake ports build test TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2014" TINYTDS_SCHEMA=sqlserver_2014
31
34
  - ps: Stop-Service 'MSSQL$SQL2014'
32
35
  - ps: Start-Service 'MSSQL$SQL2012SP1'
33
36
  - timeout /t 4 /nobreak > NUL
34
37
  - sqlcmd -S ".\SQL2012SP1" -U sa -P Password12! -i %APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.sql
35
- - bundle exec rake TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2012SP1" TINYTDS_SCHEMA=sqlserver_2014
38
+ - bundle exec rake ports build test TINYTDS_UNIT_HOST_TEST=localhost TINYTDS_UNIT_DATASERVER="localhost\SQL2012SP1" TINYTDS_SCHEMA=sqlserver_2014
36
39
  environment:
37
40
  CI_AZURE_HOST:
38
41
  secure: 8ydpYysZYKEBKvp6plKlYfepH98/zAuT27FFCaJ9Sss=
data/circle.yml CHANGED
@@ -13,13 +13,11 @@ machine:
13
13
 
14
14
  dependencies:
15
15
  override:
16
+ - sudo ./test/bin/install-openssl.sh
17
+ - sudo ./test/bin/install-freetds.sh
16
18
  - rvm-exec 2.1.9 bundle install
17
19
  - rvm-exec 2.2.5 bundle install
18
20
  - rvm-exec 2.3.1 bundle install
19
- - sudo ./test/bin/install-openssl.sh
20
- - openssl version
21
- - sudo ./test/bin/install-freetds.sh
22
- - tsql -C
23
21
 
24
22
  database:
25
23
  post:
@@ -3,366 +3,63 @@ ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
3
3
  # :stopdoc:
4
4
 
5
5
  require 'mkmf'
6
- require 'fileutils'
7
-
8
- # The gem version constraint in the gemspec is not respected at install time.
9
- # Keep this version in sync with the one in the gemspec !
10
- gem 'mini_portile2', '~> 2.0'
11
- require 'mini_portile2'
6
+ require 'rbconfig'
12
7
  require_relative './extconsts'
13
8
 
14
- OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
15
-
16
9
  # Shamelessly copied from nokogiri
17
10
  #
18
11
 
19
12
  def do_help
20
13
  print <<HELP
21
14
  usage: ruby #{$0} [options]
22
-
23
- --enable-system-freetds / --disable-system-freetds
24
- --enable-system-iconv / --disable-system-iconv
25
- --enable-system-openssl / --disable-system-openssl
26
- Force use of system or builtin freetds/iconv/openssl library.
27
- Default is to prefer system libraries and fallback to builtin.
28
-
29
15
  --with-freetds-dir=DIR
30
16
  Use the freetds library placed under DIR.
31
-
32
- --enable-lookup
33
- Search for freetds through all paths in the PATH environment variable.
34
-
35
- --disable-openssl
36
- Disable OpenSSL for freetds build. No effect on system-freetds.
37
-
38
- --enable-gnutls
39
- Use GnuTLS instead of OpenSSL for freetds build.
40
-
41
- --enable-cross-build
42
- Do cross-build.
43
17
  HELP
44
18
  exit! 0
45
19
  end
46
20
 
47
21
  do_help if arg_config('--help')
48
22
 
49
- FREETDSDIR = ENV['FREETDS_DIR']
50
-
51
- if FREETDSDIR.nil? || FREETDSDIR.empty?
52
- LIBDIR = RbConfig::CONFIG['libdir']
53
- INCLUDEDIR = RbConfig::CONFIG['includedir']
54
- else
55
- puts "Will use #{FREETDSDIR}"
56
- LIBDIR = "#{FREETDSDIR}/lib"
57
- INCLUDEDIR = "#{FREETDSDIR}/include"
23
+ # Make sure to check the ports path for the configured host
24
+ host = RbConfig::CONFIG['host']
25
+ project_dir = File.join(['..']*4)
26
+ freetds_dir = File.join(project_dir, 'ports', host, 'freetds', FREETDS_VERSION)
27
+ freetds_dir = File.expand_path(freetds_dir)
28
+
29
+ # Add all the special path searching from the original tiny_tds build
30
+ # order is important here! First in, last searched.
31
+ %w(
32
+ /usr/local
33
+ /opt/local
34
+ ).each do |path|
35
+ idir = "#{path}/include"
36
+ ldir = "#{path}/lib"
37
+
38
+ dir_config('freetds',
39
+ [idir, "#{idir}/freetds"],
40
+ [ldir, "#{ldir}/freetds"]
41
+ )
58
42
  end
59
43
 
60
- $CFLAGS << " #{ENV["CFLAGS"]}"
61
- $LDFLAGS << " #{ENV["LDFLAGS"]}"
62
- $LIBS << " #{ENV["LIBS"]}"
63
-
64
- SEARCHABLE_PATHS = begin
65
- eop_regexp = /#{File::SEPARATOR}bin$/
66
- paths = ENV['PATH']
67
- paths = paths.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
68
- paths = paths.split(File::PATH_SEPARATOR)
69
- bin_paths = paths.select{ |p| p =~ eop_regexp }
70
- bin_paths.map{ |p| p.sub(eop_regexp,'') }.compact.reject{ |p| p.empty? }.uniq
44
+ # Add the ports directory if it exists for local developer builds
45
+ if File.directory?(freetds_dir)
46
+ puts "Using freetds port path #{freetds_dir}"
47
+ dir_config('freetds', "#{freetds_dir}/include", "#{freetds_dir}/lib")
71
48
  end
72
49
 
73
- def searchable_paths_with_directories(*directories)
74
- SEARCHABLE_PATHS.map do |path|
75
- directories.map do |paths|
76
- dir = File.join path, *paths
77
- File.directory?(dir) ? dir : nil
78
- end.flatten.compact
79
- end.flatten.compact
50
+ have_dependencies = [
51
+ find_header('sybfront.h'),
52
+ find_header('sybdb.h'),
53
+ find_library('sybdb', 'tdsdbopen'),
54
+ find_library('sybdb', 'dbanydatecrack')
55
+ ].inject(true) do |memo, current|
56
+ memo && current
80
57
  end
81
58
 
82
- class BuildRecipe < MiniPortile
83
- def initialize(name, version, files)
84
- super(name, version)
85
- self.files = files
86
- self.target = File.expand_path('../../../ports', __FILE__)
87
- self.host = consolidated_host(RbConfig::CONFIG["host"])
88
- self.patch_files = Dir[File.join(self.target, "patches", self.name, self.version, "*.diff")].sort
89
- end
90
-
91
- def consolidated_host(name)
92
- # Host name and prefix of build tools are different on Windows 32 bit.
93
- name.gsub('i686-pc-mingw32', 'i686-w64-mingw32')
94
- end
95
-
96
- def configure_defaults
97
- [
98
- "--host=#{host}", # build for specific target (host)
99
- "--disable-static",
100
- "--enable-shared",
101
- ]
102
- end
103
-
104
- # Use the same path for all recipes, so that only one include/lib path is required.
105
- def port_path
106
- "#{target}/#{host}"
107
- end
108
-
109
- # We use the same port_path for all recipes. That breaks the standard installed? method.
110
- def installed?
111
- false
112
- end
113
-
114
- # When using rake-compiler-dock on Windows, the underlying Virtualbox shared
115
- # folders don't support symlinks, but libiconv expects it for a build on
116
- # Linux. We work around this limitation by using the temp dir for cooking.
117
- def chdir_for_build
118
- build_dir = ENV['RCD_HOST_RUBY_PLATFORM'].to_s =~ /mingw|mswin|cygwin/ ? '/tmp' : '.'
119
- Dir.chdir(build_dir) do
120
- yield
121
- end
122
- end
123
-
124
- def cook_and_activate
125
- checkpoint = File.join(self.target, "#{self.name}-#{self.version}-#{self.host}.installed")
126
- unless File.exist?(checkpoint)
127
- chdir_for_build do
128
- self.cook
129
- end
130
- FileUtils.touch checkpoint
131
- end
132
- self.activate
133
- self
134
- end
59
+ unless have_dependencies
60
+ abort 'Failed! Do you have FreeTDS 0.95.80 or higher installed?'
135
61
  end
136
62
 
137
- def define_libssl_recipe(host)
138
- BuildRecipe.new("openssl", OPENSSL_VERSION, [OPENSSL_SOURCE_URI]).tap do |recipe|
139
- class << recipe
140
- def extract_file(file, target)
141
- filename = File.basename(file)
142
- FileUtils.mkdir_p target
143
-
144
- message "Extracting #{filename} into #{target}... "
145
- result = `#{tar_exe} #{tar_compression_switch(filename)}xf "#{file}" -C "#{target}" 2>&1`
146
- if $?.success?
147
- output "OK"
148
- else
149
- # tar on windows returns error exit code, because it can not extract symlinks
150
- output "ERROR (ignored)"
151
- end
152
- end
153
-
154
- def execute(action, command, options={})
155
- prev_path = ENV['PATH']
156
- if host=~/mingw/
157
- git_perl = 'C:/Program Files/Git/usr/bin'
158
- if File.directory?(git_perl)
159
- ENV['PATH'] = git_perl + ';' + ENV['PATH']
160
- ENV['PERL'] = 'perl'
161
- end
162
- end
163
- super
164
- ENV['PATH'] = prev_path
165
- end
166
-
167
- def configure
168
- config = if host=~/mingw/
169
- host=~/x86_64/ ? 'mingw64' : 'mingw'
170
- end
171
- args = [ "CFLAGS=-DDSO_WIN32",
172
- "./Configure",
173
- "no-shared",
174
- configure_prefix,
175
- config,
176
- ]
177
- args.unshift("CROSS_COMPILE=#{host}-") if enable_config("cross-build")
178
-
179
- execute "configure", "sh -c \"#{args.join(" ")}\""
180
- end
181
-
182
- def dllwrap(dllname, outputlib, deffile, linkto)
183
- gcc = consolidated_host(RbConfig::CONFIG["CC"])
184
-
185
- #RbConfig does not provide dlltool, but it should exist where dllwrap lives
186
- dlltool = consolidated_host(RbConfig::CONFIG["DLLWRAP"]).sub('dllwrap','dlltool')
187
-
188
- execute "gcc-#{dllname}-compile", "#{gcc} -Wl,--base-file,#{dllname}.base -mdll -o #{dllname}.dll --leading-underscore #{linkto}"
189
- execute "dlltool-#{dllname}-exp", "#{dlltool} --base-file #{dllname}.base --output-exp #{dllname}.exp --dllname #{dllname}.dll --def #{deffile}"
190
- execute "gcc-#{dllname}-dll", "#{gcc} -Wl,--base-file,#{dllname}.base #{dllname}.exp -mdll -o #{dllname}.dll --leading-underscore #{linkto}"
191
- execute "dlltool-#{dllname}-outputlib", "#{dlltool} --base-file #{dllname}.base --output-exp #{dllname}.exp --dllname #{dllname}.dll --def #{deffile} --output-lib #{outputlib}"
192
- execute "gcc-#{dllname}-link", "#{gcc} #{dllname}.exp -mdll -o #{dllname}.dll --leading-underscore #{linkto}"
193
- end
194
-
195
- def compile
196
- super
197
- # OpenSSL DLLs are called "libcrypto32.dll" and "libssl32.dll" per default,
198
- # regardless to the version. This is best suited to meet the Windows DLL hell.
199
- # To avoid any conflicts we do a static build and build DLLs afterwards,
200
- # with our own naming scheme.
201
- execute "mkdef-crypto32", "(perl util/mkdef.pl crypto 32 >libcrypto32.def)"
202
- execute "mkdef-ssl32", "(perl util/mkdef.pl ssl 32 >libssl32.def)"
203
- dllwrap("libcrypto32-#{version}-#{host}", "libcrypto.dll.a", "libcrypto32.def", "libcrypto.a -lws2_32 -lgdi32 -lcrypt32")
204
- dllwrap("libssl32-#{version}-#{host}", "libssl.dll.a", "libssl32.def", "libssl.a libcrypto.dll.a")
205
- end
206
-
207
- def install
208
- unless installed?
209
- execute('install', %Q(#{make_cmd} install_sw install_ssldirs))
210
- end
211
- FileUtils.cp "#{work_path}/libcrypto32-#{version}-#{host}.dll", "#{path}/bin/"
212
- FileUtils.cp "#{work_path}/libssl32-#{version}-#{host}.dll", "#{path}/bin/"
213
- FileUtils.cp "#{work_path}/libcrypto.dll.a", "#{path}/lib/"
214
- FileUtils.cp "#{work_path}/libssl.dll.a", "#{path}/lib/"
215
- end
216
- end
217
- end
218
- end
219
-
220
- def define_libiconv_recipe(host)
221
- BuildRecipe.new("libiconv", ICONV_VERSION, [ICONV_SOURCE_URI]).tap do |recipe|
222
- # always produce position independent code
223
- # and set an explicit optimization to avoid inline functions being optimized
224
- # out of libiconv
225
- recipe.configure_options << "CFLAGS=-fPIC -O2"
226
- end
227
- end
228
-
229
- def define_freetds_recipe(host, libiconv, libssl, gnutls)
230
- BuildRecipe.new("freetds", FREETDS_VERSION, [FREETDS_SOURCE_URI]).tap do |recipe|
231
- with_tdsver = FREETDS_VERSION =~ /0\.91/ ? "--with-tdsver=7.1" : "--with-tdsver=7.3"
232
- for_windows = recipe.host =~ /mswin|mingw/i
233
- recipe.configure_options << '--with-pic'
234
- recipe.configure_options << "--with-libiconv-prefix=#{libiconv.path}" if libiconv
235
- if true == libssl
236
- recipe.configure_options << "--with-openssl"
237
- elsif libssl
238
- recipe.configure_options << "--with-openssl=#{libssl.path}"
239
- end
240
- recipe.configure_options << "--with-gnutls" if gnutls
241
- recipe.configure_options << '--sysconfdir=C:\Sites' if for_windows
242
- recipe.configure_options << '--enable-sspi' if for_windows
243
- recipe.configure_options << "--disable-odbc"
244
- recipe.configure_options << with_tdsver
245
- if libiconv
246
- # For some reason freetds doesn't honor --with-libiconv-prefix
247
- # so we have do add it by hand:
248
- recipe.configure_options << "CFLAGS=-I#{libiconv.path}/include"
249
- recipe.configure_options << "LDFLAGS=-L#{libiconv.path}/lib -liconv"
250
- end
251
-
252
- class << recipe
253
-
254
- def configure
255
- cross = enable_config("cross-build")
256
- if cross
257
- prev_cc = ENV['CC']
258
- ENV['CC'] = consolidated_host(gcc_cmd) + ' -static-libgcc'
259
- end
260
- super
261
- ENV['CC'] = prev_cc if cross
262
- end
263
-
264
- def install
265
- super_value = super
266
- # Install binstub target binaries.
267
- if super_value
268
- bin_path = File.expand_path File.join(path, 'bin')
269
- exe_path = File.expand_path File.join(target, '..', 'exe')
270
- return unless File.directory?(bin_path)
271
- ['tsql', 'defncopy'].each do |bin|
272
- ['.exe', ''].each do |ext|
273
- exe = File.join bin_path, "#{bin}#{ext}"
274
- next unless File.exists?(exe)
275
- next unless File.executable?(exe)
276
- FileUtils.cp exe, exe_path
277
- end
278
- end
279
- end
280
- super_value
281
- end
282
-
283
- end
284
-
285
- end
286
- end
287
-
288
- if RbConfig::CONFIG['target_os'] =~ /mswin32|mingw32/
289
- lib_prefix = 'lib' unless RbConfig::CONFIG['target_os'] =~ /mingw32/
290
- # There's no default include/lib dir on Windows. Let's just add the Ruby ones
291
- # and resort on the search path specified by INCLUDE and LIB environment
292
- # variables
293
- HEADER_DIRS = [INCLUDEDIR]
294
- LIB_DIRS = [LIBDIR]
295
- else
296
- lib_prefix = ''
297
- HEADER_DIRS = [
298
- # First search /opt/local for macports
299
- '/opt/local/include',
300
- # Then search /usr/local for people that installed from source
301
- '/usr/local/include',
302
- # Check the ruby install locations
303
- INCLUDEDIR,
304
- # Finally fall back to /usr
305
- '/usr/include'
306
- ].reject{ |dir| !File.directory?(dir) }
307
- LIB_DIRS = [
308
- # First search /opt/local for macports
309
- '/opt/local/lib',
310
- # Then search /usr/local for people that installed from source
311
- '/usr/local/lib',
312
- # Check the ruby install locations
313
- LIBDIR,
314
- # Finally fall back to /usr
315
- '/usr/lib',
316
- ].reject{ |dir| !File.directory?(dir) }
317
- end
318
-
319
- FREETDS_HEADER_DIRS = (searchable_paths_with_directories(['include'],['include','freetds']) + HEADER_DIRS).uniq
320
- FREETDS_LIB_DIRS = (searchable_paths_with_directories(['lib'],['lib','freetds']) + LIB_DIRS).uniq
321
-
322
- # lookup over searchable paths is great for native compilation, however, when
323
- # cross compiling we need to specify our own paths.
324
- if enable_config("lookup", true)
325
- dir_config('freetds', FREETDS_HEADER_DIRS, FREETDS_LIB_DIRS)
326
- else
327
- dir_config('freetds')
328
-
329
- # remove LDFLAGS
330
- $LDFLAGS = ENV.fetch("LDFLAGS", "")
331
- end
332
-
333
- def asplode(lib)
334
- msg = "-----\n"
335
- msg << "#{lib} is missing.\n"
336
- msg << "Do you have FreeTDS 0.95.80 or higher installed?\n" if lib == 'freetds'
337
- msg << "-----"
338
- abort(msg)
339
- end
340
-
341
- def freetds_usable?(lib_prefix)
342
- have_header('sybfront.h') && have_header('sybdb.h') &&
343
- find_library("#{lib_prefix}sybdb", 'tdsdbopen') &&
344
- find_library("#{lib_prefix}sybdb", 'dbanydatecrack')
345
- end
346
-
347
- # We use freetds, when available already, and fallback to compilation of ports
348
- system_freetds = enable_config('system-freetds', ENV['TINYTDS_SKIP_PORTS'] || freetds_usable?(lib_prefix))
349
-
350
- # We expect to have iconv and OpenSSL available on non-Windows systems
351
- host = RbConfig::CONFIG["host"]
352
- system_iconv = enable_config('system-iconv', host =~ /mingw|mswin/ ? false : true)
353
- system_openssl = enable_config('system-openssl', host =~ /mingw|mswin/ ? false : true )
354
- enable_gnutls = enable_config('gnutls', false )
355
- enable_openssl = enable_config('openssl', !enable_gnutls )
356
-
357
- unless system_freetds
358
- libssl = define_libssl_recipe(host).cook_and_activate unless system_openssl
359
- libiconv = define_libiconv_recipe(host).cook_and_activate unless system_iconv
360
- freetds = define_freetds_recipe(host, libiconv, libssl || enable_openssl, enable_gnutls).cook_and_activate
361
- dir_config('freetds', freetds.path + "/include", freetds.path + "/lib")
362
- end
363
-
364
- asplode 'freetds' unless freetds_usable?(lib_prefix)
365
-
366
63
  create_makefile('tiny_tds/tiny_tds')
367
64
 
368
65
  # :startdoc: