Class: PKGWizard::SRPM

Inherits:
Object
  • Object
show all
Defined in:
lib/pkg-wizard/rpm.rb

Class Method Summary collapse

Class Method Details

.create(params = {}) ⇒ Object

params rpmbuild_dir: _topdir macro macros: macros string

Raises:



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/pkg-wizard/rpm.rb', line 186

def self.create(params = {})
  rpmbuild_dir = params[:rpmbuild_dir] || "#{ENV['HOME']}/rpmbuild/"
  macros = params[:macros] || ''
  rhel5_compat = params[:rhel5_compat] || false
  specs = Dir["*.spec"]
  raise NoSpecFound.new 'No spec found in current dir'  if specs.empty?
  pkg_name = File.read(specs.first).match(/Name:(.*?)$/)[1].strip.chomp
  pkg_ver = File.read(specs.first).match(/Version:(.*?)$/)[1].strip.chomp
  pkg_release = File.read(specs.first).match(/Release:(.*?)$/)[1].strip.chomp.gsub(/%\{\?.*\}/, '')
  pkg_full_name = "#{pkg_name}-#{pkg_ver}-#{pkg_release}"
  %w(SOURCES SRPMS SPECS BUILDROOT RPMS BUILD).each do |d|
    FileUtils.mkdir_p File.join(File.expand_path(rpmbuild_dir), d) if not File.exist?(File.join(rpmbuild_dir, d))
  end
  Dir['*'].each do |f|
    FileUtils.cp(f, "#{rpmbuild_dir}/SOURCES") if not File.directory?(f)
  end
  macros << " --define '_topdir #{rpmbuild_dir}'"
  if rhel5_compat
    macros << ' --define "_source_filedigest_algorithm 0" --define "_binary_filedigest_algorithm 0"'
  end
  output = `rpmbuild --nodeps -bs *.spec #{macros} 2>&1`
  resulting_pkg = ''
  output.each_line do |l|
    if l =~ /Wrote:/
      resulting_pkg = l.gsub('Wrote: ', '').strip.chomp
    end
  end
  raise RPMBuildError.new(output) if $? != 0
  resulting_pkg
end