Skip to content

Commit

Permalink
deb: add a --compression-level option
Browse files Browse the repository at this point in the history
  • Loading branch information
chouquette committed Nov 24, 2023
1 parent b085edc commit 49093c3
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions lib/fpm/package/deb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ class FPM::Package::Deb < FPM::Package
value
end

option "--compression-level", "[0-9]", "Select a compression level. 0 is none or minimal. 9 is max compression.",
# Specify which compression level to use on the compressor backend, when building a package
:default => nil do |value|
valint = value.to_i
# if self.attributes[:deb_compression].nil?
# raise "Can't specify a compression level with compression disabled"
# end
unless value =~ /^\d$/ && valint >= 0 && valint <= 9
raise "Invalid compression level '#{value}'. Valid values are integers between 0 and 9 inclusive."
end
valint
end

option "--dist", "DIST-TAG", "Set the deb distribution.", :default => "unstable"

# Take care about the case when we want custom control file but still use fpm ...
Expand Down Expand Up @@ -642,18 +655,24 @@ def output(output_path)
datatar = build_path("data.tar.gz")
controltar = build_path("control.tar.gz")
compression_flags = ["-z"]
# gnu tar obeys GZIP environment variable with options for gzip; -n = forget original filename and date
compressor_options = {"GZIP" => "-#{self.attributes[:deb_compression_level] || 9}" +
"#{'n' if tar_cmd_supports_sort_names_and_set_mtime? and not attributes[:source_date_epoch].nil?}"}
when "bzip2"
datatar = build_path("data.tar.bz2")
controltar = build_path("control.tar.gz")
compression_flags = ["-j"]
compressor_options = {"BZIP" => "-#{self.attributes[:deb_compression_level] || 9}"}
when "xz"
datatar = build_path("data.tar.xz")
controltar = build_path("control.tar.xz")
compression_flags = ["-J"]
compressor_options = {"XZ_OPT" => "-#{self.attributes[:deb_compression_level] || 3}"}
when "none"
datatar = build_path("data.tar")
controltar = build_path("control.tar")
compression_flags = []
compressor_options = {}
else
raise FPM::InvalidPackageConfiguration,
"Unknown compression type '#{self.attributes[:deb_compression]}'"
Expand All @@ -662,9 +681,8 @@ def output(output_path)
if tar_cmd_supports_sort_names_and_set_mtime? and not attributes[:source_date_epoch].nil?
# Use gnu tar options to force deterministic file order and timestamp
args += ["--sort=name", ("--mtime=@%s" % attributes[:source_date_epoch])]
# gnu tar obeys GZIP environment variable with options for gzip; -n = forget original filename and date
args.unshift({"GZIP" => "-9n"})
end
args.unshift(compressor_options)
safesystem(*args)

# pack up the .deb, which is just an 'ar' archive with 3 files
Expand Down Expand Up @@ -721,7 +739,7 @@ def converted_from(origin)
else
# Also replace '::' in the perl module name with '-'
modulename = m["name"].gsub("::", "-")

# Fix any upper-casing or other naming concerns Debian has about packages
name = "#{attributes[:cpan_package_name_prefix]}-#{modulename}"

Expand Down Expand Up @@ -934,12 +952,17 @@ def write_control_tarball
when "gz", "bzip2", nil
controltar = "control.tar.gz"
compression_flags = ["-z"]
# gnu tar obeys GZIP environment variable with options for gzip; -n = forget original filename and date
compressor_options = {"GZIP" => "-#{self.attributes[:deb_compression_level] || 9}" +
"#{'n' if tar_cmd_supports_sort_names_and_set_mtime? and not attributes[:source_date_epoch].nil?}"}
when "xz"
controltar = "control.tar.xz"
compression_flags = ["-J"]
compressor_options = {"XZ_OPT" => "-#{self.attributes[:deb_compression_level] || 3}"}
when "none"
controltar = "control.tar"
compression_flags = []
compressor_options = {}
else
raise FPM::InvalidPackageConfiguration,
"Unknown compression type '#{self.attributes[:deb_compression]}'"
Expand All @@ -954,9 +977,8 @@ def write_control_tarball
if tar_cmd_supports_sort_names_and_set_mtime? and not attributes[:source_date_epoch].nil?
# Force deterministic file order and timestamp
args += ["--sort=name", ("--mtime=@%s" % attributes[:source_date_epoch])]
# gnu tar obeys GZIP environment variable with options for gzip; -n = forget original filename and date
args.unshift({"GZIP" => "-9n"})
end
args.unshift(compressor_options)
safesystem(*args)
end

Expand Down

0 comments on commit 49093c3

Please sign in to comment.