Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

adding --prefix support for RPM #230

Merged
merged 1 commit into from

2 participants

@jkoppe

I exposed prefix and build_sub_dir so the ERB can read these bits and manipulate the SPEC according to http://www.rpm.org/max-rpm/s1-rpm-reloc-prefix-tag.html. It's a pretty simple change, and I've used it to generate RPMs with and without the --prefix argument. Let me know if there's anything else you need!

@jkoppe

Expose prefix and build_sub_dir so the ERB can reference this information to generate the correct spec when using --prefix.

@jordansissel jordansissel commented on the diff
templates/rpm.erb
@@ -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) %>
@jordansissel Owner

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

@jkoppe
jkoppe added a note

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jordansissel

I am excited for relocatable package support! :)

@jordansissel

will test this later this week and try to write some tests to verify rpm is happy with it, then push a new gem :)

@jkoppe

@jordansissel: eta on this pull?

@jordansissel
@jordansissel jordansissel merged commit d6dddf2 into jordansissel:master
@jordansissel

This change broke a few tests, but the fixes were super easy.

I also changed it to use the File.join(prefix, path) as discussed.

Thanks again for this patch! :)

@jordansissel jordansissel referenced this pull request from a commit
@jordansissel - fix some failing tests introduced by #230 (regression check on quoted
  filenames, etc)
- Prefer File.join() when joining paths
6f3cd25
@jordansissel

I also couldn't get this to work properly, though I could be messing something. Here's what I tried, roughly 'package /etc/motd in the prefix /usr/local, but be relocatable.`

% fpm -s dir -t rpm -n example --prefix /usr/local /etc/motd`
% rpm -qlp example-1.0-1.x86_64.rpm 
/usr/local/usr/local/etc/motd

/usr/local/ was present twice.

Yet, if I patch it slightly, making 'build_sub_dir' always return "BUILD" instead of "BUILD/{prefix}", I get:

# Corrected behavior, I think?
% rpm -qlp example-1.0-1.x86_64.rpm                                  
/usr/local/etc/motd
% rpm -qip example-1.0-1.x86_64.rpm | grep Relo
Relocations : /usr/local 
% sudo rpm -i --prefix /pants example-1.0-1.x86_64.rpm 
% rpm -ql example
/pants/etc/motd
@jordansissel

Does the above behavior seem correct to you? If so, I"ll release with my patches.

@jkoppe

I'm probably abusing some RPM standard here, but the double /usr/local is ok in our case:

--> rpm -qpl Indeed-Percona-Server-server-5.5.24-rel26.0.256.rhel5-1-x86_64.rpm
/usr/local/percona/mysql-5.5.24/etc/init.d/mysql
/usr/local/percona/mysql-5.5.24/etc/logrotate.d/mysql
/usr/local/percona/mysql-5.5.24/usr/bin/innochecksum
/usr/local/percona/mysql-5.5.24/usr/bin/my_print_defaults
/usr/local/percona/mysql-5.5.24/usr/bin/myisam_ftdump
/usr/local/percona/mysql-5.5.24/usr/bin/myisamchk
/usr/local/percona/mysql-5.5.24/usr/bin/myisamlog
/usr/local/percona/mysql-5.5.24/usr/bin/myisampack
/usr/local/percona/mysql-5.5.24/usr/bin/mysql_convert_table_format
/usr/local/percona/mysql-5.5.24/usr/bin/mysql_fix_extensions
/usr/local/percona/mysql-5.5.24/usr/bin/mysql_install_db
/usr/local/percona/mysql-5.5.24/usr/bin/mysql_plugin
/usr/local/percona/mysql-5.5.24/usr/bin/mysql_secure_installation
/usr/local/percona/mysql-5.5.24/usr/bin/mysql_setpermission
/usr/local/percona/mysql-5.5.24/usr/bin/mysql_tzinfo_to_sql
/usr/local/percona/mysql-5.5.24/usr/bin/mysql_upgrade
/usr/local/percona/mysql-5.5.24/usr/bin/mysql_zap
/usr/local/percona/mysql-5.5.24/usr/bin/mysqlbug
/usr/local/percona/mysql-5.5.24/usr/bin/mysqld_multi
/usr/local/percona/mysql-5.5.24/usr/bin/mysqld_safe
/usr/local/percona/mysql-5.5.24/usr/bin/mysqldumpslow
/usr/local/percona/mysql-5.5.24/usr/bin/mysqlhotcopy
/usr/local/percona/mysql-5.5.24/usr/bin/mysqltest
/usr/local/percona/mysql-5.5.24/usr/bin/perror
/usr/local/percona/mysql-5.5.24/usr/bin/replace
/usr/local/percona/mysql-5.5.24/usr/bin/resolve_stack_dump
/usr/local/percona/mysql-5.5.24/usr/bin/resolveip
...

For MySQL RPMs, we use a modified startup script which sets environment variables correctly so the /usr/local/.../usr/ stuff just works.

Perhaps this is a no-no for RPMs. I'm going on vacation this week and won't be spending any time thinking about this. I hotfixed fpm on a machine so we could get this functionality for now -- but lets hold off on this pull until we have some more time to chat (August)

@jordansissel

Sounds reasonable to me! In the mean-time, I"ll try to find someone who uses relocatable rpms and see what their use cases are.

@prof-milki prof-milki referenced this pull request from a commit in prof-milki/xpm
jls - fix some failing tests introduced by #230 (regression check on quoted
  filenames, etc)
- Prefer File.join() when joining paths
e63fffb
@prof-milki prof-milki referenced this pull request from a commit in prof-milki/xpm
@jordansissel - fix some failing tests introduced by #230 (regression check on quoted
  filenames, etc)
- Prefer File.join() when joining paths
ded6c5f
@jordansissel jordansissel referenced this pull request from a commit
@jordansissel - fix some failing tests introduced by #230 (regression check on quoted
  filenames, etc)
- Prefer File.join() when joining paths
ba015ee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 29, 2012
  1. make --prefix work with rpm output files

    Jason Koppe authored
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 4 deletions.
  1. +10 −1 lib/fpm/package/rpm.rb
  2. +7 −3 templates/rpm.erb
View
11 lib/fpm/package/rpm.rb
@@ -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)
@@ -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
View
10 templates/rpm.erb
@@ -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 %>
@@ -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
@@ -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) %>
@jordansissel Owner

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

@jkoppe
jkoppe added a note

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
<% end -%>
<%# list only files, not directories? -%>
<%=
@@ -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
Something went wrong with that request. Please try again.