From 55528b75280e804d3ddbabdf9f246fde908f5f11 Mon Sep 17 00:00:00 2001 From: Maxim Samsonov Date: Wed, 19 Jun 2024 21:01:09 +0300 Subject: [PATCH 1/2] Fixed tests on Windows --- Rakefile | 4 +++- lib/tebako-runtime.rb | 2 +- lib/tebako-runtime/pre/seven-zip.rb | 4 +++- lib/tebako-runtime/version.rb | 2 +- spec/runtime_spec.rb | 13 +++++++++++-- tebako-runtime.gemspec | 1 + 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index 0834bca..887f89c 100644 --- a/Rakefile +++ b/Rakefile @@ -52,7 +52,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..f073f92 100644 --- a/lib/tebako-runtime.rb +++ b/lib/tebako-runtime.rb @@ -54,7 +54,7 @@ def self.full_gem_path(gem) end def self.log_enabled - @log_enabled ||= false + @log_enabled ||= true end def self.process(name, map, title) diff --git a/lib/tebako-runtime/pre/seven-zip.rb b/lib/tebako-runtime/pre/seven-zip.rb index 9f1bad2..c994161 100644 --- a/lib/tebako-runtime/pre/seven-zip.rb +++ b/lib/tebako-runtime/pre/seven-zip.rb @@ -32,9 +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| + puts "#{file} ==> #{sevenz_new_folder}" FileUtils.cp(file, sevenz_new_folder) end $LOAD_PATH.unshift(COMPILER_MEMFS_LIB_CACHE) 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..d2cb75c 100644 --- a/spec/runtime_spec.rb +++ b/spec/runtime_spec.rb @@ -187,9 +187,18 @@ def tmpdir_name 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 =~ /msys|mingw|cygwin/ + 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" + + require "excavate" expect($LOAD_PATH).to include(TebakoRuntime::COMPILER_MEMFS_LIB_CACHE) end diff --git a/tebako-runtime.gemspec b/tebako-runtime.gemspec index e91e389..03ef0ac 100644 --- a/tebako-runtime.gemspec +++ b/tebako-runtime.gemspec @@ -60,6 +60,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rubocop-rspec", "~> 2.23" spec.add_development_dependency "rubocop-rubycw", "~> 0.1" + spec.add_development_dependency "excavate", "~> 0.3" spec.add_development_dependency "ffi", "~> 1.15" spec.add_development_dependency "mn2pdf", "~> 1.79" spec.add_development_dependency "mnconvert", "~> 1.54" From 609ec4f25d51835f270ac84e46ba4f94b1187c69 Mon Sep 17 00:00:00 2001 From: Maxim Samsonov Date: Sat, 22 Jun 2024 11:27:48 +0300 Subject: [PATCH 2/2] Additional adapter for excavate gem (this is a workaround, pending https://github.com/tamatebako/tebako/issues/119) --- Rakefile | 19 ++++++++++-------- lib/tebako-runtime.rb | 7 ++++--- lib/tebako-runtime/memfs.rb | 2 +- lib/tebako-runtime/pre/excavate.rb | 31 +++++++++++++++++++++++++++++ lib/tebako-runtime/pre/seven-zip.rb | 3 +-- spec/runtime_spec.rb | 17 ++++++++-------- tebako-runtime.gemspec | 1 - 7 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 lib/tebako-runtime/pre/excavate.rb diff --git a/Rakefile b/Rakefile index 887f89c..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 diff --git a/lib/tebako-runtime.rb b/lib/tebako-runtime.rb index f073f92..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 @@ -54,7 +55,7 @@ def self.full_gem_path(gem) end def self.log_enabled - @log_enabled ||= true + @log_enabled ||= false end def self.process(name, map, title) @@ -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 c994161..31b3e9d 100644 --- a/lib/tebako-runtime/pre/seven-zip.rb +++ b/lib/tebako-runtime/pre/seven-zip.rb @@ -36,8 +36,7 @@ module TebakoRuntime sevenz_new_folder = COMPILER_MEMFS_LIB_CACHE / "seven_zip_ruby" FileUtils.mkdir_p(sevenz_new_folder) sevenz_paths.each do |file| - puts "#{file} ==> #{sevenz_new_folder}" 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/spec/runtime_spec.rb b/spec/runtime_spec.rb index d2cb75c..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,13 +181,13 @@ 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) do |source, destination| - if RUBY_PLATFORM =~ /msys|mingw|cygwin/ + 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 @@ -198,9 +197,9 @@ def tmpdir_name end.and_call_original end - require "excavate" + 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 diff --git a/tebako-runtime.gemspec b/tebako-runtime.gemspec index 03ef0ac..e91e389 100644 --- a/tebako-runtime.gemspec +++ b/tebako-runtime.gemspec @@ -60,7 +60,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rubocop-rspec", "~> 2.23" spec.add_development_dependency "rubocop-rubycw", "~> 0.1" - spec.add_development_dependency "excavate", "~> 0.3" spec.add_development_dependency "ffi", "~> 1.15" spec.add_development_dependency "mn2pdf", "~> 1.79" spec.add_development_dependency "mnconvert", "~> 1.54"