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

adding --prefix support for RPM #230

Merged
merged 1 commit into from Jul 22, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/fpm/package/rpm.rb
Expand Up @@ -204,6 +204,15 @@ def output(output_path)
@logger.log("Created rpm", :path => output_path)
end # def output

def prefix
return attributes[:prefix]
end # def prefix

def build_sub_dir
return "BUILD" + prefix
end # def prefix


def to_s(format=nil)
return super("NAME-VERSION-ITERATION.ARCH.TYPE") if format.nil?
return super(format)
Expand All @@ -218,5 +227,5 @@ def digest_algorithm
end # def digest_algorithm

public(:input, :output, :converted_from, :architecture, :to_s, :iteration,
:payload_compression, :digest_algorithm)
:payload_compression, :digest_algorithm, :prefix, :build_sub_dir)
end # class FPM::Package::RPM
10 changes: 7 additions & 3 deletions templates/rpm.erb
Expand Up @@ -27,6 +27,9 @@ AutoReqProv: no
# Seems specifying BuildRoot is required on older rpmbuild (like on CentOS 5)
# fpm passes '--define buildroot ...' on the commandline, so just reuse that.
BuildRoot: %buildroot
<% if !prefix.empty? %>
Prefix: <%= prefix %>
<% end -%>

Group: <%= category %>
License: <%= license %>
Expand Down Expand Up @@ -62,7 +65,7 @@ Obsoletes: <%= repl %>
<% files.each do |path| -%>
<% source = Shellwords.shellescape(File.join(staging_path, path)) -%>
<% # Copy to the build_path/BUILD/ to make rpmbuild happy -%>
<% target = Shellwords.shellescape(File.join(build_path, "BUILD", path)) -%>
<% target = Shellwords.shellescape(File.join(build_path, build_sub_dir, path)) -%>
<% dir = File.dirname(target) %>
mkdir -p <%= dir %>
if [ -f <%= source %> ] || [ -h <%= source %> ] ; then
Expand Down Expand Up @@ -99,7 +102,7 @@ fi
%defattr(-,<%= attributes[:rpm_user] %>,<%= attributes[:rpm_group] %>,-)
<%# Output config files and then regular files. -%>
<% config_files.each do |path| -%>
%config(noreplace) <%= path %>
%config(noreplace) <%= path.gsub(/^/,prefix) %>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an FYI: path.gsub(/^/, prefix) is probably better written as "#{prefix}/#{path}" or perhaps better File.join(prefix,path)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those two options make more sense. Note though that prefix is either / or /something/like/this. And I'm also doing no validation on prefix -- I assumed it was already done elsewhere.

<% end -%>
<%# list only files, not directories? -%>
<%=
Expand All @@ -115,7 +118,8 @@ fi
.collect { |f| f[/\s/] and "\"#{f}\"" or f } \
.collect { |f| f.gsub("[", "[\\[]") } \
.collect { |f| f.gsub("*", "[*]") } \
.join("\n")
.collect { |f| f.gsub(/^/, prefix ) } \
.join("\n")
%>

%changelog