Module: GRCommons::SearchSharedLibrary

Included in:
GR, GR3, GRM
Defined in:
lib/gr_commons/search_shared_library.rb

Overview

This module helps GR, GR and GRM to search the shared library.

The order of priority:

  1. RubyInstaller ( for Windows only )

  2. Environment variable GRDIR

  3. pkg-config : github.com/ruby-gnome/pkg-config

The following packages (should) support pkg-config.

Instance Method Summary collapse

Instance Method Details

#pkg_config_search(gr_lib_name, pkg_name) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/gr_commons/search_shared_library.rb', line 66

def pkg_config_search(gr_lib_name, pkg_name)
  PKGConfig.variable(pkg_name, 'sopath')
rescue PackageConfig::NotFoundError => e
  raise "#{e.message} Cannot find #{gr_lib_name}. " \
        "Please Make sure that GR is installed and the environment ” \
        ”variable GRDIR is set correctly."
end

#recursive_search(name, base_dir) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/gr_commons/search_shared_library.rb', line 55

def recursive_search(name, base_dir)
  Dir.chdir(base_dir) do
    path = Dir["**/#{name}"].first # FIXME
    if path
      File.expand_path(path)
    else
      raise "#{name} not found in #{base_dir}"
    end
  end
end

#search_shared_library(gr_lib_name, pkg_name) ⇒ Object

Note:

This method does not detect the Operating System.

Search the shared library.

Parameters:

  • gr_lib_name (String)

    The actual file name of the shared library.

  • pkg_name (String)

    The package name to be used when searching with pkg-configg



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gr_commons/search_shared_library.rb', line 30

def search_shared_library(gr_lib_name, pkg_name)
  # Windows + RubyInstaller
  if Object.const_defined?(:RubyInstaller)
    ENV['GRDIR'] ||= [
      RubyInstaller::Runtime.msys2_installation.msys_path,
      RubyInstaller::Runtime.msys2_installation.mingwarch
    ].join(File::ALT_SEPARATOR)
    recursive_search(gr_lib_name, ENV['GRDIR']).tap do |path|
      RubyInstaller::Runtime.add_dll_directory(File.dirname(path))
    end
  # ENV['GRDIR'] (Linux, Mac, Windows)
  elsif ENV['GRDIR']
    begin
      recursive_search(gr_lib_name, ENV['GRDIR'])
    rescue StandardError => e
      warn "\nWhile searching for #{gr_lib_name} in the directory specified " \
           "in the GRDIR environment variable, ENV['GRDIR']=#{ENV['GRDIR']}, " \
           "the following error occurred : #{e.message}"
      pkg_config_search(gr_lib_name, pkg_name)
    end
  else
    pkg_config_search(gr_lib_name, pkg_name)
  end
end