Skip to content

Commit

Permalink
Add flag --rpm-with-source
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
jordansissel committed Nov 7, 2022
1 parent d1a9ef6 commit 7ced3f1
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions lib/fpm/package/rpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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 .<arch>.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 .<arch>.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
Expand Down

0 comments on commit 7ced3f1

Please sign in to comment.