ruby-gr 0.0.17 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gr3.rb CHANGED
@@ -60,23 +60,20 @@ module GR3
60
60
  attr_accessor :ffi_lib
61
61
  end
62
62
 
63
- raise Error, 'Please set env variable GRDIR' unless ENV['GRDIR']
63
+ require_relative 'gr_commons/gr_commons'
64
+ extend GRCommons::SearchSharedLibrary
64
65
 
65
66
  # Platforms | path
66
67
  # Windows | bin/libGR3.dll
67
68
  # MacOSX | lib/libGR3.so (NOT .dylib)
68
69
  # Ubuntu | lib/libGR3.so
69
- if Object.const_defined?(:RubyInstaller)
70
- self.ffi_lib = File.expand_path('bin/libGR3.dll', ENV['GRDIR'])
71
- RubyInstaller::Runtime.add_dll_directory(File.dirname(ffi_lib))
72
- else
73
- self.ffi_lib = File.expand_path('lib/libGR3.so', ENV['GRDIR'])
74
- end
70
+ self.ffi_lib = case RbConfig::CONFIG['host_os']
71
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
72
+ search_shared_library('libGR3.dll', 'gr3')
73
+ else
74
+ search_shared_library('libGR3.so', 'gr3')
75
+ end
75
76
 
76
- # change the default encoding to UTF-8.
77
- ENV['GKS_ENCODING'] ||= 'utf8'
78
-
79
- require_relative 'gr_commons/gr_commons'
80
77
  require_relative 'gr3/version'
81
78
  require_relative 'gr3/ffi'
82
79
  require_relative 'gr3/gr3base'
@@ -13,7 +13,7 @@ module GRCommons
13
13
  # NOTE: This module is only part of the original code.
14
14
  # kojix2 adds, deletes, and modifies several methods.
15
15
  module Fiddley
16
- # NOTE: GR.rb supports 2.4 +. Unpack 1 does not work under 2.3.
16
+ # NOTE: GR.rb supports 2.5 +. Unpack 1 does not work under 2.3.
17
17
 
18
18
  module Utils
19
19
  # assumes short = 16bit, int = 32bit, long long = 64bit
@@ -4,6 +4,10 @@
4
4
  module GRCommons
5
5
  end
6
6
 
7
+ # Change the default encoding to UTF-8.
8
+ ENV['GKS_ENCODING'] ||= 'utf8'
9
+
10
+ require_relative 'search_shared_library'
7
11
  require_relative 'extern'
8
12
  require_relative 'define_methods'
9
13
  require_relative 'gr_common_utils'
@@ -0,0 +1,73 @@
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
+ if path = Dir["**/#{name}"].first # FIXME
58
+ File.expand_path(path)
59
+ else
60
+ raise StandardError "#{name} not found in #{base_dir}"
61
+ end
62
+ end
63
+ end
64
+
65
+ def pkg_config_search(gr_lib_name, pkg_name)
66
+ PKGConfig.variable(pkg_name, 'sopath')
67
+ rescue NotFoundError => e
68
+ warn "Cannot find #{gr_lib_name}."
69
+ warn 'Please set environment variable GRDIR.'
70
+ raise e
71
+ end
72
+ end
73
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GRCommons
4
- VERSION = '0.0.17'
4
+ VERSION = '0.0.22'
5
5
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Check Fiddle version.
4
+ require 'fiddle'
5
+
6
+ # Check if fiddle supports variadic arguments.
7
+ # Fiddle is a standard Gem and may not have VERSION constant.
8
+ if !Fiddle.const_defined?(:VERSION) ||
9
+ (Gem::Version.new(Fiddle::VERSION) <= Gem::Version.new('1.0.0'))
10
+ raise LoadError, <<~MSG
11
+ Failed to load GRM module
12
+ Fiddle 1.0.1 or higher is required to run GRM.
13
+ See https://github.com/ruby/fiddle
14
+ MSG
15
+ end
16
+
17
+ module GRM
18
+ class Error < StandardError; end
19
+
20
+ class << self
21
+ attr_accessor :ffi_lib
22
+ end
23
+
24
+ require_relative 'gr_commons/gr_commons'
25
+ extend GRCommons::SearchSharedLibrary
26
+
27
+ # Platforms | path
28
+ # Windows | bin/libGRM.dll
29
+ # MacOSX | lib/libGRM.so (NOT .dylib)
30
+ # 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
37
+
38
+ require_relative 'grm/version'
39
+ require_relative 'grm/ffi'
40
+ require_relative 'grm/grmbase'
41
+
42
+ # `inquiry` methods etc. are defined here.
43
+ extend GRCommons::GRCommonUtils
44
+
45
+ # `XXX` is the default type in GR.
46
+ # A Ruby array or NArray passed to GR method is automatically converted to
47
+ # a Fiddley::MemoryPointer in the GRBase class.
48
+ extend GRMBase
49
+
50
+ class << self
51
+ end
52
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fiddle/import'
4
+
5
+ module GRM
6
+ # FFI Wrapper module for GRM.
7
+ # The functions for GRM are listed here.
8
+ # Add functions here when a new version of GR is released.
9
+ module FFI
10
+ extend Fiddle::Importer
11
+
12
+ begin
13
+ dlload GRM.ffi_lib
14
+ rescue LoadError
15
+ raise LoadError, 'Could not find GR Framework'
16
+ end
17
+
18
+ extend GRCommons::Extern
19
+
20
+ # Currently, the declarations of GRM functions are distributed in several
21
+ # header files.
22
+
23
+ # https://github.com/sciapp/gr/blob/master/lib/grm/args.h
24
+ try_extern 'grm_args_t *grm_args_new(void)'
25
+ try_extern 'void grm_args_delete(grm_args_t *args)'
26
+ try_extern 'int grm_args_push(grm_args_t *args, const char *key, const char *value_format, ...)'
27
+ try_extern 'int grm_args_push_buf(grm_args_t *args, const char *key, const char *value_format, const void *buffer, int apply_padding)'
28
+ try_extern 'int grm_args_contains(const grm_args_t *args, const char *keyword)'
29
+ try_extern 'void grm_args_clear(grm_args_t *args)'
30
+ try_extern 'void grm_args_remove(grm_args_t *args, const char *key)'
31
+ try_extern 'grm_args_ptr_t grm_length(double value, const char *unit)'
32
+
33
+ # https://github.com/sciapp/gr/blob/master/lib/grm/dump.h
34
+ try_extern 'void grm_dump(const grm_args_t *args, FILE *f)'
35
+ try_extern 'void grm_dump_json(const grm_args_t *args, FILE *f)'
36
+ try_extern 'char *grm_dump_json_str(void)'
37
+
38
+ # https://github.com/sciapp/gr/blob/master/lib/grm/event.h
39
+ try_extern 'int grm_register(grm_event_type_t type, grm_event_callback_t callback)'
40
+ try_extern 'int grm_unregister(grm_event_type_t type)'
41
+
42
+ # https://github.com/sciapp/gr/blob/master/lib/grm/interaction.h
43
+ 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_input(const grm_args_t *input_args)'
46
+ try_extern 'grm_tooltip_info_t *grm_get_tooltip(const int, const int)'
47
+
48
+ # https://github.com/sciapp/gr/blob/master/lib/grm/net.h
49
+ try_extern 'void *grm_open(int is_receiver, const char *name, unsigned int id,
50
+ const char *(*custom_recv)(const char *, unsigned int),
51
+ int (*custom_send)(const char *, unsigned int, const char *))'
52
+ try_extern 'grm_args_t *grm_recv(const void *p, grm_args_t *args)'
53
+ try_extern 'int grm_send(const void *p, const char *data_desc, ...)'
54
+ try_extern 'int grm_send_buf(const void *p, const char *data_desc, const void *buffer, int apply_padding)'
55
+ try_extern 'int grm_send_ref(const void *p, const char *key, char format, const void *ref, int len)'
56
+ try_extern 'int grm_send_args(const void *p, const grm_args_t *args)'
57
+ try_extern 'void grm_close(const void *p)'
58
+
59
+ # https://github.com/sciapp/gr/blob/master/lib/grm/plot.h
60
+ try_extern 'void grm_finalize(void)'
61
+ try_extern 'int grm_clear(void)'
62
+ try_extern 'unsigned int grm_max_plotid(void)'
63
+ try_extern 'int grm_merge(const grm_args_t *args)'
64
+ try_extern 'int grm_merge_extended(const grm_args_t *args, int hold, const char *identificator)'
65
+ try_extern 'int grm_merge_hold(const grm_args_t *args)'
66
+ try_extern 'int grm_merge_named(const grm_args_t *args, const char *identificator)'
67
+ try_extern 'int grm_plot(const grm_args_t *args)'
68
+ try_extern 'int grm_switch(unsigned int id)'
69
+
70
+ # https://github.com/sciapp/gr/blob/master/lib/grm/util.h
71
+ try_extern 'FILE *grm_get_stdout(void)'
72
+ end
73
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GRM
4
+ # This module automatically converts Ruby arrays and Numo::Narray into
5
+ # Fiddley::MemoryPointer.
6
+ module GRMBase
7
+ extend GRCommons::DefineMethods
8
+ define_ffi_methods(FFI,
9
+ prefix: 'grm_',
10
+ default_type: :float) # FIXME!
11
+ end
12
+ private_constant :GRMBase
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GRM
4
+ VERSION = GRCommons::VERSION
5
+ end
metadata CHANGED
@@ -1,23 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-gr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-03 00:00:00.000000000 Z
11
+ date: 2020-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: histogram
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
- type: :development
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
@@ -25,7 +25,35 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: histogram
28
+ name: numo-narray
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pkg-config
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
59
  - - ">="
@@ -39,7 +67,7 @@ dependencies:
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
- name: numo-narray
70
+ name: fiddle
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - ">="
@@ -146,11 +174,17 @@ files:
146
174
  - lib/gr_commons/gr_common_utils.rb
147
175
  - lib/gr_commons/gr_commons.rb
148
176
  - lib/gr_commons/jupyter_support.rb
177
+ - lib/gr_commons/search_shared_library.rb
149
178
  - lib/gr_commons/version.rb
179
+ - lib/grm.rb
180
+ - lib/grm/ffi.rb
181
+ - lib/grm/grmbase.rb
182
+ - lib/grm/version.rb
150
183
  homepage: https://github.com/red-data-tools/GR.rb
151
184
  licenses:
152
185
  - MIT
153
- metadata: {}
186
+ metadata:
187
+ msys2_mingw_dependencies: gr
154
188
  post_install_message:
155
189
  rdoc_options: []
156
190
  require_paths:
@@ -159,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
193
  requirements:
160
194
  - - ">="
161
195
  - !ruby/object:Gem::Version
162
- version: '2.4'
196
+ version: '2.5'
163
197
  required_rubygems_version: !ruby/object:Gem::Requirement
164
198
  requirements:
165
199
  - - ">="