Class: Revamp::Persister::Rpm::Builder
- Inherits:
-
Object
- Object
- Revamp::Persister::Rpm::Builder
show all
- Includes:
- BuilderInternals
- Defined in:
- lib/revamp/persister/rpm/builder.rb
Overview
A builder for RPM’s packages
Constant Summary
collapse
- SOURCES =
'SOURCES'
- SPECS =
'SPECS'
- RPMS =
'RPMS'
- SELFDIR =
Pathname.new(__FILE__).dirname
- ATTRS =
[
:name, :version, :filename, :rpm, :model, :tmpdir, :release, :filenames,
:specfile, :has_requirements, :requirements, :options
]
Instance Attribute Summary collapse
Instance Method Summary
collapse
#cleanup_files, #configure_rpm_requirements_line, #erbize
Constructor Details
#initialize(model, dir, options) ⇒ Builder
Returns a new instance of Builder.
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/revamp/persister/rpm/builder.rb', line 40
def initialize(model, dir, options)
@options = options
@name = "puppetmodule_#{model.slugname}"
@release = options[:release]
assign_model(model)
@filename = "#{name}-#{version}-#{release}.noarch.rpm"
@rpm = "#{name}-#{version}"
@specfile = rpm + '.spec'
@tmpdir = dir
@produced = false
@log = Revamp.logger
@requirements = configure_rpm_requirements_line
@log.debug("Target file: #{target}")
end
|
Instance Attribute Details
#produced ⇒ Object
Also known as:
produced?
Returns the value of attribute produced.
37
38
39
|
# File 'lib/revamp/persister/rpm/builder.rb', line 37
def produced
@produced
end
|
Instance Method Details
#cleanup ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/revamp/persister/rpm/builder.rb', line 91
def cleanup
arch = RbConfig::CONFIG['arch'].gsub('-linux', '')
cleanup_files [
sources_tgz_path, specfile_path, tmpdir.join('BUILD').join(rpm),
tmpdir.join('BUILDROOT').join("#{rpm}-#{release}.#{arch}")
]
end
|
#make_structure ⇒ Object
66
67
68
69
70
|
# File 'lib/revamp/persister/rpm/builder.rb', line 66
def make_structure
return unless needs_to_write?
FileUtils.mkdir_p(tmpdir.join(SOURCES))
FileUtils.mkdir_p(tmpdir.join(SPECS))
end
|
#produce ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/revamp/persister/rpm/builder.rb', line 55
def produce
if needs_to_write?
@log.info("Converting to RPM package #{target}...")
cmd = "rpmbuild -ba #{SPECS}/#{specfile}"
verbose = options[:verbose]
ret = Revamp::Persister::Rpm::CommandLine.execute(cmd, tmpdir, verbose)
fail "RPM Build failed with retcode = #{ret.exitstatus}" unless ret.success?
end
move_produced
end
|
#write_sources ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/revamp/persister/rpm/builder.rb', line 76
def write_sources
return unless needs_to_write?
pathsufix = Pathname.new(rpm)
File.open(sources_tgz_path, 'wb') do |tgz|
Zlib::GzipWriter.wrap(tgz) do |gz|
Gem::Package::TarWriter.new(gz) do |tar|
model.files.each do |file, content|
full = pathsufix.join(file).to_s
tar.add_file_simple(full, 0644, content.length) { |io| io.write(content) }
end
end
end
end
end
|
#write_spec ⇒ Object
72
73
74
|
# File 'lib/revamp/persister/rpm/builder.rb', line 72
def write_spec
File.open(specfile_path, 'w') { |file| file.write(generate_spec) } if needs_to_write?
end
|