Skip to content

Commit f3c0658

Browse files
authored
Merge pull request #36 from fontist/rt-update-zlib-132
feat: use zlib 1.3.2, 1.3.1 is no longer available
2 parents d54148d + 47ec05a commit f3c0658

6 files changed

Lines changed: 196 additions & 10 deletions

File tree

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
# Test script to verify the installed ffi-libarchive-binary gem works correctly.
5+
# This script runs AFTER installing the gem via `gem install`,
6+
# NOT from the source directory.
7+
#
8+
# Usage:
9+
# SPEC_EXAMPLES_PATH=/path/to/spec/examples ruby test_installed_gem.rb
10+
11+
require "tempfile"
12+
require "fileutils"
13+
14+
def windows?
15+
RbConfig::CONFIG["host_os"] =~ /mswin|mingw|cygwin/
16+
end
17+
18+
# Path to spec/examples directory
19+
# Can be overridden via SPEC_EXAMPLES_PATH environment variable
20+
SPEC_EXAMPLES = ENV.fetch("SPEC_EXAMPLES_PATH") do
21+
# Default: relative to this script (works when script is in .github/scripts/)
22+
File.expand_path("../../spec/examples", __dir__)
23+
end
24+
25+
# Test 1: Verify the gem can be loaded
26+
puts "Test 1: Loading ffi-libarchive-binary..."
27+
begin
28+
require "ffi-libarchive-binary"
29+
puts " PASS: ffi-libarchive-binary loaded successfully"
30+
rescue LoadError => e
31+
puts " FAIL: Could not load ffi-libarchive-binary: #{e.message}"
32+
exit 1
33+
end
34+
35+
# Test 2: Verify libarchive library is accessible
36+
puts "Test 2: Checking library path..."
37+
lib_path = LibarchiveBinary.lib_path
38+
if File.exist?(lib_path)
39+
puts " PASS: Library found at #{lib_path}"
40+
else
41+
puts " FAIL: Library not found at #{lib_path}"
42+
puts " Contents of lib directory:"
43+
lib_dir = File.dirname(lib_path)
44+
Dir.glob("#{lib_dir}/*").each { |f| puts " - #{f}" } if Dir.exist?(lib_dir)
45+
exit 1
46+
end
47+
48+
# Test 3: Verify Archive module is functional
49+
puts "Test 3: Testing Archive module..."
50+
begin
51+
puts " Archive::EXTRACT_PERM = #{Archive::EXTRACT_PERM}"
52+
puts " PASS: Archive module is functional"
53+
rescue => e
54+
puts " FAIL: Archive module error: #{e.message}"
55+
exit 1
56+
end
57+
58+
# Test 4: Test archive extraction (7z self-extracting)
59+
puts "Test 4: Testing archive extraction..."
60+
test_archive = File.join(SPEC_EXAMPLES, "fonts_7z.exe")
61+
if File.exist?(test_archive)
62+
Dir.mktmpdir do |target|
63+
begin
64+
Dir.chdir(target) do
65+
flags = Archive::EXTRACT_PERM
66+
reader = Archive::Reader.open_filename(test_archive)
67+
68+
reader.each_entry do |entry|
69+
reader.extract(entry, flags.to_i)
70+
end
71+
72+
reader.close
73+
end
74+
75+
extracted_file = File.join(target, "Fonts", "Marlett.ttf")
76+
if File.exist?(extracted_file)
77+
puts " PASS: Archive extracted successfully, found #{extracted_file}"
78+
else
79+
puts " FAIL: Extraction did not create expected file #{extracted_file}"
80+
puts " Files created:"
81+
Dir.glob("#{target}/**/*").each { |f| puts " - #{f}" }
82+
exit 1
83+
end
84+
rescue => e
85+
puts " FAIL: Archive extraction error: #{e.message}"
86+
puts e.backtrace.first(5).join("\n")
87+
exit 1
88+
end
89+
end
90+
else
91+
puts " SKIP: Test archive not found at #{test_archive}"
92+
end
93+
94+
# Test 5: Test XAR/pkg extraction (non-Windows only)
95+
unless windows?
96+
puts "Test 5: Testing XAR/pkg extraction..."
97+
pkg_archive = File.join(SPEC_EXAMPLES, "archive.pkg")
98+
if File.exist?(pkg_archive)
99+
Dir.mktmpdir do |target|
100+
begin
101+
Dir.chdir(target) do
102+
flags = Archive::EXTRACT_PERM
103+
Archive.read_open_filename(pkg_archive) do |ar|
104+
ar.each_entry do |entry|
105+
ar.extract(entry, flags.to_i)
106+
end
107+
end
108+
end
109+
110+
payload = File.join(target, "Payload")
111+
if File.exist?(payload)
112+
puts " PASS: PKG extracted successfully, found #{payload}"
113+
else
114+
puts " FAIL: PKG extraction did not create expected Payload file"
115+
exit 1
116+
end
117+
rescue => e
118+
puts " FAIL: PKG extraction error: #{e.message}"
119+
puts e.backtrace.first(5).join("\n")
120+
exit 1
121+
end
122+
end
123+
else
124+
puts " SKIP: PKG archive not found at #{pkg_archive}"
125+
end
126+
end
127+
128+
puts ""
129+
puts "All tests passed!"
130+
exit 0

.github/workflows/gem-build.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ jobs:
8888
8989
- run: bundle exec rake gem:native:${{ matrix.platform }}
9090

91+
# Display compiled libraries for debugging
92+
- name: Inspect built libraries
93+
if: matrix.platform != 'any'
94+
shell: bash
95+
run: |
96+
echo "=== Platform: ${{ matrix.platform }} ==="
97+
echo "=== Compiled libraries ==="
98+
ls lib/ffi-libarchive-binary/*.dll lib/ffi-libarchive-binary/*.so lib/ffi-libarchive-binary/*.dylib 2>/dev/null || echo "No compiled libraries found"
99+
echo "=== Library directory contents ==="
100+
ls -la lib/ffi-libarchive-binary/ 2>/dev/null || echo "Directory not found"
101+
102+
# Unpack gem and display contents
103+
- name: Inspect gem contents
104+
shell: bash
105+
run: |
106+
cd pkg/
107+
gem unpack ffi-libarchive-binary-*.gem
108+
echo "=== Files in gem ==="
109+
ls -R */lib/ 2>/dev/null | head -50
110+
echo "=== Compiled libraries in gem ==="
111+
ls */lib/ffi-libarchive-binary/*.dll */lib/ffi-libarchive-binary/*.so */lib/ffi-libarchive-binary/*.dylib 2>/dev/null || echo "No compiled libraries found in gem"
112+
91113
- uses: actions/upload-artifact@v6
92114
if: failure()
93115
with:

.github/workflows/test.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,41 @@ jobs:
6060
matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
6161
steps:
6262
- uses: actions/checkout@v6
63+
with:
64+
# We need spec/examples for test archives and .github/scripts for test script
65+
sparse-checkout: |
66+
spec/examples
67+
.github/scripts
6368
6469
- uses: ruby/setup-ruby@v1
6570
with:
6671
ruby-version: ${{ matrix.ruby }}
6772
bundler: ${{ env.BUNDLER_VER }}
68-
bundler-cache: true
6973

74+
# Download the pre-built gem artifact (not just the binary)
7075
- uses: actions/download-artifact@v7
7176
with:
72-
name: lib-${{ github.run_number }}-${{ matrix.platform }}
73-
path: lib/ffi-libarchive-binary
77+
name: ${{ github.run_number }}-${{ matrix.platform }}-pkg
78+
path: pkg
79+
80+
# Unpack gem and display compiled libraries for debugging
81+
- name: Inspect gem contents
82+
shell: bash
83+
run: |
84+
cd pkg
85+
gem unpack ffi-libarchive-binary-*.gem
86+
echo "=== Platform: ${{ matrix.platform }} ==="
87+
echo "=== Compiled libraries in gem ==="
88+
ls */lib/ffi-libarchive-binary/*.dll */lib/ffi-libarchive-binary/*.so */lib/ffi-libarchive-binary/*.dylib 2>/dev/null || echo "No compiled libraries found in gem"
89+
echo "=== Full lib directory contents ==="
90+
ls -la */lib/ffi-libarchive-binary/ 2>/dev/null || echo "Directory not found"
91+
92+
# Install the native gem
93+
- name: Install native gem
94+
run: |
95+
cd pkg
96+
gem install ffi-libarchive-binary-*.gem
7497
75-
- run: bundle exec rspec
98+
# Run tests against the installed gem - actually extract archives!
99+
- name: Test installed gem
100+
run: ruby .github/scripts/test_installed_gem.rb

ext/configuration.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ libraries:
66
# - Other libraries use cross-platform versions under 'all'
77
zlib:
88
all:
9-
version: "1.3.1"
10-
url: "https://zlib.net/zlib-1.3.1.tar.gz"
11-
sha256: "9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23"
9+
version: "1.3.2"
10+
url: "https://zlib.net/zlib-1.3.2.tar.gz"
11+
sha256: "bb329a0a2cd0274d05519d61c667c062e06990d72e125ee2dfa8de64f0119d16"
1212
libexpat:
1313
all:
1414
version: "2.7.4"

lib/ffi-libarchive-binary.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ class Error < StandardError; end
99
LIBRARY_PATH = Pathname.new(File.join(__dir__, "ffi-libarchive-binary"))
1010

1111
def self.lib_path
12-
LIBRARY_PATH.join(lib_filename).to_s
12+
path = LIBRARY_PATH.join(lib_filename).to_s
13+
unless File.exist?(path)
14+
# Provide helpful debugging output for library loading failures
15+
if LIBRARY_PATH.exist?
16+
files = Dir.glob("#{LIBRARY_PATH}/*").map { |f| File.basename(f) }
17+
raise Error, "Library not found at #{path}. Files in directory: #{files.join(', ')}"
18+
else
19+
raise Error, "Library directory does not exist: #{LIBRARY_PATH}"
20+
end
21+
end
22+
path
1323
end
1424

1525
def self.lib_filename

lib/ffi-libarchive-binary/libarchive_recipe.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ def checkpoint
122122
def install
123123
super
124124

125-
libs = Dir.glob(File.join(port_path, "{lib,bin}", "*"))
126-
.grep(/\/(?:lib)?[a-zA-Z0-9\-]+\.(?:so|dylib|dll)$/)
125+
libs = Dir.glob(File.join(port_path, "{lib,bin}", "*.{so,dylib,dll,DLL}"))
127126
FileUtils.cp_r(libs, lib_workpath, verbose: true)
128127
if lib_fullpath.nil?
129128
message("Cannot guess libarchive library name, skipping format verification")

0 commit comments

Comments
 (0)