Class: Akabei::Builder
- Inherits:
-
Object
show all
- Extended by:
- AttrPath
- Defined in:
- lib/akabei/builder.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from AttrPath
attr_path_accessor, attr_path_writer
Constructor Details
#initialize(opts = {}) ⇒ Builder
Returns a new instance of Builder.
14
15
16
17
18
19
|
# File 'lib/akabei/builder.rb', line 14
def initialize(opts = {})
self.srcdest = opts[:srcdest]
self.pkgdest = opts[:pkgdest]
self.logdest = opts[:logdest]
self.signer = opts[:signer]
end
|
Instance Attribute Details
#signer ⇒ Object
Returns the value of attribute signer.
12
13
14
|
# File 'lib/akabei/builder.rb', line 12
def signer
@signer
end
|
Instance Method Details
#build_package(dir, chroot_tree) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/akabei/builder.rb', line 21
def build_package(dir, chroot_tree)
Dir.mktmpdir do |tmp_pkgdest|
wrap_dir(:srcdest) do
wrap_dir(:logdest) do
tmp_pkgdest = Pathname.new(tmp_pkgdest)
env = {
SRCDEST: srcdest.realpath,
PKGDEST: tmp_pkgdest.realpath,
LOGDEST: logdest.realpath,
}
chroot_tree.makechrootpkg(dir, env)
gather_packages(tmp_pkgdest)
end
end
end
end
|
#copy_and_sign_package(package_path, dest) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/akabei/builder.rb', line 47
def copy_and_sign_package(package_path, dest)
FileUtils.cp(package_path, dest)
if signer
signer.detach_sign(dest)
end
rescue => e
begin
dest.unlink
rescue Errno::ENOENT
end
raise e
end
|
#find_source_package(srcpkgdest) ⇒ Object
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/akabei/builder.rb', line 105
def find_source_package(srcpkgdest)
children = srcpkgdest.each_child.to_a
if children.empty?
raise Error.new("makepkg --source generated nothing")
elsif children.size > 1
raise Error.new("makepkg --source generated multiple files???: #{children.map(&:to_s)}")
else
children.first
end
end
|
#gather_packages(tmp_pkgdest) ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/akabei/builder.rb', line 38
def gather_packages(tmp_pkgdest)
pkgdest.mkpath
tmp_pkgdest.each_child.map do |package_path|
dest = pkgdest.join(package_path.basename)
copy_and_sign_package(package_path, dest)
Package.new(dest)
end
end
|
#makepkg_source(dir, srcdest, srcpkgdest, builddir) ⇒ Object
96
97
98
99
100
101
102
103
|
# File 'lib/akabei/builder.rb', line 96
def makepkg_source(dir, srcdest, srcpkgdest, builddir)
env = {
SRCDEST: srcdest.realpath,
SRCPKGDEST: srcpkgdest.realpath,
BUILDDIR: builddir.realpath,
}
System.system(%w[makepkg --source], chdir: dir, env: env)
end
|
#with_source_package(dir, &block) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/akabei/builder.rb', line 78
def with_source_package(dir, &block)
dir = Pathname.new(dir)
Dir.mktmpdir do |tmp_srcpkgdest|
tmp_srcpkgdest = Pathname.new(tmp_srcpkgdest)
Dir.mktmpdir do |builddir|
builddir = Pathname.new(builddir)
wrap_dir(:srcdest) do
makepkg_source(dir, srcdest, tmp_srcpkgdest, builddir)
end
end
srcpkg = find_source_package(tmp_srcpkgdest)
dir.join(srcpkg.basename).unlink
block.call(srcpkg)
end
end
|
#wrap_dir(attr, &block) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/akabei/builder.rb', line 60
def wrap_dir(attr, &block)
old_dir = instance_variable_get("@#{attr}")
if old_dir.nil?
Dir.mktmpdir do |tmp|
dir = Pathname.new(tmp)
instance_variable_set("@#{attr}", dir)
dir.chmod(0755)
block.call
end
else
old_dir.mkpath
block.call
end
ensure
instance_variable_set("@#{attr}", old_dir)
end
|