akabei 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/akabei/abs.rb +2 -2
- data/lib/akabei/build_helper.rb +5 -0
- data/lib/akabei/builder.rb +7 -8
- data/lib/akabei/chroot_tree.rb +9 -40
- data/lib/akabei/cli.rb +17 -2
- data/lib/akabei/omakase/cli.rb +34 -3
- data/lib/akabei/system.rb +51 -0
- data/lib/akabei/version.rb +1 -1
- data/spec/akabei/builder_spec.rb +8 -7
- data/spec/akabei/chroot_tree_spec.rb +7 -53
- data/spec/akabei/cli_spec.rb +27 -17
- data/spec/akabei/omakase/cli_spec.rb +43 -21
- data/spec/akabei/system_spec.rb +81 -0
- data/spec/spec_helper.rb +38 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 714ce0c1f0f26800d43745ab916973a83d66f13b
|
4
|
+
data.tar.gz: 663049f39fedbb24acc729035a6809c615a66fce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68684dbf90c74d3582fc1277a5a046350e98f9c27ab2c9a7caf7f8542fae553d953965996a58f0a5f68078b6d6d4cb5a6f281983536ece9c48555790d628870d
|
7
|
+
data.tar.gz: d4e2bf3a2d56cb0410942aaa10324c24e27e3aec3dc27e83632ad819bc36da35e674cb1e417dc0ed972f36dd14d94dc61acdbc9a78d8a8b037f2c7e473967f6b
|
data/CHANGELOG.md
CHANGED
data/lib/akabei/abs.rb
CHANGED
@@ -21,9 +21,9 @@ module Akabei
|
|
21
21
|
ArchiveUtils.extract_all(@path, tree)
|
22
22
|
end
|
23
23
|
pkgname = detect_pkgname(srcpkg)
|
24
|
-
FileUtils.rm_rf(root.join(pkgname)
|
24
|
+
FileUtils.rm_rf(root.join(pkgname))
|
25
25
|
ArchiveUtils.extract_all(srcpkg, root)
|
26
|
-
FileUtils.rm_f(@path
|
26
|
+
FileUtils.rm_f(@path)
|
27
27
|
ArchiveUtils.archive_all(tree, @path, Archive::COMPRESSION_GZIP, Archive::FORMAT_TAR)
|
28
28
|
end
|
29
29
|
end
|
data/lib/akabei/build_helper.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
require 'akabei/error'
|
2
|
+
|
1
3
|
module Akabei
|
2
4
|
module BuildHelper
|
3
5
|
def build_in_chroot(builder, chroot, repo_db, repo_files, abs, package_dir)
|
6
|
+
unless package_dir.directory?
|
7
|
+
raise Error.new("#{package_dir} isn't a directory")
|
8
|
+
end
|
4
9
|
chroot.with_chroot do
|
5
10
|
packages = builder.build_package(package_dir, chroot)
|
6
11
|
packages.each do |package|
|
data/lib/akabei/builder.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'akabei/attr_path'
|
2
2
|
require 'akabei/error'
|
3
3
|
require 'akabei/package'
|
4
|
+
require 'akabei/system'
|
4
5
|
require 'fileutils'
|
5
6
|
require 'tmpdir'
|
6
7
|
|
@@ -27,7 +28,7 @@ module Akabei
|
|
27
28
|
PKGDEST: tmp_pkgdest.realpath,
|
28
29
|
LOGDEST: logdest.realpath,
|
29
30
|
}
|
30
|
-
chroot_tree.makechrootpkg(dir
|
31
|
+
chroot_tree.makechrootpkg(dir, env)
|
31
32
|
gather_packages(tmp_pkgdest)
|
32
33
|
end
|
33
34
|
end
|
@@ -43,7 +44,7 @@ module Akabei
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def copy_and_sign_package(package_path, dest)
|
46
|
-
FileUtils.cp(package_path
|
47
|
+
FileUtils.cp(package_path, dest)
|
47
48
|
if signer
|
48
49
|
signer.detach_sign(dest)
|
49
50
|
end
|
@@ -92,13 +93,11 @@ module Akabei
|
|
92
93
|
|
93
94
|
def makepkg_source(dir, srcdest, srcpkgdest, builddir)
|
94
95
|
env = {
|
95
|
-
|
96
|
-
|
97
|
-
|
96
|
+
SRCDEST: srcdest.realpath,
|
97
|
+
SRCPKGDEST: srcpkgdest.realpath,
|
98
|
+
BUILDDIR: builddir.realpath,
|
98
99
|
}
|
99
|
-
|
100
|
-
raise Error.new("makepkg --source failed: #{dir}")
|
101
|
-
end
|
100
|
+
System.system(%w[makepkg --source], chdir: dir, env: env)
|
102
101
|
end
|
103
102
|
|
104
103
|
def find_source_package(srcpkgdest)
|
data/lib/akabei/chroot_tree.rb
CHANGED
@@ -1,18 +1,11 @@
|
|
1
1
|
require 'akabei/attr_path'
|
2
2
|
require 'akabei/error'
|
3
|
+
require 'akabei/system'
|
3
4
|
require 'pathname'
|
4
5
|
require 'tmpdir'
|
5
6
|
|
6
7
|
module Akabei
|
7
8
|
class ChrootTree
|
8
|
-
class CommandFailed < Error
|
9
|
-
attr_reader :args
|
10
|
-
def initialize(args)
|
11
|
-
super("command failed: #{args.join(' ')}")
|
12
|
-
@args = args
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
9
|
attr_reader :root, :arch
|
17
10
|
extend AttrPath
|
18
11
|
attr_path_accessor :makepkg_config, :pacman_config
|
@@ -26,57 +19,33 @@ module Akabei
|
|
26
19
|
|
27
20
|
def with_chroot(&block)
|
28
21
|
if @root
|
29
|
-
mkarchroot(
|
22
|
+
mkarchroot(BASE_PACKAGES)
|
30
23
|
block.call
|
31
24
|
else
|
32
25
|
@root = Pathname.new(Dir.mktmpdir)
|
33
26
|
begin
|
34
|
-
mkarchroot(
|
27
|
+
mkarchroot(BASE_PACKAGES)
|
35
28
|
block.call
|
36
29
|
ensure
|
37
|
-
|
30
|
+
System.sudo(['rm', '-rf', @root], {})
|
38
31
|
@root = nil
|
39
32
|
end
|
40
33
|
end
|
41
34
|
end
|
42
35
|
|
43
36
|
def makechrootpkg(dir, env)
|
44
|
-
|
37
|
+
System.sudo(['makechrootpkg', '-cur', @root], chdir: dir, env: env, arch: @arch)
|
45
38
|
end
|
46
39
|
|
47
|
-
def mkarchroot(
|
40
|
+
def mkarchroot(args)
|
48
41
|
cmd = ['mkarchroot']
|
49
42
|
[['-M', makepkg_config], ['-C', pacman_config]].each do |flag, path|
|
50
43
|
if path
|
51
|
-
cmd << flag << path
|
44
|
+
cmd << flag << path
|
52
45
|
end
|
53
46
|
end
|
54
|
-
cmd << @root.join('root')
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def arch_nspawn(*args)
|
59
|
-
execute('arch-nspawn', @root.join('root').to_s, *args)
|
60
|
-
end
|
61
|
-
|
62
|
-
def execute(*args)
|
63
|
-
if args.last.is_a?(Hash)
|
64
|
-
opts = args.last
|
65
|
-
if opts.has_key?(:env)
|
66
|
-
opts = opts.dup
|
67
|
-
env = opts.delete(:env)
|
68
|
-
env.each do |k, v|
|
69
|
-
args.unshift("#{k}=#{v}")
|
70
|
-
end
|
71
|
-
args.unshift('env')
|
72
|
-
args[-1] = opts
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
puts "Execute: #{args.join(' ')}"
|
77
|
-
unless system('sudo', 'setarch', @arch, *args)
|
78
|
-
raise CommandFailed.new(args)
|
79
|
-
end
|
47
|
+
cmd << @root.join('root')
|
48
|
+
System.sudo(cmd + args, arch: @arch)
|
80
49
|
end
|
81
50
|
end
|
82
51
|
end
|
data/lib/akabei/cli.rb
CHANGED
@@ -6,6 +6,7 @@ require 'akabei/omakase/cli'
|
|
6
6
|
require 'akabei/package'
|
7
7
|
require 'akabei/repository'
|
8
8
|
require 'akabei/signer'
|
9
|
+
require 'akabei/version'
|
9
10
|
require 'pathname'
|
10
11
|
require 'thor'
|
11
12
|
require 'tmpdir'
|
@@ -43,6 +44,8 @@ module Akabei
|
|
43
44
|
end
|
44
45
|
extend CommonOptions
|
45
46
|
|
47
|
+
package_name 'akabei'
|
48
|
+
|
46
49
|
include BuildHelper
|
47
50
|
desc 'build DIR', 'Build package in chroot environment'
|
48
51
|
option :chroot_dir,
|
@@ -97,7 +100,7 @@ module Akabei
|
|
97
100
|
|
98
101
|
abs = Abs.new(repo_path.join("#{repo_name}.abs.tar.gz"), repo_name)
|
99
102
|
|
100
|
-
build_in_chroot(builder, chroot, repo_db, repo_files, abs, package_dir)
|
103
|
+
build_in_chroot(builder, chroot, repo_db, repo_files, abs, Pathname.new(package_dir))
|
101
104
|
repo_db.save(db_path)
|
102
105
|
repo_files.save(files_path)
|
103
106
|
end
|
@@ -156,6 +159,18 @@ module Akabei
|
|
156
159
|
repo.save(db_path)
|
157
160
|
end
|
158
161
|
|
159
|
-
|
162
|
+
desc 'version', 'Show version'
|
163
|
+
option :numeric,
|
164
|
+
desc: 'Display version number only',
|
165
|
+
type: :boolean
|
166
|
+
def version
|
167
|
+
if options[:numeric]
|
168
|
+
puts VERSION
|
169
|
+
else
|
170
|
+
puts "akabei #{VERSION} on #{RUBY_DESCRIPTION}"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
Akabei::CLI.register(Akabei::Omakase::CLI, 'omakase', 'omakase <command>', 'Omakase mode. See `akabei omakase help`.')
|
160
175
|
end
|
161
176
|
end
|
data/lib/akabei/omakase/cli.rb
CHANGED
@@ -20,7 +20,7 @@ module Akabei
|
|
20
20
|
super(task, nil, true)
|
21
21
|
end
|
22
22
|
|
23
|
-
desc 'init NAME',
|
23
|
+
desc 'init NAME', 'Generate omakase template for NAME repository'
|
24
24
|
option :repo_key,
|
25
25
|
desc: 'GPG key to sign repository database',
|
26
26
|
banner: 'GPGKEY',
|
@@ -67,7 +67,7 @@ module Akabei
|
|
67
67
|
say('Edit etc/makepkg.*.conf and set PACKAGER first!', :green)
|
68
68
|
end
|
69
69
|
|
70
|
-
desc 'build PACKAGE_NAME',
|
70
|
+
desc 'build PACKAGE_NAME', 'Build PACKAGE_NAME'
|
71
71
|
def build(package_name)
|
72
72
|
builder = Builder.new(
|
73
73
|
signer: config.package_signer,
|
@@ -75,7 +75,6 @@ module Akabei
|
|
75
75
|
logdest: config.logdest,
|
76
76
|
)
|
77
77
|
repo_signer = config.repo_signer
|
78
|
-
|
79
78
|
s3 = S3.new(config['s3'], shell)
|
80
79
|
|
81
80
|
config.builds.each do |arch, config_file|
|
@@ -102,6 +101,29 @@ module Akabei
|
|
102
101
|
end
|
103
102
|
end
|
104
103
|
|
104
|
+
desc 'remove PACKAGE_NAME', 'Remove PACKAGE_NAME'
|
105
|
+
def remove(package_name)
|
106
|
+
repo_signer = config.repo_signer
|
107
|
+
s3 = S3.new(config['s3'], shell)
|
108
|
+
|
109
|
+
config.builds.each do |arch, config_file|
|
110
|
+
db_path = config.db_path(arch)
|
111
|
+
files_path = config.files_path(arch)
|
112
|
+
abs = Abs.new(config.abs_path(arch), config.name)
|
113
|
+
|
114
|
+
s3.before!(config, arch)
|
115
|
+
repo_db = Repository.load(db_path, signer: repo_signer)
|
116
|
+
repo_files = Repository.load(files_path, include_files: true)
|
117
|
+
|
118
|
+
remove_it(repo_db, package_name)
|
119
|
+
remove_it(repo_files, package_name)
|
120
|
+
abs.remove(package_name)
|
121
|
+
repo_db.save(db_path)
|
122
|
+
repo_files.save(files_path)
|
123
|
+
s3.after!(config, arch, [])
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
105
127
|
private
|
106
128
|
|
107
129
|
def config
|
@@ -111,6 +133,15 @@ module Akabei
|
|
111
133
|
c
|
112
134
|
end
|
113
135
|
end
|
136
|
+
|
137
|
+
def remove_it(repo, package_name)
|
138
|
+
entry = repo.remove(package_name)
|
139
|
+
if entry
|
140
|
+
say("#{entry.db_name} is removed")
|
141
|
+
else
|
142
|
+
say("WARNING: #{package_name} doesn't exist", :yellow)
|
143
|
+
end
|
144
|
+
end
|
114
145
|
end
|
115
146
|
end
|
116
147
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'akabei/error'
|
2
|
+
|
3
|
+
module Akabei
|
4
|
+
module System
|
5
|
+
class CommandFailed < Error
|
6
|
+
attr_reader :env, :args, :opts
|
7
|
+
def initialize(env, args, opts)
|
8
|
+
super("command failed: #{args.join(' ')}")
|
9
|
+
@env = env
|
10
|
+
@args = args
|
11
|
+
@opts = opts
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module_function
|
16
|
+
|
17
|
+
def sudo(args, opts)
|
18
|
+
if opts.has_key?(:env)
|
19
|
+
opts = opts.dup
|
20
|
+
args = args.dup
|
21
|
+
env = opts.delete(:env)
|
22
|
+
env.each do |k, v|
|
23
|
+
args.unshift("#{k}=#{v}")
|
24
|
+
end
|
25
|
+
args.unshift('env')
|
26
|
+
end
|
27
|
+
|
28
|
+
puts "SUDO: #{args.join(' ')}"
|
29
|
+
system(%w[sudo] + args, opts)
|
30
|
+
end
|
31
|
+
|
32
|
+
def system(args, opts)
|
33
|
+
opts = opts.dup
|
34
|
+
env = {}
|
35
|
+
opts.delete(:env).tap do |e|
|
36
|
+
break unless e
|
37
|
+
e.each do |k, v|
|
38
|
+
env[k.to_s] = v.to_s
|
39
|
+
end
|
40
|
+
end
|
41
|
+
opts.delete(:arch).tap do |a|
|
42
|
+
break unless a
|
43
|
+
args = args.dup
|
44
|
+
args.unshift('setarch', a)
|
45
|
+
end
|
46
|
+
unless Kernel.system(env, *args.map(&:to_s), opts)
|
47
|
+
raise CommandFailed.new(env, args, opts)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/akabei/version.rb
CHANGED
data/spec/akabei/builder_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe Akabei::Builder do
|
|
18
18
|
let(:chroot) { double('ChrootTree') }
|
19
19
|
|
20
20
|
before do
|
21
|
-
expect(chroot).to receive(:makechrootpkg).once.with(package_dir
|
21
|
+
expect(chroot).to receive(:makechrootpkg).once.with(package_dir, anything) { |dir, env|
|
22
22
|
expect(env[:SRCDEST]).to be_directory
|
23
23
|
expect(env[:PKGDEST]).to be_directory
|
24
24
|
expect(env[:LOGDEST]).to be_directory
|
@@ -94,16 +94,17 @@ describe Akabei::Builder do
|
|
94
94
|
|
95
95
|
describe '#with_source_package' do
|
96
96
|
before do
|
97
|
-
expect(
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
expect(Akabei::System).to receive(:system) { |args, opts|
|
98
|
+
env = opts[:env]
|
99
|
+
srcdest = Pathname.new(env[:SRCDEST])
|
100
|
+
srcpkgdest = Pathname.new(env[:SRCPKGDEST])
|
101
|
+
builddir = Pathname.new(env[:BUILDDIR])
|
101
102
|
expect(srcdest).to be_directory
|
102
103
|
expect(srcpkgdest).to be_directory
|
103
104
|
expect(builddir).to be_directory
|
104
105
|
|
105
|
-
expect(
|
106
|
-
expect(
|
106
|
+
expect(args[0]).to eq('makepkg')
|
107
|
+
expect(args[1]).to eq('--source')
|
107
108
|
expect(opts[:chdir]).to eq(package_dir)
|
108
109
|
|
109
110
|
# Simulate `makepkg --source`
|
@@ -10,7 +10,6 @@ describe Akabei::ChrootTree do
|
|
10
10
|
let(:action) { double('some action') }
|
11
11
|
|
12
12
|
before do
|
13
|
-
allow(chroot).to receive(:execute) { nil }
|
14
13
|
expect(action).to receive(:call).once
|
15
14
|
end
|
16
15
|
|
@@ -20,6 +19,7 @@ describe Akabei::ChrootTree do
|
|
20
19
|
it 'creates a temporary chroot' do
|
21
20
|
expect(chroot).to receive(:mkarchroot).once
|
22
21
|
expect(Dir).to receive(:mktmpdir).once.and_call_original
|
22
|
+
expect(Akabei::System).to receive(:sudo).with(['rm', '-rf', anything], anything)
|
23
23
|
|
24
24
|
chroot.with_chroot { action.call }
|
25
25
|
end
|
@@ -28,9 +28,9 @@ describe Akabei::ChrootTree do
|
|
28
28
|
context 'with root' do
|
29
29
|
it 'uses given root' do
|
30
30
|
expect(Dir).to_not receive(:mktmpdir)
|
31
|
-
expect(
|
31
|
+
expect(Akabei::System).to receive(:sudo) { |args, opts|
|
32
32
|
expect(args[0]).to eq('mkarchroot')
|
33
|
-
expect(args[1]).to eq(chroot_root.join('root')
|
33
|
+
expect(args[1]).to eq(chroot_root.join('root'))
|
34
34
|
}
|
35
35
|
|
36
36
|
chroot.with_chroot { action.call }
|
@@ -38,9 +38,9 @@ describe Akabei::ChrootTree do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'respects makepkg_config' do
|
41
|
-
path = '/path/to/makepkg.conf'
|
41
|
+
path = Pathname.new('/path/to/makepkg.conf')
|
42
42
|
chroot.makepkg_config = path
|
43
|
-
expect(
|
43
|
+
expect(Akabei::System).to receive(:sudo) { |args, opts|
|
44
44
|
expect(args[0]).to eq('mkarchroot')
|
45
45
|
expect(args.each_cons(2)).to include(['-M', path])
|
46
46
|
}
|
@@ -49,9 +49,9 @@ describe Akabei::ChrootTree do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'respects pacman_config' do
|
52
|
-
path = '/path/to/pacman.conf'
|
52
|
+
path = Pathname.new('/path/to/pacman.conf')
|
53
53
|
chroot.pacman_config = path
|
54
|
-
expect(
|
54
|
+
expect(Akabei::System).to receive(:sudo) { |args, opts|
|
55
55
|
expect(args[0]).to eq('mkarchroot')
|
56
56
|
expect(args.each_cons(2)).to include(['-C', path])
|
57
57
|
}
|
@@ -59,50 +59,4 @@ describe Akabei::ChrootTree do
|
|
59
59
|
chroot.with_chroot { action.call }
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
63
|
-
describe '#execute' do
|
64
|
-
let(:command) { %w[rm -rf /] }
|
65
|
-
let(:opts) { { chdir: '/' } }
|
66
|
-
|
67
|
-
it 'calls sudo and setarch' do
|
68
|
-
expect(chroot).to receive(:system).once.with(any_args) { |*args|
|
69
|
-
expect(args).to eq(%W[sudo setarch #{arch}] + command + [opts])
|
70
|
-
}
|
71
|
-
|
72
|
-
stdout = capture_stdout do
|
73
|
-
chroot.execute(*command + [opts])
|
74
|
-
end
|
75
|
-
expect(stdout).to include('rm -rf /')
|
76
|
-
end
|
77
|
-
|
78
|
-
context 'with :env keyword' do
|
79
|
-
let(:key) { :FOO }
|
80
|
-
let(:value) { 'BAR' }
|
81
|
-
|
82
|
-
it 'calls sudo, setarch and env' do
|
83
|
-
expect(chroot).to receive(:system).once.with(any_args) { |*args|
|
84
|
-
expected_opts = opts.dup
|
85
|
-
expected_opts.delete(:env)
|
86
|
-
expect(args).to eq(%W[sudo setarch #{arch} env #{key}=#{value}] + command + [expected_opts])
|
87
|
-
}.and_return(true)
|
88
|
-
|
89
|
-
opts.merge!(env: { key => value })
|
90
|
-
stdout = capture_stdout do
|
91
|
-
chroot.execute(*command, opts)
|
92
|
-
end
|
93
|
-
expect(stdout).to include('rm -rf /')
|
94
|
-
expect(opts).to have_key(:env)
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'with command failure' do
|
98
|
-
before do
|
99
|
-
allow(chroot).to receive(:system).and_return(false)
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'raises an error' do
|
103
|
-
expect { capture_stdout { chroot.execute(command + [opts]) } }.to raise_error(Akabei::ChrootTree::CommandFailed)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
62
|
end
|
data/spec/akabei/cli_spec.rb
CHANGED
@@ -10,29 +10,13 @@ describe Akabei::CLI do
|
|
10
10
|
describe '#build' do
|
11
11
|
let(:repo_dir) { test_dest('repo').tap(&:mkpath) }
|
12
12
|
let(:base_opts) { { arch: 'x86_64', repo_dir: repo_dir.to_s, repo_name: 'test' } }
|
13
|
-
let(:package) { double('built package') }
|
14
|
-
let(:entry) { Akabei::PackageEntry.new }
|
15
|
-
let(:chroot_expectations) { lambda { |chroot| } }
|
16
13
|
|
17
14
|
before do
|
18
15
|
tar('xf', test_input('nkf.tar.gz').to_s, '-C', package_dir.parent.to_s)
|
19
|
-
# Disable warning
|
20
|
-
entry.add('files', 'usr/bin/nkf')
|
21
|
-
|
22
|
-
allow(package).to receive(:name).and_return('nkf')
|
23
|
-
allow(package).to receive(:to_entry).and_return(entry)
|
24
|
-
|
25
|
-
allow_any_instance_of(Akabei::ChrootTree).to receive(:with_chroot) { |chroot, &block|
|
26
|
-
chroot_expectations.call(chroot)
|
27
|
-
block.call
|
28
|
-
}
|
29
|
-
allow_any_instance_of(Akabei::Builder).to receive(:build_package) { |builder, dir, chroot|
|
30
|
-
expect(builder).to receive(:with_source_package).with(package_dir.to_s).and_yield(srcpkg_path)
|
31
|
-
[package]
|
32
|
-
}
|
33
16
|
end
|
34
17
|
|
35
18
|
it 'calls Builder#build_package in chroot and create repository database' do
|
19
|
+
setup_command_expectations('x86_64', package_dir)
|
36
20
|
cli.invoke(:build, [package_dir.to_s], base_opts)
|
37
21
|
expect(repo_dir.join('test.db')).to be_file
|
38
22
|
expect(repo_dir.join('test.files')).to be_file
|
@@ -48,6 +32,7 @@ describe Akabei::CLI do
|
|
48
32
|
}
|
49
33
|
|
50
34
|
it 'calls ChrootTree#with_chroot with makepkg_config' do
|
35
|
+
setup_command_expectations('x86_64', package_dir)
|
51
36
|
cli.invoke(:build, [package_dir.to_s], base_opts.merge(makepkg_config: makepkg_path.to_s))
|
52
37
|
end
|
53
38
|
end
|
@@ -61,9 +46,19 @@ describe Akabei::CLI do
|
|
61
46
|
}
|
62
47
|
|
63
48
|
it 'calls ChrootTree#with_chroot with pacman_config' do
|
49
|
+
setup_command_expectations('x86_64', package_dir)
|
64
50
|
cli.invoke(:build, [package_dir.to_s], base_opts.merge(pacman_config: pacman_path.to_s))
|
65
51
|
end
|
66
52
|
end
|
53
|
+
|
54
|
+
context "when package_dir isn't a directory" do
|
55
|
+
let(:package_dir) { test_dest('does-not-exist') }
|
56
|
+
|
57
|
+
it 'fails early' do
|
58
|
+
expect(Akabei::System).to_not receive(:system)
|
59
|
+
expect { cli.invoke(:build, [package_dir.to_s], base_opts) }.to raise_error(Akabei::Error, /isn't a directory/)
|
60
|
+
end
|
61
|
+
end
|
67
62
|
end
|
68
63
|
|
69
64
|
describe '#abs_add' do
|
@@ -137,4 +132,19 @@ describe Akabei::CLI do
|
|
137
132
|
expect(tar('tf', files_path.to_s)).to_not include('htop-vi-1.0.2-4/files')
|
138
133
|
end
|
139
134
|
end
|
135
|
+
|
136
|
+
describe '#version' do
|
137
|
+
it 'displays version' do
|
138
|
+
stdout = capture_stdout { cli.invoke(:version) }
|
139
|
+
expect(stdout).to include('akabei')
|
140
|
+
expect(stdout).to include(Akabei::VERSION)
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'with --numeric' do
|
144
|
+
it 'displays version number only' do
|
145
|
+
stdout = capture_stdout { cli.invoke(:version, [], numeric: true) }
|
146
|
+
expect(stdout.strip).to eq(Akabei::VERSION)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
140
150
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'akabei/abs'
|
2
3
|
require 'akabei/cli'
|
4
|
+
require 'akabei/repository'
|
3
5
|
|
4
6
|
class TestShell < Thor::Shell::Basic
|
5
7
|
attr_reader :stdout
|
@@ -71,35 +73,17 @@ describe Akabei::Omakase::CLI do
|
|
71
73
|
|
72
74
|
describe '#build' do
|
73
75
|
let(:config) { Akabei::Omakase::Config.load }
|
74
|
-
let(:packages) { { 'i686' => double('built package (i686)'), 'x86_64' => double('built package (x86_64)') } }
|
75
|
-
let(:entry) { Akabei::PackageEntry.new }
|
76
76
|
let(:init_opts) { {} }
|
77
77
|
|
78
78
|
before do
|
79
79
|
cli.invoke(:init, ['test'], init_opts)
|
80
80
|
tar('xf', test_input('nkf.tar.gz').to_s, '-C', config.pkgbuild.to_s)
|
81
|
-
|
82
|
-
packages.each do |arch, package|
|
83
|
-
allow(package).to receive(:name).and_return('nkf')
|
84
|
-
allow(package).to receive(:to_entry).and_return(entry)
|
85
|
-
allow(package).to receive(:path).and_return(Pathname.new("test/os/#{arch}/nkf-2.1.3-1-#{arch}.pkg.tar.xz"))
|
86
|
-
end
|
87
|
-
entry.add('files', 'usr/bin/nkf')
|
88
|
-
|
89
|
-
allow_any_instance_of(Akabei::ChrootTree).to receive(:with_chroot) { |chroot, &block|
|
90
|
-
expect(chroot.makepkg_config.to_s).to eq("etc/makepkg.#{chroot.arch}.conf")
|
91
|
-
expect(chroot.pacman_config.to_s).to eq("etc/pacman.#{chroot.arch}.conf")
|
92
|
-
block.call
|
93
|
-
}
|
94
|
-
expect(config['builds'].size).to eq(2)
|
95
|
-
|
96
|
-
allow_any_instance_of(Akabei::Builder).to receive(:build_package) { |builder, dir, chroot|
|
97
|
-
expect(builder).to receive(:with_source_package).with(config.package_dir('nkf')).and_yield(test_input('nkf.tar.gz'))
|
98
|
-
[packages[chroot.arch]]
|
99
|
-
}
|
100
81
|
end
|
101
82
|
|
102
83
|
it 'builds a package and add it to repository' do
|
84
|
+
%w[i686 x86_64].each do |arch|
|
85
|
+
setup_command_expectations(arch, config.package_dir('nkf'))
|
86
|
+
end
|
103
87
|
cli.invoke(:build, ['nkf'])
|
104
88
|
end
|
105
89
|
|
@@ -128,6 +112,9 @@ describe Akabei::Omakase::CLI do
|
|
128
112
|
end
|
129
113
|
|
130
114
|
it 'uploads built packages and update repositories' do
|
115
|
+
%w[i686 x86_64].each do |arch|
|
116
|
+
setup_command_expectations(arch, config.package_dir('nkf'))
|
117
|
+
end
|
131
118
|
expect(buckets).to receive(:[]).with(bucket_name).and_return(bucket)
|
132
119
|
allow(bucket).to receive(:objects).and_return(objects)
|
133
120
|
|
@@ -150,5 +137,40 @@ describe Akabei::Omakase::CLI do
|
|
150
137
|
cli.invoke(:build, ['nkf'])
|
151
138
|
end
|
152
139
|
end
|
140
|
+
|
141
|
+
context 'when PACKAGE_NAME is wrong' do
|
142
|
+
it 'fails early' do
|
143
|
+
expect(Akabei::System).to_not receive(:system)
|
144
|
+
expect { cli.invoke(:build, ['wrong']) }.to raise_error(Akabei::Error)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe '#remove' do
|
150
|
+
let(:config) { Akabei::Omakase::Config.load }
|
151
|
+
|
152
|
+
it 'removes package' do
|
153
|
+
cli.invoke(:init, ['test'])
|
154
|
+
%w[i686 x86_64].each do |arch|
|
155
|
+
config.repo_path(arch).mkpath
|
156
|
+
FileUtils.cp(test_input('test.db'), config.db_path(arch))
|
157
|
+
FileUtils.cp(test_input('test.files'), config.files_path(arch))
|
158
|
+
FileUtils.cp(test_input('abs.tar.gz'), config.abs_path(arch))
|
159
|
+
end
|
160
|
+
|
161
|
+
%w[i686 x86_64].each do |arch|
|
162
|
+
expect(tar('tf', config.db_path(arch).to_s)).to include('htop-vi-1.0.2-4/desc')
|
163
|
+
expect(tar('tf', config.files_path(arch).to_s)).to include('htop-vi-1.0.2-4/files')
|
164
|
+
expect(tar('tf', config.abs_path(arch).to_s)).to include('test/htop-vi/PKGBUILD')
|
165
|
+
end
|
166
|
+
|
167
|
+
cli.invoke(:remove, ['htop-vi'])
|
168
|
+
|
169
|
+
%w[i686 x86_64].each do |arch|
|
170
|
+
expect(tar('tf', config.db_path(arch).to_s)).to_not include('htop-vi-1.0.2-4/desc')
|
171
|
+
expect(tar('tf', config.files_path(arch).to_s)).to_not include('htop-vi-1.0.2-4/files')
|
172
|
+
expect(tar('tf', config.abs_path(arch).to_s)).to_not include('test/htop-vi/PKGBUILD')
|
173
|
+
end
|
174
|
+
end
|
153
175
|
end
|
154
176
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'akabei/system'
|
3
|
+
|
4
|
+
describe Akabei::System do
|
5
|
+
let(:command) { %w[rm -rf /] }
|
6
|
+
let(:options) { { chdir: '/' } }
|
7
|
+
|
8
|
+
describe '.sudo' do
|
9
|
+
it 'executes sudo' do
|
10
|
+
expect(Akabei::System).to receive(:system) { |args, opts|
|
11
|
+
expect(args).to eq(%w[sudo] + command)
|
12
|
+
expect(opts).to eq(options)
|
13
|
+
}
|
14
|
+
|
15
|
+
stdout = capture_stdout do
|
16
|
+
described_class.sudo(command, options)
|
17
|
+
end
|
18
|
+
expect(stdout).to include('rm -rf /')
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with :env keyword' do
|
22
|
+
let(:key) { :FOO }
|
23
|
+
let(:value) { 'BAR' }
|
24
|
+
|
25
|
+
it 'executes sudo and env' do
|
26
|
+
expect(Akabei::System).to receive(:system) { |args, opts|
|
27
|
+
expect(args).to eq(%W[sudo env #{key}=#{value}] + command)
|
28
|
+
expect(opts).to_not have_key(:env)
|
29
|
+
}
|
30
|
+
|
31
|
+
options.merge!(env: { key => value })
|
32
|
+
stdout = capture_stdout do
|
33
|
+
described_class.sudo(command, options)
|
34
|
+
end
|
35
|
+
expect(stdout).to include('rm -rf /')
|
36
|
+
expect(options).to have_key(:env)
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with command failure' do
|
40
|
+
before do
|
41
|
+
allow(Kernel).to receive(:system).and_return(false)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'raises an error' do
|
45
|
+
expect { capture_stdout { described_class.sudo(command, options) } }.to raise_error(Akabei::System::CommandFailed)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '.system' do
|
52
|
+
context 'with :arch keyword' do
|
53
|
+
let(:arch) { 'armv7h' }
|
54
|
+
|
55
|
+
it 'executes sudo and setarch' do
|
56
|
+
expect(Kernel).to receive(:system) { |*args|
|
57
|
+
args = args.dup
|
58
|
+
env = args.shift
|
59
|
+
opts = args.pop
|
60
|
+
expect(args).to eq(%W[setarch #{arch}] + command)
|
61
|
+
expect(opts).to_not have_key(:arch)
|
62
|
+
true
|
63
|
+
}
|
64
|
+
|
65
|
+
options.merge!(arch: arch)
|
66
|
+
described_class.system(command, options)
|
67
|
+
expect(options).to have_key(:arch)
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'with command failure' do
|
71
|
+
before do
|
72
|
+
allow(Kernel).to receive(:system).and_return(false)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'raises an error' do
|
76
|
+
expect { described_class.system(command, options) }.to raise_error(Akabei::System::CommandFailed)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -75,12 +75,48 @@ module TarHelpers
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
module ArrayStartingWith
|
79
|
+
class Matcher
|
80
|
+
def initialize(expected)
|
81
|
+
@expected = expected
|
82
|
+
end
|
83
|
+
|
84
|
+
def description
|
85
|
+
"array_starting_with(#{@expected.join(',')})"
|
86
|
+
end
|
87
|
+
|
88
|
+
def ==(actual)
|
89
|
+
actual[0 ... @expected.length] == @expected
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def array_starting_with(expected)
|
94
|
+
Matcher.new(expected)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
78
98
|
module IntegrationSpecHelper
|
79
99
|
def akabei(*cmd)
|
80
100
|
system(File.expand_path('../../bin/akabei', __FILE__), *cmd)
|
81
101
|
end
|
82
102
|
end
|
83
103
|
|
104
|
+
module BuildSpecHelper
|
105
|
+
def setup_command_expectations(arch, package_dir)
|
106
|
+
expect(Akabei::System).to receive(:sudo).with(array_starting_with(['mkarchroot']), hash_including(arch: arch))
|
107
|
+
expect(Akabei::System).to receive(:sudo).with(['rm', '-rf', anything], {})
|
108
|
+
|
109
|
+
expect(Akabei::System).to receive(:sudo).with(['makechrootpkg', '-cur', anything], hash_including(arch: arch, chdir: package_dir)) { |args, opts|
|
110
|
+
FileUtils.cp(test_input('nkf-2.1.3-1-x86_64.pkg.tar.xz'), opts[:env][:PKGDEST].join("nkf-2.1.3-1-#{arch}.pkg.tar.xz"))
|
111
|
+
}
|
112
|
+
expect(Akabei::System).to receive(:system).with(['makepkg', '--source'], hash_including(chdir: package_dir)) { |args, opts|
|
113
|
+
# Simulate `makepkg --source`
|
114
|
+
FileUtils.cp(test_input('nkf.tar.gz'), opts[:env][:SRCPKGDEST])
|
115
|
+
Pathname.new(opts[:chdir]).join('nkf.tar.gz').make_symlink(opts[:env][:SRCPKGDEST])
|
116
|
+
}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
84
120
|
RSpec.configure do |config|
|
85
121
|
config.filter_run :focus
|
86
122
|
if ENV['AKABEI_ARCH_SPEC']
|
@@ -107,4 +143,6 @@ RSpec.configure do |config|
|
|
107
143
|
config.include OutputHelpers
|
108
144
|
config.include TarHelpers
|
109
145
|
config.include IntegrationSpecHelper
|
146
|
+
config.include ArrayStartingWith
|
147
|
+
config.include BuildSpecHelper
|
110
148
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: akabei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gpgme
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- lib/akabei/package_info.rb
|
191
191
|
- lib/akabei/repository.rb
|
192
192
|
- lib/akabei/signer.rb
|
193
|
+
- lib/akabei/system.rb
|
193
194
|
- lib/akabei/thor_handler.rb
|
194
195
|
- lib/akabei/version.rb
|
195
196
|
- spec/akabei/abs_spec.rb
|
@@ -203,6 +204,7 @@ files:
|
|
203
204
|
- spec/akabei/package_spec.rb
|
204
205
|
- spec/akabei/repository_spec.rb
|
205
206
|
- spec/akabei/signer_spec.rb
|
207
|
+
- spec/akabei/system_spec.rb
|
206
208
|
- spec/data/input/abs.tar.gz
|
207
209
|
- spec/data/input/htop-vi.tar.gz
|
208
210
|
- spec/data/input/makepkg.x86_64.conf
|
@@ -251,6 +253,7 @@ test_files:
|
|
251
253
|
- spec/akabei/package_spec.rb
|
252
254
|
- spec/akabei/repository_spec.rb
|
253
255
|
- spec/akabei/signer_spec.rb
|
256
|
+
- spec/akabei/system_spec.rb
|
254
257
|
- spec/data/input/abs.tar.gz
|
255
258
|
- spec/data/input/htop-vi.tar.gz
|
256
259
|
- spec/data/input/makepkg.x86_64.conf
|