ruby-gr 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54882caa13673ab79c5589d9ba8fcd02d3fef5adb0b2ad820e4aa75dc6894273
4
- data.tar.gz: 5d57cc79475d98ac75c4fef19d3af024085774ca835978b79d878fb49873e267
3
+ metadata.gz: 684689c3494cbf841d908396c562fb418796d25afabd0a5d9c58497a8dca6a32
4
+ data.tar.gz: 3274ea957c350ddc0ec0abd5c260e54e933ab80930dba7bf5252d807bc47c770
5
5
  SHA512:
6
- metadata.gz: 5b22d5d24b5fba2fa5f806543cc513e4a4d12f7d416f7aa94b3378b7deccef5974dcaf0454afd6e0bfcb6a07322ea6fce71067c9da4eb3b7188f680e0affbf3d
7
- data.tar.gz: 4fef6ebc51e3ff253e59017c85c8d8d9ac2a56c8000a628944603c4e3645365283a403e09dbec0a7fe654353cd8f418bcfa8fbf9e5f3cd37de11eaee2b900d3a
6
+ metadata.gz: 00b957ba8bf7f2f63b67cba456fd0016a8cc18503bbee605e3f02001e61ee377d02d7800eaacfe3077878a3cb92b8ecd9987378a40acae018ddc2428f699f2c4
7
+ data.tar.gz: ed6aaaf3a5ca30ecdf5695623b36036afe00610c720bef330ae25922fce12ad7c76a42ff8801066c3dccf4d973a77d83861651998b7da960c4b5bea7d236fa47
data/LICENSE.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 kojix2
4
- Copyright (c) 2019 Red Data Tools
3
+ Copyright (c) 2019 - present kojix2
4
+ Copyright (c) 2019 - present Red Data Tools
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # GR.rb
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/ruby-gr.svg)](https://badge.fury.io/rb/ruby-gr)
3
+ [![Gem Version](https://img.shields.io/gem/v/ruby-gr?color=brightgreen)](https://rubygems.org/gems/ruby-gr)
4
+ [![CI](https://github.com/red-data-tools/GR.rb/workflows/CI/badge.svg)](https://github.com/red-data-tools/GR.rb/actions)
4
5
  [![Gitter Chat](https://badges.gitter.im/red-data-tools/en.svg)](https://gitter.im/red-data-tools/en)
5
6
  [![Docs Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://rubydoc.info/gems/ruby-gr)
6
7
 
@@ -31,8 +32,7 @@ First, [install GR](#gr-installation). Then install `ruby-gr` gem.
31
32
  ```sh
32
33
  gem install ruby-gr
33
34
  ```
34
-
35
- Note: If you are using Rubyinstaller(Windows), pacman will automatically install [mingw-w64-gr](https://packages.msys2.org/base/mingw-w64-gr).
35
+ Note: If you are using [RubyInstaller](https://rubyinstaller.org/) (Windows), pacman will automatically install [mingw-w64-gr](https://packages.msys2.org/base/mingw-w64-gr).
36
36
 
37
37
  Set environment variable `GRDIR`.
38
38
 
@@ -196,6 +196,9 @@ GR.rb will be the default backend for [Charty](https://github.com/red-data-tools
196
196
 
197
197
  ## Contributing
198
198
 
199
+ GR.rb is a library under development, so even small improvements like typofix are welcome!
200
+ Please feel free to send us your PR.
201
+
199
202
  * [Report bugs](https://github.com/red-data-tools/GR.rb/issues)
200
203
  * Fix bugs and [submit pull requests](https://github.com/red-data-tools/GR.rb/pulls)
201
204
  * Write, clarify, or fix documentation
data/lib/gr.rb CHANGED
@@ -48,23 +48,33 @@
48
48
  module GR
49
49
  class Error < StandardError; end
50
50
 
51
+ class NotFoundError < Error; end
52
+
51
53
  class << self
52
54
  attr_accessor :ffi_lib
53
55
  end
54
56
 
55
57
  require_relative 'gr_commons/gr_commons'
56
- extend GRCommons::SearchSharedLibrary
57
58
 
58
59
  # Platforms | path
59
60
  # Windows | bin/libgr.dll
60
- # MacOSX | lib/libGR.so (NOT .dylib)
61
+ # MacOSX | lib/libGR.so (v0.53.0 .so)
61
62
  # Ubuntu | lib/libGR.so
62
- self.ffi_lib = case RbConfig::CONFIG['host_os']
63
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
64
- search_shared_library('libgr.dll', 'gr')
65
- else
66
- search_shared_library('libGR.so', 'gr')
67
- end
63
+ platform = RbConfig::CONFIG['host_os']
64
+ lib_names, pkg_name = \
65
+ case platform
66
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
67
+ [['libGR.dll'], 'gr']
68
+ when /darwin|mac os/
69
+ [['libGR.dylib', 'libGR.so'], 'gr']
70
+ else
71
+ [['libGR.so'], 'gr']
72
+ end
73
+ lib_path = GRCommons::GRLib.search(lib_names, pkg_name)
74
+
75
+ raise NotFoundError, "#{lib_names} not found" if lib_path.nil?
76
+
77
+ self.ffi_lib = lib_path
68
78
 
69
79
  require_relative 'gr/version'
70
80
  require_relative 'gr/ffi'
@@ -777,7 +787,7 @@ module GR
777
787
 
778
788
  # Set the clipping indicator.
779
789
  #
780
- # @params indicator [Integer] An indicator specifying whether clipping is on
790
+ # @param indicator [Integer] An indicator specifying whether clipping is on
781
791
  # or off.
782
792
  # * 0 : Clipping is off. Data outside of the window will be drawn.
783
793
  # * 1 : Clipping is on. Data outside of the window will not be drawn.
@@ -1829,7 +1839,8 @@ module GR
1829
1839
  # * 3 : INTERP2_CUBIC - Cubic interpolation
1830
1840
  # @param extrapval [Numeric] The extrapolation value
1831
1841
  #
1832
- def interp2(x, y, z, xq, yq, method, extrapval) # flatten
1842
+ # flatten
1843
+ def interp2(x, y, z, xq, yq, method, extrapval)
1833
1844
  nx = x.length
1834
1845
  ny = y.length
1835
1846
  # nz = z.length
data/lib/gr/ffi.rb CHANGED
@@ -15,7 +15,7 @@ module GR
15
15
  raise LoadError, 'Could not find GR Framework'
16
16
  end
17
17
 
18
- extend GRCommons::Extern
18
+ extend GRCommons::TryExtern
19
19
 
20
20
  # https://github.com/sciapp/gr/blob/master/lib/gr/gr.h
21
21
  # keep same order
@@ -41,6 +41,8 @@ module GR
41
41
  'int, int, int, int, int, int, int *)'
42
42
  try_extern 'void gr_polarcellarray(double, double, double, double, double, double, ' \
43
43
  'int, int, int, int, int, int, int *)'
44
+ try_extern 'void gr_nonuniformpolarcellarray(double, double, double *, double *, ' \
45
+ 'int, int, int, int, int, int, int *);'
44
46
  try_extern 'void gr_gdp(int, double *, double *, int, int, int *)'
45
47
  try_extern 'void gr_spline(int, double *, double *, int, int)'
46
48
  try_extern 'void gr_gridit(int, double *, double *, double *, int, int, ' \
data/lib/gr/plot.rb CHANGED
@@ -239,10 +239,10 @@ module GR
239
239
  xmax += 0.5
240
240
  end
241
241
  xtick, majorx = if (scale & GR::OPTION_X_LOG) == 0
242
- unless %i[heatmap polarheatmap].include?(kind)
243
- unless kvs.has_key?(:xlim)
244
- xmin, xmax = GR.adjustlimits(xmin, xmax) unless kvs[:panzoom]
245
- end
242
+ if !%i[heatmap polarheatmap].include?(kind) &&
243
+ !kvs.has_key?(:xlim) &&
244
+ !kvs[:panzoom]
245
+ xmin, xmax = GR.adjustlimits(xmin, xmax)
246
246
  end
247
247
  if kvs.has_key?(:xticks)
248
248
  kvs[:xticks]
@@ -268,10 +268,10 @@ module GR
268
268
  end
269
269
  end
270
270
  ytick, majory = if (scale & GR::OPTION_Y_LOG) == 0
271
- unless %i[heatmap polarheatmap].include?(kind)
272
- unless kvs.has_key?(:ylim)
273
- ymin, ymax = GR.adjustlimits(ymin, ymax) unless kvs[:panzoom]
274
- end
271
+ if !%i[heatmap polarheatmap].include?(kind) &&
272
+ !kvs.has_key?(:ylim) &&
273
+ !kvs[:panzoom]
274
+ ymin, ymax = GR.adjustlimits(ymin, ymax)
275
275
  end
276
276
  if kvs.has_key?(:yticks)
277
277
  kvs[:yticks]
@@ -617,7 +617,7 @@ module GR
617
617
  if kvs.has_key?(:font)
618
618
  name = kvs[:font]
619
619
  # 'Cmuserif-Math' => :cmuserif_math
620
- sym_name = name.to_s.gsub('-','_').downcase.to_sym
620
+ sym_name = name.to_s.gsub('-', '_').downcase.to_sym
621
621
  if FONTS.include?(sym_name)
622
622
  font = FONTS[sym_name]
623
623
  GR.settextfontprec(font, font > 200 ? 3 : 0)
data/lib/gr3.rb CHANGED
@@ -58,23 +58,33 @@
58
58
  module GR3
59
59
  class Error < StandardError; end
60
60
 
61
+ class NotFoundError < Error; end
62
+
61
63
  class << self
62
64
  attr_accessor :ffi_lib
63
65
  end
64
66
 
65
67
  require_relative 'gr_commons/gr_commons'
66
- extend GRCommons::SearchSharedLibrary
67
68
 
68
69
  # Platforms | path
69
70
  # Windows | bin/libGR3.dll
70
- # MacOSX | lib/libGR3.so (NOT .dylib)
71
+ # MacOSX | lib/libGR3.dylib (v0.53.0 .so)
71
72
  # Ubuntu | lib/libGR3.so
72
- self.ffi_lib = case RbConfig::CONFIG['host_os']
73
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
74
- search_shared_library('libGR3.dll', 'gr3')
75
- else
76
- search_shared_library('libGR3.so', 'gr3')
77
- end
73
+ platform = RbConfig::CONFIG['host_os']
74
+ lib_names, pkg_name = \
75
+ case platform
76
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
77
+ [['libGR3.dll'], 'gr3']
78
+ when /darwin|mac os/
79
+ [['libGR3.dylib', 'libGR3.so'], 'gr3']
80
+ else
81
+ [['libGR3.so'], 'gr3']
82
+ end
83
+ lib_path = GRCommons::GRLib.search(lib_names, pkg_name)
84
+
85
+ raise NotFoundError, "#{lib_names} not found" if lib_path.nil?
86
+
87
+ self.ffi_lib = lib_path
78
88
 
79
89
  require_relative 'gr3/version'
80
90
  require_relative 'gr3/ffi'
data/lib/gr3/ffi.rb CHANGED
@@ -15,7 +15,7 @@ module GR3
15
15
  raise LoadError, 'Could not find GR Framework'
16
16
  end
17
17
 
18
- extend GRCommons::Extern
18
+ extend GRCommons::TryExtern
19
19
 
20
20
  # https://github.com/sciapp/gr/blob/master/lib/gr3/gr3.h
21
21
  # keep same order
@@ -43,7 +43,7 @@ module GRCommons
43
43
  if narray?(data)
44
44
  Numo::Int32.cast(data).to_binary
45
45
  else
46
- Fiddley::Utils.array2str(:int32, data.to_a.flatten) # TODO
46
+ Fiddley::Utils.array2str(:int32, data.to_a.flatten)
47
47
  end
48
48
  end
49
49
 
@@ -52,7 +52,7 @@ module GRCommons
52
52
  if narray?(data)
53
53
  Numo::UInt32.cast(data).to_binary
54
54
  else
55
- Fiddley::Utils.array2str(:uint, data.to_a.flatten) # TODO
55
+ Fiddley::Utils.array2str(:uint32, data.to_a.flatten)
56
56
  end
57
57
  end
58
58
 
@@ -7,8 +7,8 @@ end
7
7
  # Change the default encoding to UTF-8.
8
8
  ENV['GKS_ENCODING'] ||= 'utf8'
9
9
 
10
- require_relative 'search_shared_library'
11
- require_relative 'extern'
10
+ require_relative 'gr_lib'
11
+ require_relative 'try_extern'
12
12
  require_relative 'define_methods'
13
13
  require_relative 'gr_common_utils'
14
14
  require_relative 'jupyter_support'
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pkg-config'
4
+
5
+ module GRCommons
6
+ # This module helps GR, GR and GRM to search the shared library.
7
+ #
8
+ # The order of priority:
9
+ # 1. RubyInstaller ( for Windows only )
10
+ # 2. Environment variable GRDIR
11
+ # 3. pkg-config : https://github.com/ruby-gnome/pkg-config
12
+ # The following packages (should) support pkg-config.
13
+ # - Linux
14
+ # - Red Data Tools https://github.com/red-data-tools/packages.red-data-tools.org
15
+ # - libgr-dev
16
+ # - libgr3-dev
17
+ # - libgrm-dev
18
+ # - Mac
19
+ # - Homebrew https://github.com/Homebrew/homebrew-core
20
+ # - libgr
21
+ # - Windows
22
+ # - MinGW https://github.com/msys2/MINGW-packages
23
+ # - mingw-w64-gr
24
+ module GRLib
25
+ class << self
26
+ # Search the shared library.
27
+ # @note This method does not detect the Operating System.
28
+ #
29
+ # @param lib_names [Array] The actual file name of the shared library.
30
+ # @param pkg_name [String] The package name to be used when searching with pkg-configg
31
+ def search(lib_names, pkg_name)
32
+ def lib_names.map_find(&block)
33
+ lazy.map(&block).find { |path| path }
34
+ end
35
+ # Windows + RubyInstaller
36
+ if Object.const_defined?(:RubyInstaller)
37
+ dir = ENV['GRDIR'] || [
38
+ RubyInstaller::Runtime.msys2_installation.msys_path,
39
+ RubyInstaller::Runtime.msys2_installation.mingwarch
40
+ ].join(File::ALT_SEPARATOR)
41
+ lib_names.lazy.map do |lib_name|
42
+ recursive_search(lib_name, dir)
43
+ end.find { |i| i }.tap do |path|
44
+ RubyInstaller::Runtime.add_dll_directory(File.dirname(path)) if path
45
+ end
46
+ # ENV['GRDIR'] (Linux, Mac, Windows)
47
+ elsif ENV['GRDIR']
48
+ # Search for XXX.dylib and then XXX.so on macOS
49
+ lib_names.map_find do |lib_name|
50
+ recursive_search(lib_name, ENV['GRDIR'])
51
+ end || lib_names.map_find do |lib_name|
52
+ pkg_config_search(lib_name, pkg_name)
53
+ end
54
+ else
55
+ lib_names.map_find do |lib_name|
56
+ pkg_config_search(lib_name, pkg_name)
57
+ end
58
+ end
59
+ end
60
+
61
+ # Recursive file search in directories
62
+ # @param name [String] File to search for
63
+ # @param base_dir [String] Directory to search
64
+ # @retrun path [String, NilClass] Returns the first path found.
65
+ # If not found, nil is returned.
66
+ def recursive_search(name, base_dir)
67
+ Dir.chdir(base_dir) do
68
+ paths = Dir["**/#{name}"].sort
69
+ warn "More than one file found: #{paths}" if paths.size > 1
70
+ path = paths.first
71
+ File.expand_path(path) if path
72
+ end
73
+ end
74
+
75
+ # Use pkg-config to search for shared libraries
76
+ def pkg_config_search(lib_name, pkg_name)
77
+ PKGConfig.variable(pkg_name, 'sopath')
78
+ rescue PackageConfig::NotFoundError => e
79
+ warn "#{e.message} Cannot find #{lib_name}. "
80
+ end
81
+ end
82
+ end
83
+ end
@@ -11,7 +11,7 @@ require 'awesome_print'
11
11
  module GRCommons
12
12
  class << self
13
13
  # Create a new GRLogger
14
- # @params out [String]
14
+ # @param out [String]
15
15
  # @return [GRLogger]
16
16
  # @example
17
17
  # require 'gr_commons/gr_logger'
@@ -2,7 +2,7 @@
2
2
 
3
3
  module GRCommons
4
4
  # This module records the names of the methods defined by Fiddle::Importer.
5
- module Extern
5
+ module TryExtern
6
6
  attr_reader :ffi_methods
7
7
 
8
8
  # Improved extern method.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GRCommons
4
- VERSION = '0.0.24'
4
+ VERSION = '0.0.25'
5
5
  end
data/lib/grm.rb CHANGED
@@ -17,23 +17,33 @@ end
17
17
  module GRM
18
18
  class Error < StandardError; end
19
19
 
20
+ class NotFoundError < Error; end
21
+
20
22
  class << self
21
23
  attr_accessor :ffi_lib
22
24
  end
23
25
 
24
26
  require_relative 'gr_commons/gr_commons'
25
- extend GRCommons::SearchSharedLibrary
26
27
 
27
28
  # Platforms | path
28
29
  # Windows | bin/libGRM.dll
29
- # MacOSX | lib/libGRM.so (NOT .dylib)
30
+ # MacOSX | lib/libGRM.dylib (v0.53.0 .so)
30
31
  # Ubuntu | lib/libGRM.so
31
- self.ffi_lib = case RbConfig::CONFIG['host_os']
32
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
33
- search_shared_library('libGRM.dll', 'grm')
34
- else
35
- search_shared_library('libGRM.so', 'grm')
36
- end
32
+ platform = RbConfig::CONFIG['host_os']
33
+ lib_names, pkg_name = \
34
+ case platform
35
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
36
+ [['libGRM.dll'], 'grm']
37
+ when /darwin|mac os/
38
+ [['libGRM.dylib', 'libGRM.so'], 'grm']
39
+ else
40
+ [['libGRM.so'], 'grm']
41
+ end
42
+ lib_path = GRCommons::GRLib.search(lib_names, pkg_name)
43
+
44
+ raise NotFoundError, "#{lib_names} not found" if lib_path.nil?
45
+
46
+ self.ffi_lib = lib_path
37
47
 
38
48
  require_relative 'grm/version'
39
49
  require_relative 'grm/ffi'
data/lib/grm/ffi.rb CHANGED
@@ -15,7 +15,7 @@ module GRM
15
15
  raise LoadError, 'Could not find GR Framework'
16
16
  end
17
17
 
18
- extend GRCommons::Extern
18
+ extend GRCommons::TryExtern
19
19
 
20
20
  # Currently, the declarations of GRM functions are distributed in several
21
21
  # header files.
@@ -28,6 +28,7 @@ module GRM
28
28
  try_extern 'int grm_args_contains(const grm_args_t *args, const char *keyword)'
29
29
  try_extern 'void grm_args_clear(grm_args_t *args)'
30
30
  try_extern 'void grm_args_remove(grm_args_t *args, const char *key)'
31
+ typealias 'grm_args_ptr_t', 'void*'
31
32
  try_extern 'grm_args_ptr_t grm_length(double value, const char *unit)'
32
33
 
33
34
  # https://github.com/sciapp/gr/blob/master/lib/grm/dump.h
@@ -36,13 +37,17 @@ module GRM
36
37
  try_extern 'char *grm_dump_json_str(void)'
37
38
 
38
39
  # https://github.com/sciapp/gr/blob/master/lib/grm/event.h
40
+ typealias 'grm_event_type_t', 'int' # enum
41
+ typealias 'grm_event_callback_t', 'void*'
39
42
  try_extern 'int grm_register(grm_event_type_t type, grm_event_callback_t callback)'
40
43
  try_extern 'int grm_unregister(grm_event_type_t type)'
41
44
 
42
45
  # https://github.com/sciapp/gr/blob/master/lib/grm/interaction.h
46
+ # FIXME: https://github.com/ruby/fiddle/issues/68
47
+ typealias 'const_int', 'int' # FIXME
43
48
  try_extern 'int grm_input(const grm_args_t *input_args)'
44
- try_extern 'int grm_get_box(const int x1, const int y1, const int x2, const int y2, const int keep_aspect_ratio, int *x, int *y, int *w, int *h)'
45
- try_extern 'grm_tooltip_info_t *grm_get_tooltip(const int, const int)'
49
+ try_extern 'int grm_get_box(const_int x1, const_int y1, const_int x2, const_int y2, const_int keep_aspect_ratio, int *x, int *y, int *w, int *h)' # FIXME
50
+ try_extern 'grm_tooltip_info_t *grm_get_tooltip(const_int, const_int)' # FIXME
46
51
 
47
52
  # https://github.com/sciapp/gr/blob/master/lib/grm/net.h
48
53
  try_extern 'void *grm_open(int is_receiver, const char *name, unsigned int id,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-gr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-04 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: histogram
@@ -154,13 +154,13 @@ files:
154
154
  - lib/gr3/gr3base.rb
155
155
  - lib/gr3/version.rb
156
156
  - lib/gr_commons/define_methods.rb
157
- - lib/gr_commons/extern.rb
158
157
  - lib/gr_commons/fiddley.rb
159
158
  - lib/gr_commons/gr_common_utils.rb
160
159
  - lib/gr_commons/gr_commons.rb
160
+ - lib/gr_commons/gr_lib.rb
161
161
  - lib/gr_commons/gr_logger.rb
162
162
  - lib/gr_commons/jupyter_support.rb
163
- - lib/gr_commons/search_shared_library.rb
163
+ - lib/gr_commons/try_extern.rb
164
164
  - lib/gr_commons/version.rb
165
165
  - lib/grm.rb
166
166
  - lib/grm/ffi.rb
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  requirements: []
189
- rubygems_version: 3.1.4
189
+ rubygems_version: 3.2.3
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: GR for Ruby
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'pkg-config'
4
-
5
- module GRCommons
6
- # This module helps GR, GR and GRM to search the shared library.
7
- #
8
- # The order of priority:
9
- # 1. RubyInstaller ( for Windows only )
10
- # 2. Environment variable GRDIR
11
- # 3. pkg-config : https://github.com/ruby-gnome/pkg-config
12
- # The following packages (should) support pkg-config.
13
- # - Linux
14
- # - Red Data Tools https://github.com/red-data-tools/packages.red-data-tools.org
15
- # - libgr-dev
16
- # - libgr3-dev
17
- # - libgrm-dev
18
- # - Mac
19
- # - Homebrew https://github.com/Homebrew/homebrew-core
20
- # - libgr
21
- # - Windows
22
- # - MinGW https://github.com/msys2/MINGW-packages
23
- # - mingw-w64-gr
24
- module SearchSharedLibrary
25
- # Search the shared library.
26
- # @note This method does not detect the Operating System.
27
- #
28
- # @param gr_lib_name [String] The actual file name of the shared library.
29
- # @param pkg_name [String] The package name to be used when searching with pkg-configg
30
- def search_shared_library(gr_lib_name, pkg_name)
31
- # Windows + RubyInstaller
32
- if Object.const_defined?(:RubyInstaller)
33
- ENV['GRDIR'] ||= [
34
- RubyInstaller::Runtime.msys2_installation.msys_path,
35
- RubyInstaller::Runtime.msys2_installation.mingwarch
36
- ].join(File::ALT_SEPARATOR)
37
- recursive_search(gr_lib_name, ENV['GRDIR']).tap do |path|
38
- RubyInstaller::Runtime.add_dll_directory(File.dirname(path))
39
- end
40
- # ENV['GRDIR'] (Linux, Mac, Windows)
41
- elsif ENV['GRDIR']
42
- begin
43
- recursive_search(gr_lib_name, ENV['GRDIR'])
44
- rescue StandardError => e
45
- warn "\nWhile searching for #{gr_lib_name} in the directory specified " \
46
- "in the GRDIR environment variable, ENV['GRDIR']=#{ENV['GRDIR']}, " \
47
- "the following error occurred : #{e.message}"
48
- pkg_config_search(gr_lib_name, pkg_name)
49
- end
50
- else
51
- pkg_config_search(gr_lib_name, pkg_name)
52
- end
53
- end
54
-
55
- def recursive_search(name, base_dir)
56
- Dir.chdir(base_dir) do
57
- path = Dir["**/#{name}"].first # FIXME
58
- if path
59
- File.expand_path(path)
60
- else
61
- raise "#{name} not found in #{base_dir}"
62
- end
63
- end
64
- end
65
-
66
- def pkg_config_search(gr_lib_name, pkg_name)
67
- PKGConfig.variable(pkg_name, 'sopath')
68
- rescue PackageConfig::NotFoundError => e
69
- raise "#{e.message} Cannot find #{gr_lib_name}. " \
70
- "Please Make sure that GR is installed and the environment ” \
71
- ”variable GRDIR is set correctly."
72
- end
73
- end
74
- end