From 977d72f3453591e697ed5e7670b365afbbd06eed Mon Sep 17 00:00:00 2001 From: Yury Romanov Date: Tue, 20 Mar 2018 15:47:46 +0100 Subject: [PATCH 1/4] Do not raise exception if eric binaries are not available --- lib/liberic/boot.rb | 8 +++++++- lib/liberic/sdk/api.rb | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/liberic/boot.rb b/lib/liberic/boot.rb index 47c70cb..887f06b 100644 --- a/lib/liberic/boot.rb +++ b/lib/liberic/boot.rb @@ -8,6 +8,10 @@ def eric_home ERIC_HOME end + def binaries_unavailable? + ENV['ERIC_HOME_27'].to_s.empty? + end + def library_path suffix = if RUBY_PLATFORM =~ /linux/ 'so' @@ -19,10 +23,12 @@ def library_path File.expand_path("libericapi.#{suffix}", ERIC_LIB_FOLDER) end - ERIC_HOME = ENV['ERIC_HOME_27'] || raise(InitializationError.new('ERIC_HOME_27 environment variable not found (set it to the path to the ERiC libraries)')) + ERIC_HOME = ENV['ERIC_HOME_272'] || warn(InitializationError.new('ERIC_HOME_27 environment variable not found (set it to the path to the ERiC libraries)')) ERIC_LIB_FOLDER = File.expand_path('lib', ERIC_HOME) def check_eric_version! + return true if binaries_unavailable? + version_response = Response::Version.new( Helpers::Invocation.with_result_buffer do |handle| SDK::API::version(handle) diff --git a/lib/liberic/sdk/api.rb b/lib/liberic/sdk/api.rb index 290a488..1a79c53 100644 --- a/lib/liberic/sdk/api.rb +++ b/lib/liberic/sdk/api.rb @@ -2,11 +2,20 @@ module Liberic module SDK module API extend FFI::Library - ffi_lib Liberic.library_path - def self.attach_eric_function(name, params, return_type, original_name = nil) - original_name ||= 'Eric' + name.to_s.capitalize.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" } - attach_function(name, original_name, params, return_type) + if Liberic.binaries_available? + ffi_lib Liberic.library_path + + def self.attach_eric_function(name, params, return_type, original_name = nil) + original_name ||= 'Eric' + name.to_s.capitalize.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" } + attach_function(name, original_name, params, return_type) + end + else + # define fake functions to allow tests pass + def self.attach_eric_function(name, params, return_type, original_name = nil) + define_method(name) { |*options| true } + end + extend self end # ERICAPI_DECL int STDCALL EricBearbeiteVorgang( From 2d9e465b16dda45405999ea82c8cf925c6de7eff Mon Sep 17 00:00:00 2001 From: Yury Romanov Date: Tue, 20 Mar 2018 15:55:26 +0100 Subject: [PATCH 2/4] Remove debug code --- lib/liberic/boot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/liberic/boot.rb b/lib/liberic/boot.rb index 887f06b..9d73d19 100644 --- a/lib/liberic/boot.rb +++ b/lib/liberic/boot.rb @@ -23,7 +23,7 @@ def library_path File.expand_path("libericapi.#{suffix}", ERIC_LIB_FOLDER) end - ERIC_HOME = ENV['ERIC_HOME_272'] || warn(InitializationError.new('ERIC_HOME_27 environment variable not found (set it to the path to the ERiC libraries)')) + ERIC_HOME = ENV['ERIC_HOME_27'] || warn(InitializationError.new('ERIC_HOME_27 environment variable not found (set it to the path to the ERiC libraries)')) ERIC_LIB_FOLDER = File.expand_path('lib', ERIC_HOME) def check_eric_version! From 35657dd14a3883419c0518a8ea2e79c8772a5c61 Mon Sep 17 00:00:00 2001 From: Yury Romanov Date: Tue, 20 Mar 2018 15:59:10 +0100 Subject: [PATCH 3/4] Rearrange code --- lib/liberic/sdk/api.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/liberic/sdk/api.rb b/lib/liberic/sdk/api.rb index 1a79c53..67d53fd 100644 --- a/lib/liberic/sdk/api.rb +++ b/lib/liberic/sdk/api.rb @@ -3,19 +3,19 @@ module SDK module API extend FFI::Library - if Liberic.binaries_available? + if Liberic.binaries_unavailable? + # define fake functions to allow tests pass + def self.attach_eric_function(name, params, return_type, original_name = nil) + define_method(name) { |*options| true } + end + extend self + else ffi_lib Liberic.library_path def self.attach_eric_function(name, params, return_type, original_name = nil) original_name ||= 'Eric' + name.to_s.capitalize.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" } attach_function(name, original_name, params, return_type) end - else - # define fake functions to allow tests pass - def self.attach_eric_function(name, params, return_type, original_name = nil) - define_method(name) { |*options| true } - end - extend self end # ERICAPI_DECL int STDCALL EricBearbeiteVorgang( From 56caf6637b600ef9af9efee3d26c071535345fe1 Mon Sep 17 00:00:00 2001 From: Yury Romanov Date: Tue, 20 Mar 2018 17:06:01 +0100 Subject: [PATCH 4/4] Replace define_method to define_singleton_method --- lib/liberic/sdk/api.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/liberic/sdk/api.rb b/lib/liberic/sdk/api.rb index 67d53fd..6633447 100644 --- a/lib/liberic/sdk/api.rb +++ b/lib/liberic/sdk/api.rb @@ -6,9 +6,8 @@ module API if Liberic.binaries_unavailable? # define fake functions to allow tests pass def self.attach_eric_function(name, params, return_type, original_name = nil) - define_method(name) { |*options| true } + define_singleton_method(name) { |*options| true } end - extend self else ffi_lib Liberic.library_path