Top Level Namespace
Defined Under Namespace
Modules: Rice
Constant Summary collapse
- IS_MSWIN =
/mswin/ =~ RUBY_PLATFORM
- IS_MINGW =
/mingw/ =~ RUBY_PLATFORM
- IS_DARWIN =
RbConfig::CONFIG['host_os'].match?(/darwin/)
- LINE_ENDING =
"\n"- RICE_INCLUDE_REGEX =
%r{#include "(.*)"}- OTHER_INCLUDE_REGEX =
%r{#include <(.*)>}- RICE_HEADER_GUARD_1 =
%r{#ifndef Rice__}- RICE_HEADER_GUARD_2 =
%r{#define Rice__}- RICE_HEADER_GUARD_3 =
%r{#endif\s*//\s*Rice__}- SHARED_METHODS_REGEX =
%r{#include "((?:cpp_api\/)?shared_methods.hpp)"}
Instance Method Summary collapse
- #add_include(path, stream) ⇒ Object
- #combine_headers(filename) ⇒ Object
- #have_libffi ⇒ Object
- #load_file(relative_path) ⇒ Object
- #strip_includes(content) ⇒ Object
-
#system_libffi_usable? ⇒ Boolean
Copied from Ruby FFI bindings - see github.com/ffi/ffi/blob/1715332d553d53fae13fd9fcbbd9d2c1982a5c2f/ext/ffi_c/extconf.rb#L7C1-L27C6.
Instance Method Details
#add_include(path, stream) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rice/make_rice_headers.rb', line 32 def add_include(path, stream) basename = File.basename(path) basename_no_ext = File.basename(path, ".*") stream << "\n" << "// ========= #{File.basename(path)} =========" << "\n" load_file(path).each_line do |line| if match = line.match(RICE_INCLUDE_REGEX) # Check for related includes, ie., Object.hpp, Object_defn.hpp and Object.ipp sub_include = File.basename(match[1]) if ["#{basename_no_ext}_defn.hpp", "#{basename_no_ext}.ipp"].include?(sub_include) sub_include_path = File.join(File.dirname(path), match[1]) stream << "\n" << "// --------- #{File.basename(sub_include_path)} ---------" << "\n" stream << strip_includes(load_file(sub_include_path)) end elsif line.match(RICE_HEADER_GUARD_1) || line.match(RICE_HEADER_GUARD_2) || line.match(RICE_HEADER_GUARD_3) # Skip the header guard else # Include the line in the output stream << line end end end |
#combine_headers(filename) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rice/make_rice_headers.rb', line 56 def combine_headers(filename) stream = StringIO.new stream << "// This file is part of [rice](https://github.com/ruby-rice/rice).\n" stream << "//\n" load_file("COPYING").each_line do |line| stream << (line.strip.size.zero? ? "//\n" : "// #{line}") end stream << "\n" load_file("rice/#{filename}").each_line do |line| if matches = line.match(RICE_INCLUDE_REGEX) path = File.join("rice", matches[1]) add_include(path, stream) else stream << line end end File.open("include/rice/#{filename}", 'wb') do |file| file << stream.string end end |
#have_libffi ⇒ Object
75 76 77 78 79 80 |
# File 'lib/mkmf-rice.rb', line 75 def have_libffi # Check for libffi to support C style callacks. libffi_usable = system_libffi_usable? $CPPFLAGS += " -DHAVE_LIBFFI" if libffi_usable libffi_usable end |
#load_file(relative_path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rice/make_rice_headers.rb', line 12 def load_file(relative_path) content = File.read(relative_path, mode: 'rb') # Special case shared_methods.hpp which if requested we want to # merge into the current file match = content.match(SHARED_METHODS_REGEX) if match shared_path = File.join(File.dirname(relative_path), match[1]) content.gsub!(SHARED_METHODS_REGEX, File.read(shared_path, mode: 'rb')) end content end |
#strip_includes(content) ⇒ Object
26 27 28 29 30 |
# File 'lib/rice/make_rice_headers.rb', line 26 def strip_includes(content) content.lines.find_all do |line| !line.match(RICE_INCLUDE_REGEX) end.join end |
#system_libffi_usable? ⇒ Boolean
Copied from Ruby FFI bindings - see github.com/ffi/ffi/blob/1715332d553d53fae13fd9fcbbd9d2c1982a5c2f/ext/ffi_c/extconf.rb#L7C1-L27C6
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mkmf-rice.rb', line 53 def system_libffi_usable? # We need pkg_config or ffi.h libffi_ok = pkg_config("libffi") || have_header("ffi.h") || find_header("ffi.h", "/usr/local/include", "/usr/include/ffi", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ffi", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ffi") || (find_header("ffi.h", `xcrun --sdk macosx --show-sdk-path`.strip + "/usr/include/ffi") rescue false) # Ensure we can link to ffi_prep_closure_loc libffi_ok &&= have_library("ffi", "ffi_prep_closure_loc", [ "ffi.h" ]) || have_library("libffi", "ffi_prep_closure_loc", [ "ffi.h" ]) || have_library("libffi-8", "ffi_prep_closure_loc", [ "ffi.h" ]) if RbConfig::CONFIG['host_os'] =~ /mswin/ have_library('libffi_convenience') have_library('shlwapi') end libffi_ok end |