Module: TebakoRuntime
- Defined in:
- lib/tebako-runtime.rb,
lib/tebako-runtime/memfs.rb,
lib/tebako-runtime/version.rb,
lib/tebako-runtime/pre/seven-zip.rb,
lib/tebako-runtime/adapters/mn2pdf.rb
Overview
Unpack mn2pdf.jar
Constant Summary collapse
- PRE_REQUIRE_MAP =
{ "excavate" => "tebako-runtime/pre/excavate", "seven_zip_ruby" => "tebako-runtime/pre/seven-zip" }.freeze
- POST_REQUIRE_MAP =
{ "ffi" => "tebako-runtime/adapters/ffi", "jing" => "tebako-runtime/adapters/jing", "mn2pdf" => "tebako-runtime/adapters/mn2pdf", "mnconvert" => "tebako-runtime/adapters/mnconvert", "net/http" => "tebako-runtime/adapters/net-http", "sassc" => "tebako-runtime/adapters/sassc", "sinatra" => "tebako-runtime/adapters/sinatra" }.freeze
- COMPILER_MEMFS =
RUBY_PLATFORM =~ /mswin|mingw/ ? "A:/__tebako_memfs__" : "/__tebako_memfs__"
- COMPILER_MEMFS_LIB_CACHE =
initialize_compiler_memfs_lib_cache
- VERSION =
"0.5.4"
- MN2PDF_J_PATH =
TebakoRuntime.extract_memfs(File.join(TebakoRuntime.full_gem_path("mn2pdf"), "bin", "mn2pdf.jar"))
Class Method Summary collapse
- .extract(file, wild, extract_path) ⇒ Object
-
.extract_memfs(file, wild: false, cache_path: COMPILER_MEMFS_LIB_CACHE) ⇒ Object
wild == true means “also extract other files with the same extension”.
- .full_gem_path(gem) ⇒ Object
- .initialize_compiler_memfs_lib_cache ⇒ Object
- .log_enabled ⇒ Object
- .process(name, map, title) ⇒ Object
- .process_all(name) ⇒ Object
-
.process_pass_through(name) ⇒ Object
Very special deploy-time patching It targets ffi-compiler/ffi-compiler2 that use some functions of deployed ffi to process other gems THis approach is not compatible with tebako on Windows because ffi is deployed with (implib) reference to target tebako package that is not available at deploy time.
Class Method Details
.extract(file, wild, extract_path) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/tebako-runtime/memfs.rb', line 54 def self.extract(file, wild, extract_path) files = if wild Dir.glob("#{File.dirname(file)}/*#{File.extname(file)}") else [file] end FileUtils.cp_r files, extract_path end |
.extract_memfs(file, wild: false, cache_path: COMPILER_MEMFS_LIB_CACHE) ⇒ Object
wild == true means “also extract other files with the same extension”
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/tebako-runtime/memfs.rb', line 64 def self.extract_memfs(file, wild: false, cache_path: COMPILER_MEMFS_LIB_CACHE) is_quoted = file.quoted? file = file.unquote if is_quoted return is_quoted ? file.quote : file unless File.exist?(file) && file.start_with?(COMPILER_MEMFS) memfs_extracted_file = cache_path + File.basename(file) extract(file, wild, cache_path) unless memfs_extracted_file.exist? is_quoted ? memfs_extracted_file.to_path.quote : memfs_extracted_file.to_path end |
.full_gem_path(gem) ⇒ Object
54 55 56 |
# File 'lib/tebako-runtime.rb', line 54 def self.full_gem_path(gem) Gem::Specification.find_by_name(gem).full_gem_path end |
.initialize_compiler_memfs_lib_cache ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tebako-runtime/memfs.rb', line 38 def self.initialize_compiler_memfs_lib_cache Pathname.new(Dir.mktmpdir("tebako-runtime-")) rescue StandardError return nil unless defined?($tebako_original_pwd) && !$tebako_original_pwd.nil? # rubocop:disable Style/GlobalVars begin Pathname.new(Dir.mktmpdir("tebako-runtime-", $tebako_original_pwd)) # rubocop:disable Style/GlobalVars rescue StandardError nil end end |
.log_enabled ⇒ Object
58 59 60 |
# File 'lib/tebako-runtime.rb', line 58 def self.log_enabled @log_enabled ||= false end |
.process(name, map, title) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/tebako-runtime.rb', line 62 def self.process(name, map, title) return !log_enabled unless map.key?(name) puts "Tebako runtime: req/#{title} [#{name} => #{map[name]}]" if log_enabled res_inner = require_relative map[name] puts "Tebako runtime: skipped [#{name}]" if log_enabled && !res_inner log_enabled end |
.process_all(name) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/tebako-runtime.rb', line 71 def self.process_all(name) f1 = process(name, PRE_REQUIRE_MAP, "pre") res = original_require name f2 = process(name, POST_REQUIRE_MAP, "post") puts "Tebako runtime: req [#{name}]" unless f1 || f2 res end |
.process_pass_through(name) ⇒ Object
Very special deploy-time patching It targets ffi-compiler/ffi-compiler2 that use some functions of deployed ffi to process other gems THis approach is not compatible with tebako on Windows because ffi is deployed with (implib) reference to target tebako package that is not available at deploy time
86 87 88 89 90 91 92 93 94 |
# File 'lib/tebako-runtime.rb', line 86 def self.process_pass_through(name) if name == "ffi" && RUBY_PLATFORM =~ /mswin|mingw/ puts "Replacing ffi ffi-platform-stub" if log_enabled res = original_require "tebako-runtime/pass-through/ffi-platform-stub" else res = original_require name end res end |