1 # This file can be distributed under the same terms as ruby itself.
2 # Author: Marek Gilbert <gil (at) fooplanet (dot) com>
4 # A simple wrapper around rpmbuild's --showrc command that allows rpm to
5 # tell gem2rpm where to install things.
8 IO.popen('rpmbuild --showrc', 'r') do |fd|
13 # Read the rc file and define all the macros in it.
16 fd.each_line() do |line|
17 if line =~ /^-14:\s+(\w+)\s+(\S+)/
23 # Lookup a macro by name. Use only the name part and leave out the
24 # leading '%{' and trailing '}'. If any value exists for the macro, it is
25 # evaluated such that the result will be macro-free.
31 # Recursively examine the string and substitute any macros with their
34 return nil if value.nil?
35 # value = value.gsub(/%\(([^\)]+)\)/) do |x|
39 return value.gsub(/%\{([^}]+)\}/) { |x| lookup($1) }
44 attr_reader :name, :bits, :flags
46 def initialize(bits, name, flags)
53 0 != @bits & other.bits
56 BINARIES = RpmBuildOption.new(1, 'binary', '-bb')
57 SOURCES = RpmBuildOption.new(2, 'sources', '-bs')
58 ALL = RpmBuildOption.new(1 + 2, 'all', '-ba')
61 # Wrapper around the rpmbuild command.
70 SysUtils.run("rpmbuild #{$options.rpm_build_opts.flags} " +
71 "#{rpm.spec_filename}")
75 @rc.lookup('_builddir')
83 @rc.lookup('_srcrpmdir')
87 @rc.lookup('_sourcedir')
91 @rc.lookup('_specdir')
95 return File.join(rpm_dir, rpm.build_arch,
96 "#{rpm.name}-#{rpm.version}-#{rpm.release}.#{rpm.build_arch}.rpm")
99 def srpm_filename(rpm)
100 return File.join(src_rpm_dir,
101 "#{rpm.name}-#{rpm.version}-#{rpm.release}.src.rpm")