Module: FFI::Compiler::Loader
- Defined in:
- lib/ffi-compiler/loader.rb,
lib/ffi-compiler/fake_ffi/ffi-compiler/loader.rb
Class Method Summary collapse
Class Method Details
.caller_path(line = caller[0]) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ffi-compiler/loader.rb', line 48 def self.caller_path(line = caller[0]) if FFI::Platform::OS == 'windows' drive = line[0..1] path = line[2..-1].split(/:/)[0] full_path = drive + path else full_path = line.split(/:/)[0] end File.dirname full_path end |
.find(*args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ffi-compiler/loader.rb', line 8 def self.find(name, start_path = nil) library = Platform.system.map_library_name(name) start_path ||= caller_path(caller[0]) # Load from modern extension fast-path when called from an active gem spec if (spec = active_spec_containing(start_path)) && spec.respond_to?(:extension_dir) ext_path = File.join(spec.extension_dir, library) return ext_path if File.exist?(ext_path) end # Try to find the library in the legacy lib path, passed start_path or local folder root = false Pathname.new(start_path).ascend do |path| Dir.glob("#{path}/**/#{FFI::Platform::ARCH}-#{FFI::Platform::OS}/#{library}") do |f| return f end Dir.glob("#{path}/**/#{library}") do |f| return f end break if root # Next iteration will be the root of the gem if this is the lib/ dir - stop after that root = File.basename(path) == 'lib' end raise LoadError.new("cannot find '#{name}' library") end |