Class: FFI::Clang::Args

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi/clang/args/args.rb

Overview

Platform-specific clang configuration: finding libclang, locating the resource directory, and injecting extra command-line arguments into parse_translation_unit.

All discovery is lazy — nothing runs until a method is called.

Direct Known Subclasses

DarwinArgs, LinuxArgs, MingwArgs, MswinArgs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#libclang_loaded_path=(value) ⇒ Object (writeonly)

Set the loaded libclang path after ffi_lib succeeds, so resource dir probing can use it.



19
20
21
# File 'lib/ffi/clang/args/args.rb', line 19

def libclang_loaded_path=(value)
  @libclang_loaded_path = value
end

Class Method Details

.createObject

Factory: returns the platform-appropriate subclass instance.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ffi/clang/args/args.rb', line 23

def self.create
	case FFI::Clang.platform
	when :darwin
		DarwinArgs.new
	when :mingw
		MingwArgs.new
	when :mswin
		MswinArgs.new
	else
		LinuxArgs.new
	end
end

Instance Method Details

#command_line_args(command_line_args = []) ⇒ Object

Extra args to inject into parse_translation_unit. Includes -resource-dir (unless already present) plus any platform-specific flags.



51
52
53
54
55
56
57
58
59
60
# File 'lib/ffi/clang/args/args.rb', line 51

def command_line_args(command_line_args = [])
	args = []
	
	if !command_line_args.include?("-resource-dir") && resource_dir
		args.push("-resource-dir", resource_dir)
	end
	
	args.concat(extra_args(command_line_args))
	args
end

#libclang_pathsObject

Ordered list of library paths for ffi_lib.



38
39
40
41
42
43
44
# File 'lib/ffi/clang/args/args.rb', line 38

def libclang_paths
	@libclang_paths ||= if ENV["LIBCLANG"]
		[ENV["LIBCLANG"]]
	else
		find_libclang_paths
	end
end

#post_load(library) ⇒ Object

Called after ffi_lib successfully loads libclang. Subclasses may override to perform post-load setup.



76
77
# File 'lib/ffi/clang/args/args.rb', line 76

def post_load(library)
end

#resource_dirObject

The resolved resource directory path.



64
65
66
67
68
69
70
# File 'lib/ffi/clang/args/args.rb', line 64

def resource_dir
	if defined?(@resource_dir)
		@resource_dir
	else
		@resource_dir = find_resource_dir
	end
end