diff --git a/Rakefile b/Rakefile index 0834bca..fc639d8 100644 --- a/Rakefile +++ b/Rakefile @@ -35,14 +35,17 @@ require "fileutils" namespace :build do desc "Download cacert.pem" task :download_cacert do - url = URI("https://curl.se/ca/cacert.pem") - FileUtils.mkdir_p("lib/cert") - Net::HTTP.start(url.host, url.port, use_ssl: url.scheme == "https") do |http| - request = Net::HTTP::Get.new url - http.request request do |response| - open "lib/cert/cacert.pem.mozilla", "w" do |io| - response.read_body do |chunk| - io.write chunk + unless File.exist?("lib/cert/cacert.pem.mozilla") + + url = URI("https://curl.se/ca/cacert.pem") + FileUtils.mkdir_p("lib/cert") + Net::HTTP.start(url.host, url.port, use_ssl: url.scheme == "https") do |http| + request = Net::HTTP::Get.new url + http.request request do |response| + open "lib/cert/cacert.pem.mozilla", "w" do |io| + response.read_body do |chunk| + io.write chunk + end end end end @@ -52,7 +55,9 @@ end task build: "build:download_cacert" -task default: ["build:download_cacert", :spec] +task spec: "build:download_cacert" + +task default: :spec RSpec::Core::RakeTask.new(:spec) RuboCop::RakeTask.new diff --git a/lib/tebako-runtime.rb b/lib/tebako-runtime.rb index 14fa21e..ae24ca7 100644 --- a/lib/tebako-runtime.rb +++ b/lib/tebako-runtime.rb @@ -37,6 +37,7 @@ # - an option to implement adapter 'AFTER' module TebakoRuntime PRE_REQUIRE_MAP = { + "excavate" => "tebako-runtime/pre/excavate", "seven_zip_ruby" => "tebako-runtime/pre/seven-zip" }.freeze @@ -79,10 +80,10 @@ def self.process_all(name) # 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 (inplib) reference to target tebako package that is + # is deployed with (implib) reference to target tebako package that is # not available at deploy time def self.process_pass_through(name) - if name == "ffi" && RUBY_PLATFORM =~ /msys|mingw|cygwin/ + 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 diff --git a/lib/tebako-runtime/memfs.rb b/lib/tebako-runtime/memfs.rb index 98f5d06..5235af1 100644 --- a/lib/tebako-runtime/memfs.rb +++ b/lib/tebako-runtime/memfs.rb @@ -35,7 +35,7 @@ # Module TebakoRuntime # Methods to extract files from memfs to temporary folder module TebakoRuntime - COMPILER_MEMFS = RUBY_PLATFORM =~ /msys|mingw|cygwin/ ? "A:/__tebako_memfs__" : "/__tebako_memfs__" + COMPILER_MEMFS = RUBY_PLATFORM =~ /mswin|mingw/ ? "A:/__tebako_memfs__" : "/__tebako_memfs__" COMPILER_MEMFS_LIB_CACHE = Pathname.new(Dir.mktmpdir("tebako-runtime-")) class << self diff --git a/lib/tebako-runtime/pre/excavate.rb b/lib/tebako-runtime/pre/excavate.rb new file mode 100644 index 0000000..aa60600 --- /dev/null +++ b/lib/tebako-runtime/pre/excavate.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +# Copyright (c) 2024 [Ribose Inc](https://www.ribose.com). +# All rights reserved. +# This file is a part of tebako +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +# For some reason on Windows an attempt to require "seven_zip_ruby" from excavate fails +# I cannot debug it effectively because of https://github.com/tamatebako/tebako/issues/119 + +require "seven_zip_ruby" diff --git a/lib/tebako-runtime/pre/seven-zip.rb b/lib/tebako-runtime/pre/seven-zip.rb index 9f1bad2..31b3e9d 100644 --- a/lib/tebako-runtime/pre/seven-zip.rb +++ b/lib/tebako-runtime/pre/seven-zip.rb @@ -32,10 +32,11 @@ module TebakoRuntime sevenz_lib = RUBY_PLATFORM.downcase.match(/mswin|mingw/) ? "7z*.dll" : "7z.so" sevenz_path = File.join(full_gem_path("seven-zip"), "lib", "seven_zip_ruby", sevenz_lib) + sevenz_paths = Dir.glob(sevenz_path) sevenz_new_folder = COMPILER_MEMFS_LIB_CACHE / "seven_zip_ruby" FileUtils.mkdir_p(sevenz_new_folder) - Dir.glob(sevenz_path).each do |file| + sevenz_paths.each do |file| FileUtils.cp(file, sevenz_new_folder) end - $LOAD_PATH.unshift(COMPILER_MEMFS_LIB_CACHE) + $LOAD_PATH.unshift(COMPILER_MEMFS_LIB_CACHE.to_s) end diff --git a/lib/tebako-runtime/version.rb b/lib/tebako-runtime/version.rb index 284bf36..f1bbc3b 100644 --- a/lib/tebako-runtime/version.rb +++ b/lib/tebako-runtime/version.rb @@ -26,5 +26,5 @@ # POSSIBILITY OF SUCH DAMAGE. module TebakoRuntime - VERSION = "0.5.0" + VERSION = "0.5.1" end diff --git a/spec/runtime_spec.rb b/spec/runtime_spec.rb index a10b879..3752c5c 100644 --- a/spec/runtime_spec.rb +++ b/spec/runtime_spec.rb @@ -29,6 +29,8 @@ # rubocop:disable Metrics/BlockLength RSpec.describe TebakoRuntime do + let(:tmpd) { tmpdir_name } + it "has a version number" do expect(TebakoRuntime::VERSION).not_to be nil end @@ -40,7 +42,6 @@ def tmpdir_name end it "extracts single file from memfs" do - tmpd = tmpdir_name test_file = File.join(__dir__, "fixtures", "files", "test1.file") expect(FileUtils).to receive(:cp_r).with([test_file], tmpd) @@ -48,8 +49,6 @@ def tmpdir_name end it "extracts files from memfs by wildcard" do - tmpd = tmpdir_name - test1_file = File.join(__dir__, "fixtures", "files", "test1.file") test2_file = File.join(__dir__, "fixtures", "files", "test2.file") test_files = File.join(__dir__, "fixtures", "files", "*.file") @@ -60,7 +59,6 @@ def tmpdir_name end it "returns unchanged reference to non-memfs file" do - tmpd = tmpdir_name expect(TebakoRuntime.extract_memfs("#{tmpd}/test.file")).to eq("#{tmpd}/test.file") end @@ -98,10 +96,11 @@ def tmpdir_name ref = TebakoRuntime.extract_memfs(File.join(TebakoRuntime::COMPILER_MEMFS, "test1.file"), cache_path: cache) expect(ref).to eq(File.join(cache, "test1.file")) + + FileUtils.remove_dir(cache, true) end it "returns unchanged reference to non-memfs file with quoted name" do - tmpd = tmpdir_name expect(TebakoRuntime.extract_memfs("\"#{tmpd}/test.file\"")).to eq("\"#{tmpd}/test.file\"") end @@ -182,16 +181,25 @@ def tmpdir_name end it "provides a pre-processor for seven-zip gem" do - sevenz_libs = RUBY_PLATFORM =~ /msys|mingw|cygwin/ ? ["7z.dll", "7z64.dll"] : ["7z.so"] + sevenz_libs = RUBY_PLATFORM =~ /mswin|mingw/ ? ["7z.dll", "7z64.dll"] : ["7z.so"] sevenz_libs.each do |sevenz_lib| sevenz_path = File.join(TebakoRuntime.full_gem_path("seven-zip"), "lib", "seven_zip_ruby", sevenz_lib).to_s sevenz_new_folder = TebakoRuntime::COMPILER_MEMFS_LIB_CACHE / "seven_zip_ruby" - expect(FileUtils).to receive(:cp).with(sevenz_path, sevenz_new_folder).and_call_original + expect(FileUtils).to receive(:cp) do |source, destination| + if RUBY_PLATFORM =~ /mswin|mingw/ + expect(source.casecmp(sevenz_path)).to eq(0) # Case-insensitive comparison for Windows + expect(destination.casecmp(sevenz_new_folder)).to eq(0) + else + expect(source).to eq(sevenz_path) # Case-sensitive comparison for other platforms + expect(destination).to eq(sevenz_new_folder) + end + end.and_call_original end + require "seven_zip_ruby" - expect($LOAD_PATH).to include(TebakoRuntime::COMPILER_MEMFS_LIB_CACHE) + expect($LOAD_PATH).to include(TebakoRuntime::COMPILER_MEMFS_LIB_CACHE.to_s) end end # rubocop:enable Metrics/BlockLength