Skip to content

Commit 7ced3f1

Browse files
committed
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"
1 parent d1a9ef6 commit 7ced3f1

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

lib/fpm/package/rpm.rb

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ class FPM::Package::RPM < FPM::Package
122122
next File.expand_path(file)
123123
end
124124

125+
option "--with-source", :flag, "Also output an SRPM.", :default => false
126+
125127
rpmbuild_filter_from_provides = []
126128
option "--filter-from-provides", "REGEX",
127129
"Set %filter_from_provides to the supplied REGEX." do |filter_from_provides|
@@ -578,29 +580,35 @@ def output(output_path)
578580
FileUtils.cp(rpmpath, output_path)
579581
end
580582

581-
# Copy out the SRPM packages
582-
::Dir["#{build_path}/SRPMS/**/*.rpm"].each do |rpmpath|
583-
# Try to use the same naming scheme if we are specifying a custom output path?
584-
# Replace the .ARCH.EXTENSION with .src.EXTENSION ?
585-
#
586-
# For example, if the output wanted "foo.noarch.rpm"
587-
# then the srpm should be named "foo.src.rpm"
588-
#
589-
# But for the cases where someone asked for a file with just ".rpm" at the end,
590-
# we can also write the srpm as ".src.rpm"
591-
extension_checks = [
592-
# Try .<arch>.rpm ending
593-
Regexp.compile(to_s(".ARCH.EXTENSION$")),
594-
# Try just .rpm ending
595-
Regexp.compile(to_s(".EXTENSION$"))
596-
]
597-
598-
extension_checks.each do |re|
599-
if output_path =~ re
600-
filename = File.basename(output_path).gsub(re, to_s(".src.EXTENSION"))
601-
p [ "Copying", rpmpath => filename ]
602-
FileUtils.cp(rpmpath, File.join(File.dirname(output_path), filename))
603-
break
583+
if attributes[:rpm_with_source?]
584+
# Copy out the SRPM packages
585+
::Dir["#{build_path}/SRPMS/**/*.rpm"].each do |rpmpath|
586+
# Try to use the same naming scheme if we are specifying a custom output path?
587+
# Replace the .ARCH.EXTENSION with .src.EXTENSION ?
588+
#
589+
# For example, if the output wanted "foo.noarch.rpm"
590+
# then the srpm should be named "foo.src.rpm"
591+
#
592+
# But for the cases where someone asked for a file with just ".rpm" at the end,
593+
# we can also write the srpm as ".src.rpm"
594+
extension_checks = [
595+
# Try .<arch>.rpm ending
596+
Regexp.compile(to_s(".ARCH.EXTENSION$")),
597+
# Try just .rpm ending
598+
Regexp.compile(to_s(".EXTENSION$")),
599+
600+
# Last effort to just append `.src.rpm` to the end of the filename
601+
/$/
602+
]
603+
604+
extension_checks.each do |re|
605+
if output_path =~ re
606+
filename = File.basename(output_path).gsub(re, to_s(".src.EXTENSION"))
607+
outpath = File.join(File.dirname(output_path), filename)
608+
logger.log("Created SRPM", :path => outpath)
609+
FileUtils.cp(rpmpath, outpath)
610+
break
611+
end
604612
end
605613
end
606614
end

0 commit comments

Comments
 (0)