Skip to content

Commit

Permalink
FreeBSD package: Replace ruby-xz usage with alternative using tar
Browse files Browse the repository at this point in the history
For #1795

This replaces another library which uses ffi with an implementation
that doesn't need ffi.

I am not certain this is an exact replacement, but for my casual tests,
comparing .txz files generated before/after this commit, things seem ok.
This would benefit from real freebsd testing, though.
  • Loading branch information
jordansissel committed Jun 19, 2021
1 parent 3965a0f commit ab4eb18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
3 changes: 0 additions & 3 deletions fpm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ Gem::Specification.new do |spec|

spec.add_development_dependency("rake", "~> 10") # license: MIT

# For creating FreeBSD package archives (xz-compressed tars)
spec.add_dependency("ruby-xz", "~> 0.2.3") # license: MIT

# For sourcing from pleaserun
spec.add_dependency("pleaserun", "~> 0.0.29") # license: Apache 2

Expand Down
31 changes: 12 additions & 19 deletions lib/fpm/package/freebsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class FPM::Package::FreeBSD < FPM::Package
:default => "fpm/<name>"

def output(output_path)
# See https://github.com/jordansissel/fpm/issues/1090
# require xz later, because this triggers a load of liblzma.so.5 that is
# unavailable on older CentOS/RH distros.
require "xz"
output_check(output_path)

# Build the packaging metadata files.
Expand Down Expand Up @@ -80,22 +76,19 @@ def output(output_path)
file.write(pkgdata.to_json + "\n")
end

# Create the .txz package archive from the files in staging_path.
File.open(output_path, "wb") do |file|
XZ::StreamWriter.new(file) do |xz|
FPM::Util::TarWriter.new(xz) do |tar|
# The manifests must come first for pkg.
add_path(tar, "+COMPACT_MANIFEST",
File.join(staging_path, "+COMPACT_MANIFEST"))
add_path(tar, "+MANIFEST",
File.join(staging_path, "+MANIFEST"))

checksums.keys.each do |path|
add_path(tar, "/" + path, File.join(staging_path, path))
end
end
end
file_list = File.new(build_path("file_list"), "w")
files.each do |i|
file_list.puts(i)
end
file_list.close

# Create the .txz package archive from the files in staging_path.
# We use --files-from here to keep the tar entries from having `./` as the prefix.
# This is done as a best effor to mimic what FreeBSD packages do, having everything at the top-level as
# file names, like "+MANIFEST" instead of "./+MANIFEST"
# Note: This will include top-level files like "/usr/bin/foo" listed in the tar as "usr/bin/fo" without
# a leading slash. I don't know if this has any negative impact on freebsd packages.
safesystem("tar", "-Jcf", output_path, "-C", staging_path, "--files-from", build_path("file_list"))
end # def output

# Handle architecture naming conversion:
Expand Down

0 comments on commit ab4eb18

Please sign in to comment.