Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deb: add a --compression-level option #2036

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 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 @@ -666,22 +679,29 @@ 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 "zst"
datatar = build_path("data.tar.zst")
controltar = build_path("control.tar.zst")
compression_flags = ["-I zstd"]
compressor_options = {"ZSTD_CLEVEL", "-#{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 @@ -690,9 +710,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 @@ -962,15 +981,21 @@ 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 "zst"
controltar = "control.tar.zst"
compression_flags = ["-I zstd"]
compressor_options = {"ZSTD_CLEVEL", "-#{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 @@ -985,9 +1010,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
Loading