|
7 | 7 | # This gives a chance to be flexible about the load path
|
8 | 8 | # Or to bomb out with a clear error message instead of a linker crash
|
9 | 9 | if RUBY_PLATFORM =~ /mswin|mingw/
|
10 |
| - dll_search = [ |
11 |
| - File.expand_path('../vendor/libmysql.dll', File.dirname(__FILE__)).gsub('/', '\\'), |
12 |
| - File.expand_path('../libmysql.dll', File.dirname(__FILE__)).gsub('/', '\\'), |
13 |
| - 'libmysql.dll' # This will use default / system library paths |
14 |
| - ] |
15 |
| - |
16 |
| - # If this environment variable is set, it overrides any other search paths |
17 |
| - dll_search = [ ENV['RUBY_MYSQL2_LIBMYSQL_DLL'].dup ] if ENV['RUBY_MYSQL2_LIBMYSQL_DLL'] |
| 10 | + dll_path = if ENV['RUBY_MYSQL2_LIBMYSQL_DLL'] |
| 11 | + # If this environment variable is set, it overrides any other paths |
| 12 | + # The user is advised to use backslashes not forward slashes |
| 13 | + ENV['RUBY_MYSQL2_LIBMYSQL_DLL'].dup |
| 14 | + elsif File.exist?(File.expand_path('../vendor/libmysql.dll', File.dirname(__FILE__))) |
| 15 | + # Use vendor/libmysql.dll if it exists, convert slashes for Win32 LoadLibrary |
| 16 | + File.expand_path('../vendor/libmysql.dll', File.dirname(__FILE__)).gsub('/', '\\') |
| 17 | + else |
| 18 | + # This will use default / system library paths |
| 19 | + 'libmysql.dll' |
| 20 | + end |
18 | 21 |
|
19 | 22 | require 'Win32API'
|
20 | 23 | LoadLibrary = Win32API.new('Kernel32', 'LoadLibrary', ['P'], 'I')
|
21 |
| - unless dll_search.any? { |dll| 0 != LoadLibrary.call(dll) } |
22 |
| - abort "Failed to load libmysql.dll from any of #{dll_search.inspect}" |
| 24 | + if 0 == LoadLibrary.call(dll_path) |
| 25 | + abort "Failed to load libmysql.dll from #{dll_path}" |
23 | 26 | end
|
24 | 27 | end
|
25 | 28 |
|
|
0 commit comments