Sha256: 27edcfd8bb6dd83419e1f1692d4cde5dac984b8123a52d03bf839873b3153a94

Contents?: true

Size: 1022 Bytes

Versions: 12

Compression:

Stored size: 1022 Bytes

Contents

require 'pathname'
require 'ffi'
require_relative 'platform'

module FFI
  module Compiler
    module Loader
      def self.find(name, start_path = nil)
        library = Platform.system.map_library_name(name)
        root = false
        Pathname.new(start_path || caller_path(caller[0])).ascend do |path|
          Dir.glob("#{path}/**/{#{FFI::Platform::ARCH}-#{FFI::Platform::OS}/#{library},#{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

      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
    end
  end
end

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/loader.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/loader.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/loader.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/loader.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/loader.rb
direct7-0.0.11 vendor/bundle/ruby/2.7.0/gems/ffi-compiler-1.0.1/lib/ffi-compiler/loader.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/ffi-compiler2-2.0.0/lib/ffi-compiler/loader.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/ffi-compiler2-2.0.0/lib/ffi-compiler/loader.rb
ffi-compiler-1.0.1 lib/ffi-compiler/loader.rb
ffi-compiler-1.0.0 lib/ffi-compiler/loader.rb
ffi-compiler2-2.0.0 lib/ffi-compiler/loader.rb
ffi-compiler-0.1.3 lib/ffi-compiler/loader.rb