Module: GRCommons::GRLib
- Defined in:
- lib/gr_commons/gr_lib.rb
Overview
This module helps GR, GR and GRM to search the shared library.
The order of priority:
-
RubyInstaller ( for Windows only )
-
Environment variable GRDIR
-
pkg-config : github.com/ruby-gnome/pkg-config
The following packages (should) support pkg-config.
-
Linux
-
Red Data Tools github.com/red-data-tools/packages.red-data-tools.org
-
libgr-dev
-
libgr3-dev
-
libgrm-dev
-
-
-
Mac
-
Homebrew github.com/Homebrew/homebrew-core
-
libgr
-
-
-
Windows
-
MinGW github.com/msys2/MINGW-packages
-
mingw-w64-gr
-
-
Class Method Summary collapse
-
.pkg_config_search(lib_name, pkg_name) ⇒ Object
Use pkg-config to search for shared libraries.
-
.recursive_search(name, base_dir) ⇒ Object
Recursive file search in directories.
-
.search(lib_names, pkg_name) ⇒ Object
Search the shared library.
Class Method Details
.pkg_config_search(lib_name, pkg_name) ⇒ Object
Use pkg-config to search for shared libraries
76 77 78 79 80 |
# File 'lib/gr_commons/gr_lib.rb', line 76 def pkg_config_search(lib_name, pkg_name) PKGConfig.variable(pkg_name, 'sopath') rescue PackageConfig::NotFoundError => e warn "#{e.message} Cannot find #{lib_name}. " end |
.recursive_search(name, base_dir) ⇒ Object
Recursive file search in directories
66 67 68 69 70 71 72 73 |
# File 'lib/gr_commons/gr_lib.rb', line 66 def recursive_search(name, base_dir) Dir.chdir(base_dir) do paths = Dir["**/#{name}"].sort warn "More than one file found: #{paths}" if paths.size > 1 path = paths.first File.(path) if path end end |
.search(lib_names, pkg_name) ⇒ Object
Note:
This method does not detect the Operating System.
Search the shared library.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gr_commons/gr_lib.rb', line 31 def search(lib_names, pkg_name) def lib_names.map_find(&block) lazy.map(&block).find { |path| path } end # Windows + RubyInstaller if Object.const_defined?(:RubyInstaller) dir = ENV['GRDIR'] || [ RubyInstaller::Runtime.msys2_installation.msys_path, RubyInstaller::Runtime.msys2_installation.mingwarch ].join(File::ALT_SEPARATOR) lib_names.lazy.map do |lib_name| recursive_search(lib_name, dir) end.find { |i| i }.tap do |path| RubyInstaller::Runtime.add_dll_directory(File.dirname(path)) if path end # ENV['GRDIR'] (Linux, Mac, Windows) elsif ENV['GRDIR'] # Search for XXX.dylib and then XXX.so on macOS lib_names.map_find do |lib_name| recursive_search(lib_name, ENV['GRDIR']) end || lib_names.map_find do |lib_name| pkg_config_search(lib_name, pkg_name) end else lib_names.map_find do |lib_name| pkg_config_search(lib_name, pkg_name) end end end |