|
12 | 12 | # Support multiple ruby versions, fat binaries under Windows.
|
13 | 13 | if RUBY_PLATFORM =~ /mingw|mswin/ && RUBY_VERSION =~ /(\d+.\d+)/
|
14 | 14 | ver = Regexp.last_match(1)
|
15 |
| - # Set the PATH environment variable, so that the DLLs can be found. |
16 |
| - old_path = ENV['PATH'] |
17 |
| - begin |
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 | 15 |
|
24 |
| - require "tiny_tds/#{ver}/tiny_tds" |
25 |
| - rescue LoadError |
26 |
| - require 'tiny_tds/tiny_tds' |
27 |
| - ensure |
28 |
| - ENV['PATH'] = old_path |
| 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}" |
| 23 | + begin |
| 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) |
| 35 | + end |
| 36 | + else |
| 37 | + block.call |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 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 |
29 | 48 | end
|
30 | 49 | else
|
31 | 50 | # Load dependent shared libraries into the process, so that they are already present,
|
|
0 commit comments