From e0edc7e55910d201f16ed40377562342c63ebcbd Mon Sep 17 00:00:00 2001 From: SaltwaterC Date: Fri, 28 Apr 2023 20:25:00 +0100 Subject: [PATCH 1/8] Add support for zstd compression for deb packages. --- lib/fpm/package/deb.rb | 19 ++++++++++++++++--- spec/fpm/package/deb_spec.rb | 5 +++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/fpm/package/deb.rb b/lib/fpm/package/deb.rb index 4d97dfb0cc..9ea3e300ab 100644 --- a/lib/fpm/package/deb.rb +++ b/lib/fpm/package/deb.rb @@ -27,7 +27,7 @@ class FPM::Package::Deb < FPM::Package } unless defined?(SCRIPT_MAP) # The list of supported compression types. Default is gz (gzip) - COMPRESSION_TYPES = [ "gz", "bzip2", "xz", "none" ] + COMPRESSION_TYPES = [ "gz", "bzip2", "xz", "zst", "none" ] # https://www.debian.org/doc/debian-policy/ch-relationships.html#syntax-of-relationship-fields # Example value with version relationship: libc6 (>= 2.2.1) @@ -332,6 +332,9 @@ def extract_info(package) when "xz" controltar = "control.tar.xz" compression = "-J" + when "zst" + controltar = "control.tar.zst" + compression = "-I zstd" when 'tar' controltar = "control.tar" compression = "" @@ -344,7 +347,7 @@ def extract_info(package) build_path("control").tap do |path| FileUtils.mkdir(path) if !File.directory?(path) - # unpack the control.tar.{,gz,bz2,xz} from the deb package into staging_path + # unpack the control.tar.{,gz,bz2,xz,zst} from the deb package into staging_path # Unpack the control tarball safesystem(ar_cmd[0] + " p #{package} #{controltar} | tar #{compression} -xf - -C #{path}") @@ -454,6 +457,9 @@ def extract_files(package) when "xz" datatar = "data.tar.xz" compression = "-J" + when "zst" + datatar = "data.tar.zst" + compression = "-I zstd" when 'tar' datatar = "data.tar" compression = "" @@ -650,6 +656,10 @@ def output(output_path) datatar = build_path("data.tar.xz") controltar = build_path("control.tar.xz") compression_flags = ["-J"] + when "zst" + datatar = build_path("data.tar.zst") + controltar = build_path("control.tar.zst") + compression_flags = ["-I zstd"] when "none" datatar = build_path("data.tar") controltar = build_path("control.tar") @@ -721,7 +731,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}" @@ -937,6 +947,9 @@ def write_control_tarball when "xz" controltar = "control.tar.xz" compression_flags = ["-J"] + when "zst" + controltar = "control.tar.zst" + compression_flags = ["-I zstd"] when "none" controltar = "control.tar" compression_flags = [] diff --git a/spec/fpm/package/deb_spec.rb b/spec/fpm/package/deb_spec.rb index 5334bb5d9d..687dedf924 100644 --- a/spec/fpm/package/deb_spec.rb +++ b/spec/fpm/package/deb_spec.rb @@ -413,7 +413,7 @@ def dpkg_field(field) context "when run against lintian" do before do - skip("Missing lintian program") unless have_lintian + skip("Missing lintian program") unless have_lintian end lintian_errors_to_ignore = [ @@ -535,7 +535,8 @@ def dpkg_field(field) { "bzip2" => "bz2", "xz" => "xz", - "gz" => "gz" + "gz" => "gz", + "zst" => "zst" }.each do |flag,suffix| context "when --deb-compression is #{flag}" do let(:target) { Stud::Temporary.pathname + ".deb" } From bf0aa55655a1796b8d010c990a10dea353adf195 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Thu, 8 Aug 2024 06:07:24 -0700 Subject: [PATCH 2/8] build proper freebsd package --- docs/cli-reference.rst | 6 ++++++ docs/contributing.rst | 7 ++++++- docs/packages/cli/freebsd.rst | 2 ++ lib/fpm/package/freebsd.rb | 34 +++++++++++++++++++++++----------- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/docs/cli-reference.rst b/docs/cli-reference.rst index 744bfe9b21..fd9676ad51 100644 --- a/docs/cli-reference.rst +++ b/docs/cli-reference.rst @@ -246,6 +246,9 @@ General Options * ``--freebsd-origin ABI`` - (freebsd only) Sets the FreeBSD 'origin' pkg field +* ``--freebsd-osversion VERSION`` + - (freebsd only) Sets the FreeBSD 'version' pkg field, ie. 12 or 13, use '*' for all. + * ``--gem-bin-path DIRECTORY`` - (gem only) The directory to install gem executables @@ -766,6 +769,9 @@ freebsd * ``--freebsd-origin ABI`` - Sets the FreeBSD 'origin' pkg field +* ``--freebsd-osversion VERSION`` + - Sets the FreeBSD 'version' pkg field, ie. 12 or 13, use '*' for all. + gem --- diff --git a/docs/contributing.rst b/docs/contributing.rst index 2f2390f420..3ab6b740a4 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -56,10 +56,15 @@ when it lists the FPM gem: If your system doesn't have `bsdtar` by default, make sure to install it or some tests will fail: - apt-get install bsdtar + apt-get install bsdtar || apt install libarchive-tools yum install bsdtar + +You also need these tools: + + apt-get install lintian cpanminus + Next, run make in root of the FPM repo. If there are any problems (such as missing dependencies) you should receive an error diff --git a/docs/packages/cli/freebsd.rst b/docs/packages/cli/freebsd.rst index 3f16a015e8..017872feb2 100644 --- a/docs/packages/cli/freebsd.rst +++ b/docs/packages/cli/freebsd.rst @@ -1,3 +1,5 @@ * ``--freebsd-origin ABI`` - Sets the FreeBSD 'origin' pkg field +* ``--freebsd-osversion VERSION`` + - Sets the FreeBSD 'version' pkg field, ie. 12 or 13, use '*' for all. diff --git a/lib/fpm/package/freebsd.rb b/lib/fpm/package/freebsd.rb index 42d3df9823..2aab74be4b 100644 --- a/lib/fpm/package/freebsd.rb +++ b/lib/fpm/package/freebsd.rb @@ -16,6 +16,10 @@ class FPM::Package::FreeBSD < FPM::Package "Sets the FreeBSD 'origin' pkg field", :default => "fpm/" + option "--osversion", "VERSION", + "Sets the FreeBSD 'version' pkg field, ie 12 or 13, use '*' for all.", + :default => "13" + def output(output_path) output_check(output_path) @@ -90,28 +94,36 @@ def output(output_path) end # def output # Handle architecture naming conversion: - # :::[.other] + # :: def architecture - osname = %x{uname -s}.chomp - osversion = %x{uname -r}.chomp.split('.').first - - # Essentially because no testing on other platforms - arch = 'x86' + osname = 'FreeBSD' - wordsize = case @architecture + arch = case @architecture when nil, 'native' %x{getconf LONG_BIT}.chomp # 'native' is current arch when 'arm64' - '64' + 'arm64' + when 'aarch64' + 'arm64' when 'amd64' - '64' + 'amd64' + when 'x86_64' + 'amd64' when 'i386' - '32' + 'i386' + when 'i686' + 'i386' + when 'any' + '*' + when 'all' + '*' + when 'noarch' + '*' else %x{getconf LONG_BIT}.chomp # default to native, the current arch end - return [osname, osversion, arch, wordsize].join(':') + return [osname, attributes[:freebsd_osversion], arch].join(':') end def add_path(tar, tar_path, path) From 6957220642629a13704d4a58054f72211da33d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phillipp=20R=C3=B6ll?= Date: Mon, 12 Aug 2024 14:47:47 +0200 Subject: [PATCH 3/8] Add support for .timer units to --deb-systemd Before the change, when using an option --deb-systemd myunit.timer, the actual file created would be /lib/systemd/system/myunit.timer.service Because of that, systemd would then not find the timer. With this change, the correct extension is extracted from the file, defaulting to .service. Typically, there would be two files for installing a timer: --deb-systemd myunit.service (where .service could be omitted) and --deb-systemd myunit.timer So that the .timer references a .service file. --- lib/fpm/package/deb.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/fpm/package/deb.rb b/lib/fpm/package/deb.rb index 4d97dfb0cc..9f2a135fb4 100644 --- a/lib/fpm/package/deb.rb +++ b/lib/fpm/package/deb.rb @@ -517,14 +517,23 @@ def output(output_path) attributes[:deb_systemd] = [] attributes.fetch(:deb_systemd_list, []).each do |systemd| - name = File.basename(systemd, ".service") - dest_systemd = staging_path("lib/systemd/system/#{name}.service") + name = File.basename(systemd) + extname = File.extname(name) + + name_with_extension = if extname.empty? + "#{name}.service" + elsif [".service", ".timer"].include?(extname) + name + else + raise ArgumentError, "Invalid systemd unit file extension: #{extname}. Expected .service or .timer, or no extension." + end + + dest_systemd = staging_path("lib/systemd/system/#{name_with_extension}") mkdir_p(File.dirname(dest_systemd)) FileUtils.cp(systemd, dest_systemd) File.chmod(0644, dest_systemd) - # add systemd service name to attribute - attributes[:deb_systemd] << name + attributes[:deb_systemd] << name_with_extension end if script?(:before_upgrade) or script?(:after_upgrade) or attributes[:deb_systemd].any? @@ -627,8 +636,11 @@ def output(output_path) end attributes.fetch(:deb_systemd_list, []).each do |systemd| - name = File.basename(systemd, ".service") - dest_systemd = staging_path("lib/systemd/system/#{name}.service") + name = File.basename(systemd) + extname = File.extname(systemd) + name_with_extension = extname.empty? ? "#{name}.service" : name + + dest_systemd = staging_path("lib/systemd/system/#{name_with_extension}") mkdir_p(File.dirname(dest_systemd)) FileUtils.cp(systemd, dest_systemd) File.chmod(0644, dest_systemd) From 843c729b166f4ed26080b27a0f2829b55672310d Mon Sep 17 00:00:00 2001 From: Jordan Sissel Date: Thu, 12 Sep 2024 10:39:55 -0700 Subject: [PATCH 4/8] Configuration errors should raise a specific exception Raising FPM::InvalidPackageConfiguration will allow the fpm command-line to print an error message and exit non-zero. Raising other exceptions will often produce a crash-like behavior which prints the exception and a stack trace. Stack traces are not helpful content in situations where a user has made a configuration error. --- lib/fpm/package/deb.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/fpm/package/deb.rb b/lib/fpm/package/deb.rb index 9f2a135fb4..ba8975e798 100644 --- a/lib/fpm/package/deb.rb +++ b/lib/fpm/package/deb.rb @@ -73,7 +73,7 @@ class FPM::Package::Deb < FPM::Package option "--compression", "COMPRESSION", "The compression type to use, must " \ "be one of #{COMPRESSION_TYPES.join(", ")}.", :default => "gz" do |value| if !COMPRESSION_TYPES.include?(value) - raise ArgumentError, "deb compression value of '#{value}' is invalid. " \ + raise FPM::InvalidPackageConfiguration, "deb compression value of '#{value}' is invalid. " \ "Must be one of #{COMPRESSION_TYPES.join(", ")}" end value @@ -364,7 +364,7 @@ def extract_info(package) version_re = /^(?:([0-9]+):)?(.+?)(?:-(.*))?$/ m = version_re.match(parse.call("Version")) if !m - raise "Unsupported version string '#{parse.call("Version")}'" + raise FPM::InvalidPackageConfiguration, "Unsupported version string '#{parse.call("Version")}'" end self.epoch, self.version, self.iteration = m.captures @@ -504,15 +504,15 @@ def output(output_path) end if attributes[:source_date_epoch] == "0" logger.error("Alas, ruby's Zlib::GzipWriter does not support setting an mtime of zero. Aborting.") - raise "#{name}: source_date_epoch of 0 not supported." + raise FPM::InvalidPackageConfiguration, "#{name}: source_date_epoch of 0 not supported." end if not attributes[:source_date_epoch].nil? and not ar_cmd_deterministic? logger.error("Alas, could not find an ar that can handle -D option. Try installing recent gnu binutils. Aborting.") - raise "#{name}: ar is insufficient to support source_date_epoch." + raise FPM::InvalidPackageConfiguration, "#{name}: ar is insufficient to support source_date_epoch." end if not attributes[:source_date_epoch].nil? and not tar_cmd_supports_sort_names_and_set_mtime? logger.error("Alas, could not find a tar that can set mtime and sort. Try installing recent gnu tar. Aborting.") - raise "#{name}: tar is insufficient to support source_date_epoch." + raise FPM::InvalidPackageConfiguration, "#{name}: tar is insufficient to support source_date_epoch." end attributes[:deb_systemd] = [] @@ -525,7 +525,7 @@ def output(output_path) elsif [".service", ".timer"].include?(extname) name else - raise ArgumentError, "Invalid systemd unit file extension: #{extname}. Expected .service or .timer, or no extension." + raise FPM::InvalidPackageConfiguration, "Invalid systemd unit file extension: #{extname}. Expected .service or .timer, or no extension." end dest_systemd = staging_path("lib/systemd/system/#{name_with_extension}") From e94f56c01ec7eedaa767345c05bc0560a4c38864 Mon Sep 17 00:00:00 2001 From: Jordan Sissel Date: Thu, 12 Sep 2024 10:48:55 -0700 Subject: [PATCH 5/8] Flag errors should use FPM::Package::InvalidArgument --- lib/fpm/package/deb.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fpm/package/deb.rb b/lib/fpm/package/deb.rb index ba8975e798..0d536528f1 100644 --- a/lib/fpm/package/deb.rb +++ b/lib/fpm/package/deb.rb @@ -73,7 +73,7 @@ class FPM::Package::Deb < FPM::Package option "--compression", "COMPRESSION", "The compression type to use, must " \ "be one of #{COMPRESSION_TYPES.join(", ")}.", :default => "gz" do |value| if !COMPRESSION_TYPES.include?(value) - raise FPM::InvalidPackageConfiguration, "deb compression value of '#{value}' is invalid. " \ + raise FPM::Package::InvalidArgument, "deb compression value of '#{value}' is invalid. " \ "Must be one of #{COMPRESSION_TYPES.join(", ")}" end value From 790f53c766ff9f8ac507fc7221afcabfbc07537d Mon Sep 17 00:00:00 2001 From: Matt Ezell Date: Mon, 23 Sep 2024 10:33:57 -0400 Subject: [PATCH 6/8] Support pip download returning a zip file Signed-off-by: Matt Ezell --- lib/fpm/package/python.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/fpm/package/python.rb b/lib/fpm/package/python.rb index 5754a053d4..7e0dfac1d3 100644 --- a/lib/fpm/package/python.rb +++ b/lib/fpm/package/python.rb @@ -171,13 +171,19 @@ def download_if_necessary(package, version=nil) # behind a directory with the Python package extracted and ready to be used. # For example, `pip download ... Django` puts `Django-4.0.4.tar.tz` into the build_path directory. # If we expect `pip` to leave an unknown-named file in the `build_path` directory, let's check for - # a single file and unpack it. I don't know if it will /always/ be a .tar.gz though. - files = ::Dir.glob(File.join(build_path, "*.tar.gz")) + # a single file and unpack it. + files = ::Dir.glob(File.join(build_path, "*.{tar.gz,zip}")) if files.length != 1 raise "Unexpected directory layout after `pip download ...`. This might be an fpm bug? The directory is #{build_path}" end - safesystem("tar", "-zxf", files[0], "-C", target) + if files[0].end_with?("tar.gz") + safesystem("tar", "-zxf", files[0], "-C", target) + elsif files[0].end_with?("zip") + safesystem("unzip", files[0], "-d", target) + else + raise "Unexpected file format after `pip download ...`. This might be an fpm bug? The file is #{files[0]}" + end else # no pip, use easy_install logger.debug("no pip, defaulting to easy_install", :easy_install => attributes[:python_easyinstall]) From b852c59b02e49483f5f11f2a738cdaebdc88af13 Mon Sep 17 00:00:00 2001 From: Wayne Heaney <42350981+wheaney@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:45:47 -0700 Subject: [PATCH 7/8] Update rpm.rb Fix how buildroot is specified to better conform with the rpmbuild CLI. The old way was failing with `File not found` errors. --- lib/fpm/package/rpm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fpm/package/rpm.rb b/lib/fpm/package/rpm.rb index a925256561..33242785de 100644 --- a/lib/fpm/package/rpm.rb +++ b/lib/fpm/package/rpm.rb @@ -473,7 +473,7 @@ def output(output_path) args += ["--define", "dist .#{attributes[:rpm_dist]}"] if attributes[:rpm_dist] args += [ - "--define", "buildroot #{build_path}/BUILD", + "--buildroot", "#{build_path}/BUILD", "--define", "_topdir #{build_path}", "--define", "_sourcedir #{build_path}", "--define", "_rpmdir #{build_path}/RPMS", From 0fb0d2615200176adafb1d38354462228022e5b3 Mon Sep 17 00:00:00 2001 From: Wayne Heaney <42350981+wheaney@users.noreply.github.com> Date: Mon, 4 Nov 2024 22:02:31 -0800 Subject: [PATCH 8/8] Update rpm.rb Leave old `--define` argument in place for `buildroot` --- lib/fpm/package/rpm.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/fpm/package/rpm.rb b/lib/fpm/package/rpm.rb index 33242785de..861568bc06 100644 --- a/lib/fpm/package/rpm.rb +++ b/lib/fpm/package/rpm.rb @@ -474,6 +474,7 @@ def output(output_path) args += [ "--buildroot", "#{build_path}/BUILD", + "--define", "buildroot #{build_path}/BUILD", "--define", "_topdir #{build_path}", "--define", "_sourcedir #{build_path}", "--define", "_rpmdir #{build_path}/RPMS",