Module: FFI::Native::ConfigTool

Extended by:
Loader
Defined in:
lib/ffi/native/config_tool.rb

Instance Method Summary collapse

Methods included from Loader

ffi_find_library_path, ffi_load, ffi_load_failure

Instance Method Details

#ffi_load_using_config_tool(command, search_paths: [], names: [], **options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ffi/native/config_tool.rb', line 15

def ffi_load_using_config_tool(command, search_paths: [], names: [], **options)
	return false unless output = ::IO.popen(command).read
	
	arguments = ::Shellwords.split(output)
	search_paths = search_paths.dup
	names = names.dup
	
	arguments.each do |argument|
		if match = argument.match(/\A(-[lL])(.*)\z/)
			command, value = match.captures
			case command
			when '-L'
				search_paths << value
			when '-l'
				names << value
			end
		elsif File.directory?(argument)
			# Assume it's a search path:
			search_paths << argument
		end
	end
	
	result = false
	
	# Load all specified libraries:
	names.each do |name|
		result = ffi_load(name, search_paths: search_paths, **options) || result
	end
	
	return result
rescue Errno::ENOENT
	return nil
end