Class: NativeFolder

Inherits:
Object
  • Object
show all
Defined in:
lib/jruby_art/native_folder.rb

Overview

Utility to load native binaries on Java CLASSPATH HACK until jruby returns a more specific ‘host_os’ than ‘linux’

Constant Summary collapse

LINUX_FORMAT =
'linux%<bit>d'
WIN_FORMAT =

ARM64 = ‘-aarch64’

'windows%<bit>d'
WIN_PATTERNS =
[
  /bccwin/i,
  /cygwin/i,
  /djgpp/i,
  /ming/i,
  /mswin/i,
  /wince/i
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNativeFolder

Returns a new instance of NativeFolder.



22
23
24
25
# File 'lib/jruby_art/native_folder.rb', line 22

def initialize
  @os = RbConfig::CONFIG['host_os'].downcase
  @bit = /64/.match?(java.lang.System.get_property('os.arch')) ? 64 : 32
end

Instance Attribute Details

#bitObject (readonly)

Returns the value of attribute bit.



8
9
10
# File 'lib/jruby_art/native_folder.rb', line 8

def bit
  @bit
end

#osObject (readonly)

Returns the value of attribute os.



8
9
10
# File 'lib/jruby_art/native_folder.rb', line 8

def os
  @os
end

Instance Method Details

#extensionObject



39
40
41
42
43
44
45
# File 'lib/jruby_art/native_folder.rb', line 39

def extension
  return '*.so' if /linux/.match?(os)

  return '*.dll' if WIN_PATTERNS.any? { |pat| pat.match?(os) }

  '*.dylib' # MacOS
end

#nameObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jruby_art/native_folder.rb', line 27

def name
  return 'macosx' if /darwin|mac/.match?(os)

  return format(LINUX_FORMAT, bit: bit) if /linux/.match?(os)

  unless WIN_PATTERNS.any? { |pat| pat.match?(os) }
    raise StandardError, 'Unsupported Architecture'
  end

  format(WIN_FORMAT, bit: bit)
end