From 7ced3f132abe0be53bd5148358e95fc2042026e0 Mon Sep 17 00:00:00 2001 From: Jordan Sissel Date: Sun, 6 Nov 2022 16:21:42 -0800 Subject: [PATCH] Add flag --rpm-with-source This flag allows a user to ask for an SRPM in addition to the binary rpm. This also adds fallback case if the file extension seems weird. That is, if someone asks for a package file named "foobar" then fpm will also output an SRPM named "foobar.src.rpm" in addition to the rpm file named "foobar" --- lib/fpm/package/rpm.rb | 54 ++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/lib/fpm/package/rpm.rb b/lib/fpm/package/rpm.rb index 379404aad3..d6406c04cd 100644 --- a/lib/fpm/package/rpm.rb +++ b/lib/fpm/package/rpm.rb @@ -122,6 +122,8 @@ class FPM::Package::RPM < FPM::Package next File.expand_path(file) end + option "--with-source", :flag, "Also output an SRPM.", :default => false + rpmbuild_filter_from_provides = [] option "--filter-from-provides", "REGEX", "Set %filter_from_provides to the supplied REGEX." do |filter_from_provides| @@ -578,29 +580,35 @@ def output(output_path) FileUtils.cp(rpmpath, output_path) end - # Copy out the SRPM packages - ::Dir["#{build_path}/SRPMS/**/*.rpm"].each do |rpmpath| - # Try to use the same naming scheme if we are specifying a custom output path? - # Replace the .ARCH.EXTENSION with .src.EXTENSION ? - # - # For example, if the output wanted "foo.noarch.rpm" - # then the srpm should be named "foo.src.rpm" - # - # But for the cases where someone asked for a file with just ".rpm" at the end, - # we can also write the srpm as ".src.rpm" - extension_checks = [ - # Try ..rpm ending - Regexp.compile(to_s(".ARCH.EXTENSION$")), - # Try just .rpm ending - Regexp.compile(to_s(".EXTENSION$")) - ] - - extension_checks.each do |re| - if output_path =~ re - filename = File.basename(output_path).gsub(re, to_s(".src.EXTENSION")) - p [ "Copying", rpmpath => filename ] - FileUtils.cp(rpmpath, File.join(File.dirname(output_path), filename)) - break + if attributes[:rpm_with_source?] + # Copy out the SRPM packages + ::Dir["#{build_path}/SRPMS/**/*.rpm"].each do |rpmpath| + # Try to use the same naming scheme if we are specifying a custom output path? + # Replace the .ARCH.EXTENSION with .src.EXTENSION ? + # + # For example, if the output wanted "foo.noarch.rpm" + # then the srpm should be named "foo.src.rpm" + # + # But for the cases where someone asked for a file with just ".rpm" at the end, + # we can also write the srpm as ".src.rpm" + extension_checks = [ + # Try ..rpm ending + Regexp.compile(to_s(".ARCH.EXTENSION$")), + # Try just .rpm ending + Regexp.compile(to_s(".EXTENSION$")), + + # Last effort to just append `.src.rpm` to the end of the filename + /$/ + ] + + extension_checks.each do |re| + if output_path =~ re + filename = File.basename(output_path).gsub(re, to_s(".src.EXTENSION")) + outpath = File.join(File.dirname(output_path), filename) + logger.log("Created SRPM", :path => outpath) + FileUtils.cp(rpmpath, outpath) + break + end end end end