dr 0.2.5 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dr +170 -35
- data/dr.conf-example +15 -0
- data/lib/dr/{distros.rb → build_environments.rb} +27 -11
- data/lib/dr/buildroot.rb +74 -35
- data/lib/dr/config.rb +6 -6
- data/lib/dr/gitpackage.rb +47 -6
- data/lib/dr/package.rb +8 -0
- data/lib/dr/repo.rb +35 -23
- data/lib/dr/utils.rb +42 -0
- data/lib/dr/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48dfeab96a546a1ea867447378a4db3d2004a87a
|
4
|
+
data.tar.gz: f9002254094f0d190ce164e74c39118e44a0aaee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93d864a9d2c275c1c90bee88d8f2d91c91797659c86648183fb8df996a71ec6563ce801b553775598d3a28e35bd1836ff49270b72c22365e2f0cf21e2d71a244
|
7
|
+
data.tar.gz: 0eaa169652f489a898171edb18758306c276a46bd149260fb425bf7d94fb7683067dad0e6dd16fd91eb074d19992631d08ad9942ac43bdfa18eb707980bcb6fc
|
data/bin/dr
CHANGED
@@ -12,6 +12,7 @@ require "dr/repo"
|
|
12
12
|
require "dr/gitpackage"
|
13
13
|
require "dr/debpackage"
|
14
14
|
require "dr/buildroot"
|
15
|
+
require "dr/pkgversion"
|
15
16
|
|
16
17
|
require "dr/shellcmd"
|
17
18
|
require "dr/logger"
|
@@ -59,6 +60,79 @@ class Archive < ExtendedThor
|
|
59
60
|
#end
|
60
61
|
end
|
61
62
|
|
63
|
+
class Conf < ExtendedThor
|
64
|
+
desc "repo", "Configuration of the whole repository"
|
65
|
+
def repo(key, value=nil)
|
66
|
+
repo = get_repo_handle
|
67
|
+
|
68
|
+
metadata = repo.get_configuration
|
69
|
+
|
70
|
+
if value == nil
|
71
|
+
value = dot_get_value metadata, key
|
72
|
+
puts value if value
|
73
|
+
else
|
74
|
+
repo.set_configuration dot_set_value metadata, key, value
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "package", "Package-specific configuration options"
|
79
|
+
def package(pkg_name, key, value=nil)
|
80
|
+
repo = get_repo_handle
|
81
|
+
pkg = repo.get_package pkg_name
|
82
|
+
|
83
|
+
metadata = pkg.get_configuration
|
84
|
+
|
85
|
+
if value == nil
|
86
|
+
value = dot_get_value metadata, key
|
87
|
+
puts value if value
|
88
|
+
else
|
89
|
+
pkg.set_configuration dot_set_value metadata, key, value
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
def dot_set_value(dict, key, value)
|
95
|
+
levels = key.split(".").map {|l| l.to_sym}
|
96
|
+
raise "Incorrect key" if levels.length == 0
|
97
|
+
|
98
|
+
begin
|
99
|
+
last = levels.pop
|
100
|
+
object = dict
|
101
|
+
levels.each do |l|
|
102
|
+
object[l] = {} unless object.has_key? l
|
103
|
+
object = object[l]
|
104
|
+
end
|
105
|
+
|
106
|
+
if value.length > 0
|
107
|
+
object[last] = value
|
108
|
+
else
|
109
|
+
object.delete last
|
110
|
+
end
|
111
|
+
rescue
|
112
|
+
log :err, "The configuration key '#{key}' isn't right"
|
113
|
+
raise "Incorrect key"
|
114
|
+
end
|
115
|
+
|
116
|
+
dict
|
117
|
+
end
|
118
|
+
|
119
|
+
def dot_get_value(dict, key)
|
120
|
+
levels = key.split(".").map {|l| l.to_sym}
|
121
|
+
raise "Incorrect key" if levels.length == 0
|
122
|
+
|
123
|
+
begin
|
124
|
+
last = levels.pop
|
125
|
+
object = dict
|
126
|
+
levels.each do |l|
|
127
|
+
object = object[l]
|
128
|
+
end
|
129
|
+
return object[last]
|
130
|
+
rescue
|
131
|
+
log :err, "The configuration key '#{key}' isn't right"
|
132
|
+
raise "Incorrect key"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
62
136
|
|
63
137
|
class List < ExtendedThor
|
64
138
|
desc "packages", "Show a list of source packages in the repo"
|
@@ -71,11 +145,16 @@ class List < ExtendedThor
|
|
71
145
|
end
|
72
146
|
end
|
73
147
|
|
74
|
-
|
75
|
-
desc "versions PACKAGE", "Show the history of all available versions for a package"
|
148
|
+
desc "versions PACKAGE", "DEPRECATED, please use builds instead"
|
76
149
|
def versions(pkg_name)
|
150
|
+
log :warn, "This subcommand is deprecated, please use builds instead"
|
151
|
+
builds pkg_name
|
152
|
+
end
|
153
|
+
|
154
|
+
desc "builds PACKAGE", "Show the history of all builds of a package"
|
155
|
+
def builds(pkg_name)
|
77
156
|
repo = get_repo_handle
|
78
|
-
log :info, "Listing all
|
157
|
+
log :info, "Listing all buils of #{pkg_name.style "pkg-name"}"
|
79
158
|
|
80
159
|
suites = repo.get_suites
|
81
160
|
|
@@ -178,7 +257,7 @@ class RepoCLI < ExtendedThor
|
|
178
257
|
:arches => ["amd64"],
|
179
258
|
:components => ["main"],
|
180
259
|
:suites => ["stable", "testing", "unstable"],
|
181
|
-
:
|
260
|
+
:build_environment => :kano,
|
182
261
|
:codenames => []
|
183
262
|
}
|
184
263
|
|
@@ -188,40 +267,38 @@ class RepoCLI < ExtendedThor
|
|
188
267
|
desc = ask " Description [#{repo_conf[:desc]}]:"
|
189
268
|
repo_conf[:desc] = desc if desc.length > 0
|
190
269
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
distro_name = distro[0]
|
195
|
-
distro_map[index+1] = distro_name
|
196
|
-
|
197
|
-
distro_name = distro_name.fg "yellow" if distro_name == repo_conf[:distro]
|
198
|
-
puts " [#{index+1}] #{distro_name}"
|
270
|
+
puts " Default build environment [pick one]: "
|
271
|
+
Dr::config.build_environments.each do |id, benv|
|
272
|
+
puts " [#{id.to_s.fg "blue"}] #{benv[:name]}"
|
199
273
|
end
|
200
274
|
|
201
|
-
|
202
|
-
|
203
|
-
|
275
|
+
benv = nil
|
276
|
+
loop do
|
277
|
+
benv_str = ask " Your choice [#{repo_conf[:build_environment].to_s.fg "yellow"}]:"
|
278
|
+
benv = benv_str.to_sym
|
279
|
+
break if Dr::config.build_environments.has_key? benv_str.to_sym
|
204
280
|
end
|
205
|
-
repo_conf[:
|
281
|
+
repo_conf[:build_environment] = benv
|
206
282
|
|
207
|
-
|
208
|
-
|
209
|
-
pp Dr::config.distros
|
210
|
-
pp Dr::config.distros[repo_conf[:distro]]
|
211
|
-
repo_conf[:arches] = [Dr::config.distros[repo_conf[:distro]][:arches][0]]
|
283
|
+
# guess repo arches
|
284
|
+
repo_conf[:arches] = Dr::config.build_environments[benv][:arches]
|
212
285
|
|
213
|
-
|
286
|
+
loop do
|
214
287
|
str = ask " Architectures [#{repo_conf[:arches].join(" ").fg("yellow")}]:"
|
215
288
|
break if str.length == 0
|
216
289
|
|
290
|
+
# Determine the available architectures
|
291
|
+
avail = Dr.config.build_environments[benv][:arches]
|
292
|
+
|
217
293
|
arches = str.split(/\s+/)
|
218
294
|
arches_valid = arches.reduce(true) do |acc, arch|
|
219
|
-
|
220
|
-
|
221
|
-
|
295
|
+
if !avail.include?(arch)
|
296
|
+
puts " " + "#{arch.fg "yellow"}" +
|
297
|
+
" not supported by the build environments you selected"
|
298
|
+
acc = false
|
222
299
|
end
|
223
300
|
|
224
|
-
|
301
|
+
acc
|
225
302
|
end
|
226
303
|
next if !arches_valid
|
227
304
|
|
@@ -321,7 +398,7 @@ class RepoCLI < ExtendedThor
|
|
321
398
|
desc "push [pkg-name]", "push a built package to a specified suite"
|
322
399
|
method_option :suite, :aliases => "-s", :type => :string,
|
323
400
|
:desc => "the target suite (defaults to testing)"
|
324
|
-
method_option :
|
401
|
+
method_option :build, :aliases => "-b", :type => :string,
|
325
402
|
:desc => "which version to push (defaults to the highest one build)"
|
326
403
|
method_option :force, :aliases => "-f", :type => :boolean,
|
327
404
|
:desc => "force inclusion of the package to the suite"
|
@@ -332,7 +409,7 @@ class RepoCLI < ExtendedThor
|
|
332
409
|
suite = options["suite"] if options.has_key? "suite"
|
333
410
|
|
334
411
|
version = nil
|
335
|
-
version = options["
|
412
|
+
version = options["build"] if options.has_key? "build"
|
336
413
|
|
337
414
|
repo.push pkg_name, version, suite, options["force"] == true
|
338
415
|
end
|
@@ -344,11 +421,15 @@ class RepoCLI < ExtendedThor
|
|
344
421
|
repo.unpush pkg_name, suite
|
345
422
|
end
|
346
423
|
|
347
|
-
|
348
424
|
desc "list SUBCOMMAND [ARGS]", "show information about packages"
|
349
425
|
map "l" => :list, "ls" => :list
|
350
426
|
subcommand "list", List
|
351
427
|
|
428
|
+
|
429
|
+
desc "config SUBCOMMAND [ARGS]", "configure your repository"
|
430
|
+
map "c" => :config, "conf" => :config, "configure" => :config
|
431
|
+
subcommand "config", Conf
|
432
|
+
|
352
433
|
desc "rm [pkg-name]", "remove a package completely from the build system"
|
353
434
|
method_option :force, :aliases => "-f", :type => :boolean,
|
354
435
|
:desc => "force removal even if the package is still used"
|
@@ -459,25 +540,75 @@ class RepoCLI < ExtendedThor
|
|
459
540
|
|
460
541
|
|
461
542
|
desc "force-sync", "Force cloning the sources repository from scratch again"
|
543
|
+
method_option :url, :aliases => "-u", :type => :string,
|
544
|
+
:desc => "The URL to clone from"
|
545
|
+
method_option :branch, :aliases => "-b", :type => :string,
|
546
|
+
:desc => "The default branch to use for building"
|
462
547
|
def force_sync(pkg_name)
|
463
548
|
repo = get_repo_handle
|
464
549
|
pkg = repo.get_package pkg_name
|
465
550
|
|
466
551
|
if pkg.is_a? Dr::GitPackage
|
467
|
-
pkg.reinitialise_repo
|
552
|
+
pkg.reinitialise_repo options["url"], options["branch"]
|
468
553
|
else
|
469
554
|
raise "The source of #{pkg_name.style "pkg-name"} is not managed by " +
|
470
555
|
"#{"dr".bright}"
|
471
556
|
end
|
472
557
|
end
|
473
558
|
|
474
|
-
desc "snapshot", "save a snapshot of the archive"
|
475
|
-
def snapshot(tag)
|
559
|
+
#desc "snapshot", "save a snapshot of the archive"
|
560
|
+
#def snapshot(tag)
|
561
|
+
# repo = get_repo_handle
|
562
|
+
#end
|
563
|
+
|
564
|
+
desc "cleanup", "Remove builds beyond certain date or number"
|
565
|
+
method_option :package, :aliases => "-p", :type => :string,
|
566
|
+
:desc => "Cleanup this package only"
|
567
|
+
method_option :date, :aliases => "-d", :type => :string,
|
568
|
+
:desc => "Remove builds beyond this date (YYYYMMDD)"
|
569
|
+
method_option :number, :aliases => "-n", :type => :string,
|
570
|
+
:desc => "Keep only N newest builds"
|
571
|
+
def cleanup
|
476
572
|
repo = get_repo_handle
|
477
573
|
|
478
|
-
|
479
|
-
|
480
|
-
|
574
|
+
if options["date"] != nil && options["number"] != nil
|
575
|
+
log :err, "Can't use -n and -d at the same time"
|
576
|
+
raise "Bad arguments"
|
577
|
+
end
|
578
|
+
|
579
|
+
date = options["date"]
|
580
|
+
number = options["number"]
|
581
|
+
|
582
|
+
if options["date"] == nil && options["number"] == nil
|
583
|
+
number = 10
|
584
|
+
end
|
585
|
+
|
586
|
+
packages = unless options["package"] == nil
|
587
|
+
[repo.get_package(options["package"])]
|
588
|
+
else
|
589
|
+
repo.list_packages
|
590
|
+
end
|
591
|
+
|
592
|
+
packages.each do |pkg|
|
593
|
+
kept = 0
|
594
|
+
pkg.history.each do |version_string|
|
595
|
+
# Can't remove a used build
|
596
|
+
if repo.is_used? pkg.name, version_string
|
597
|
+
kept += 1
|
598
|
+
next
|
599
|
+
end
|
600
|
+
|
601
|
+
if date != nil
|
602
|
+
version = Dr::PkgVersion.new version_string
|
603
|
+
if version.date.to_i < date.to_i
|
604
|
+
rmbuild pkg.name, version_string
|
605
|
+
end
|
606
|
+
elsif number != nil && kept >= number.to_i
|
607
|
+
rmbuild pkg.name, version_string
|
608
|
+
else
|
609
|
+
kept += 1
|
610
|
+
end
|
611
|
+
end
|
481
612
|
end
|
482
613
|
end
|
483
614
|
end
|
@@ -493,4 +624,8 @@ begin
|
|
493
624
|
RepoCLI.start ARGV
|
494
625
|
rescue StandardError => e
|
495
626
|
Dr::Logger.log :err, e.to_s
|
627
|
+
e.backtrace.each do |line|
|
628
|
+
line = " #{line}" if line.length > 0 && line[0] == '/'
|
629
|
+
Dr::Logger.log :err, line.fg("grey")
|
630
|
+
end
|
496
631
|
end
|
data/dr.conf-example
CHANGED
@@ -9,3 +9,18 @@ repositories:
|
|
9
9
|
|
10
10
|
- name: "sandbox"
|
11
11
|
location: "/path/to/the/sandbox/repo"
|
12
|
+
|
13
|
+
build_environments:
|
14
|
+
basic_wheezy:
|
15
|
+
name: "Test Build Environment"
|
16
|
+
arches: [armhf, x86_64]
|
17
|
+
repos:
|
18
|
+
wheezy:
|
19
|
+
url: "http://ftp.uk.debian.org/debian/"
|
20
|
+
key: "https://ftp-master.debian.org/keys/archive-key-7.0.asc"
|
21
|
+
src: false
|
22
|
+
codename: wheezy
|
23
|
+
components: main nonfree
|
24
|
+
base_repo: wheezy
|
25
|
+
packages: []
|
26
|
+
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# Copyright (C) 2014 Kano Computing Ltd.
|
2
2
|
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
|
3
3
|
|
4
|
-
|
5
4
|
module Dr
|
6
|
-
module
|
7
|
-
@@
|
8
|
-
|
9
|
-
:
|
5
|
+
module BuildEnvironments
|
6
|
+
@@build_environments = {
|
7
|
+
:kano => {
|
8
|
+
:name =>"Kano OS",
|
9
|
+
:arches => ["armhf"],
|
10
10
|
:repos => {
|
11
11
|
:raspbian => {
|
12
12
|
:url => "http://mirror.ox.ac.uk/sites/archive.raspbian.org/archive/raspbian/",
|
@@ -17,8 +17,8 @@ module Dr
|
|
17
17
|
},
|
18
18
|
|
19
19
|
:raspi_foundation => {
|
20
|
-
:url => "http://
|
21
|
-
:key => "http://
|
20
|
+
:url => "http://dev.kano.me/mirrors/raspberrypi/",
|
21
|
+
:key => "http://dev.kano.me/mirrors/raspberrypi/raspberrypi.gpg.key",
|
22
22
|
:src => false,
|
23
23
|
:codename => "wheezy",
|
24
24
|
:components => "main"
|
@@ -34,15 +34,31 @@ module Dr
|
|
34
34
|
},
|
35
35
|
:base_repo => :raspbian,
|
36
36
|
:packages => []
|
37
|
+
},
|
38
|
+
|
39
|
+
:wheezy => {
|
40
|
+
:name => "Debian Wheezy",
|
41
|
+
:arches => ["x86_64"],
|
42
|
+
:repos => {
|
43
|
+
:wheezy => {
|
44
|
+
:url => "http://ftp.uk.debian.org/debian/",
|
45
|
+
:key => "https://ftp-master.debian.org/keys/archive-key-7.0.asc",
|
46
|
+
:src => true,
|
47
|
+
:codename => "wheezy",
|
48
|
+
:components => "main contrib non-free"
|
49
|
+
}
|
50
|
+
},
|
51
|
+
:base_repo => :wheezy,
|
52
|
+
:packages => []
|
37
53
|
}
|
38
54
|
}
|
39
55
|
|
40
|
-
def
|
41
|
-
@@
|
56
|
+
def build_environments
|
57
|
+
@@build_environments
|
42
58
|
end
|
43
59
|
|
44
|
-
def
|
45
|
-
@@
|
60
|
+
def add_build_environment(name, benv)
|
61
|
+
@@build_environments[name.to_sym] = benv
|
46
62
|
end
|
47
63
|
end
|
48
64
|
end
|
data/lib/dr/buildroot.rb
CHANGED
@@ -11,23 +11,31 @@ module Dr
|
|
11
11
|
class BuildRoot
|
12
12
|
include Logger
|
13
13
|
|
14
|
-
def initialize(
|
15
|
-
@location = "#{br_cache}/#{base.strip.downcase.gsub(" ", "_")}-#{arch}.tar.gz"
|
16
|
-
@base = base
|
14
|
+
def initialize(env, arch, br_cache)
|
17
15
|
@arch = arch
|
16
|
+
if arch == "all"
|
17
|
+
unless Dr::config.build_environments.has_key? env
|
18
|
+
log :err, "Unkown build environment: #{env.to_s.fg "red"}"
|
19
|
+
raise "Build environment not recognised"
|
20
|
+
end
|
21
|
+
@arch = Dr::config.build_environments[env][:arches][0]
|
22
|
+
end
|
23
|
+
|
24
|
+
@location = "#{br_cache}/#{env.to_s}-#{@arch}.tar.gz"
|
25
|
+
@env = env
|
18
26
|
|
19
27
|
@essential_pkgs = "sudo,vim,ca-certificates,fakeroot,build-essential," +
|
20
28
|
"curl,devscripts,debhelper,git,bc,locales,equivs," +
|
21
29
|
"pkg-config,libfile-fcntllock-perl"
|
22
30
|
|
23
|
-
|
24
|
-
setup
|
31
|
+
unless File.exists?(@location)
|
32
|
+
setup @env, @arch
|
25
33
|
end
|
26
34
|
end
|
27
35
|
|
28
36
|
def open
|
29
37
|
Dir.mktmpdir do |tmp|
|
30
|
-
log :info, "Preparing #{@
|
38
|
+
log :info, "Preparing #{@env.to_s.fg "blue"} #{@arch.fg "orange"} build root"
|
31
39
|
ShellCmd.new "sudo tar xz -C #{tmp} -f #{@location}", :tag => "tar"
|
32
40
|
begin
|
33
41
|
log :info, "Mounting the /proc file system"
|
@@ -46,18 +54,16 @@ module Dr
|
|
46
54
|
end
|
47
55
|
|
48
56
|
private
|
49
|
-
def setup(
|
50
|
-
unless Dr.config.
|
51
|
-
raise "Sorry,
|
57
|
+
def setup(env, arch)
|
58
|
+
unless Dr.config.build_environments.has_key? env
|
59
|
+
raise "Sorry, build environment #{env.to_s.fg "blue"} isn't supported by dr."
|
52
60
|
end
|
53
61
|
|
54
|
-
unless Dr.config.
|
55
|
-
raise "Arch #{arch.fg "blue"} not supported by this
|
62
|
+
unless Dr.config.build_environments[env][:arches].include? arch
|
63
|
+
raise "Arch #{arch.fg "blue"} not supported by this build environment."
|
56
64
|
end
|
57
65
|
|
58
|
-
repos = Dr.config.
|
59
|
-
base_repo = Dr.config.distros[base][:base_repo].to_sym
|
60
|
-
additional_pkgs = Dr.config.distros[base][:packages].join ","
|
66
|
+
repos = Dr.config.build_environments[env][:repos]
|
61
67
|
|
62
68
|
Dir.mktmpdir do |tmp|
|
63
69
|
broot = "#{tmp}/broot"
|
@@ -66,30 +72,15 @@ module Dr
|
|
66
72
|
log :info, "Setting up the buildroot"
|
67
73
|
|
68
74
|
begin
|
69
|
-
|
70
|
-
|
71
|
-
cmd = "sudo debootstrap --foreign --variant=buildd --no-check-gpg " +
|
72
|
-
"--include=#{@essential_pkgs},#{additional_pkgs} " +
|
73
|
-
"--arch=#{arch} wheezy #{broot} #{repos[base_repo][:url]}"
|
74
|
-
debootsrap = ShellCmd.new cmd, {
|
75
|
-
:tag => "debootstrap",
|
76
|
-
:show_out => true
|
77
|
-
}
|
75
|
+
arch_cmd = ShellCmd.new "arch"
|
76
|
+
arch = arch_cmd.out.strip
|
78
77
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}
|
78
|
+
if @arch == arch
|
79
|
+
setup_native broot
|
80
|
+
else
|
81
|
+
setup_foreign broot
|
84
82
|
end
|
85
83
|
|
86
|
-
log :info, "Bootstrapping Raspian (#{arch} stage)"
|
87
|
-
cmd = "sudo chroot #{broot} /debootstrap/debootstrap --second-stage"
|
88
|
-
debootstrap = ShellCmd.new cmd, {
|
89
|
-
:tag => "debootstrap",
|
90
|
-
:show_out => true
|
91
|
-
}
|
92
|
-
|
93
84
|
log :info, "Configuring the build root"
|
94
85
|
|
95
86
|
repo_setup_sequences = repos.map do |name, repo|
|
@@ -141,5 +132,53 @@ EOF"
|
|
141
132
|
end
|
142
133
|
end
|
143
134
|
end
|
135
|
+
|
136
|
+
def setup_foreign(broot)
|
137
|
+
repos = Dr.config.build_environments[@env][:repos]
|
138
|
+
base_repo = Dr.config.build_environments[@env][:base_repo].to_sym
|
139
|
+
additional_pkgs = Dr.config.build_environments[@env][:packages].join ","
|
140
|
+
codename = repos[base_repo][:codename]
|
141
|
+
url = repos[base_repo][:url]
|
142
|
+
|
143
|
+
log :info, "Bootstrapping #{@env.to_s} (foreign chroot, first stage)"
|
144
|
+
cmd = "sudo debootstrap --foreign --variant=buildd --no-check-gpg " +
|
145
|
+
"--include=#{@essential_pkgs},#{additional_pkgs} " +
|
146
|
+
"--arch=#{@arch} #{codename} #{broot} #{url}"
|
147
|
+
debootsrap = ShellCmd.new cmd, {
|
148
|
+
:tag => "debootstrap",
|
149
|
+
:show_out => true
|
150
|
+
}
|
151
|
+
|
152
|
+
static_qemu = Dir["/usr/bin/qemu-*-static"]
|
153
|
+
static_qemu.each do |path|
|
154
|
+
cp = ShellCmd.new "sudo cp #{path} #{broot}/usr/bin", {
|
155
|
+
:tag => "cp"
|
156
|
+
}
|
157
|
+
end
|
158
|
+
|
159
|
+
log :info, "Bootstrapping Raspian (#{@arch} stage)"
|
160
|
+
cmd = "sudo chroot #{broot} /debootstrap/debootstrap --second-stage"
|
161
|
+
debootstrap = ShellCmd.new cmd, {
|
162
|
+
:tag => "debootstrap",
|
163
|
+
:show_out => true
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
167
|
+
def setup_native(broot)
|
168
|
+
repos = Dr.config.build_environments[@env][:repos]
|
169
|
+
base_repo = Dr.config.build_environments[@env][:base_repo].to_sym
|
170
|
+
additional_pkgs = Dr.config.build_environments[@env][:packages].join ","
|
171
|
+
codename = repos[base_repo][:codename]
|
172
|
+
url = repos[base_repo][:url]
|
173
|
+
|
174
|
+
log :info, "Bootstrapping #{@env.to_s} (native chroot)"
|
175
|
+
cmd = "sudo debootstrap --variant=buildd --no-check-gpg " +
|
176
|
+
"--include=#{@essential_pkgs},#{additional_pkgs} " +
|
177
|
+
"#{codename} #{broot} #{repos[base_repo][:url]}"
|
178
|
+
debootsrap = ShellCmd.new cmd, {
|
179
|
+
:tag => "debootstrap",
|
180
|
+
:show_out => true
|
181
|
+
}
|
182
|
+
end
|
144
183
|
end
|
145
184
|
end
|
data/lib/dr/config.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
|
4
4
|
require "yaml"
|
5
5
|
|
6
|
-
require "dr/
|
6
|
+
require "dr/build_environments"
|
7
7
|
|
8
8
|
module Dr
|
9
9
|
class Config
|
10
10
|
attr_reader :default_repo, :repositories
|
11
11
|
|
12
|
-
include
|
12
|
+
include BuildEnvironments
|
13
13
|
|
14
14
|
def initialize(locations)
|
15
15
|
@default_repo = nil
|
@@ -47,10 +47,10 @@ module Dr
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
if conf_file.has_key? "
|
51
|
-
conf_file["
|
52
|
-
|
53
|
-
|
50
|
+
if conf_file.has_key? "build_environments"
|
51
|
+
conf_file["build_environments"].each do |id, be|
|
52
|
+
be_sym_keys = be.inject({}) { |memo,(k,v)| memo[k.to_sym] = v; memo }
|
53
|
+
add_build_environment(id, be_sym_keys)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
data/lib/dr/gitpackage.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
require "dr/package"
|
5
5
|
require "dr/pkgversion"
|
6
6
|
require "dr/shellcmd"
|
7
|
+
require "dr/utils"
|
7
8
|
|
8
9
|
require "yaml"
|
9
10
|
require "octokit"
|
@@ -70,8 +71,9 @@ module Dr
|
|
70
71
|
@default_branch = get_current_branch
|
71
72
|
end
|
72
73
|
|
73
|
-
def reinitialise_repo
|
74
|
-
git_addr
|
74
|
+
def reinitialise_repo(git_addr=nil, branch=nil)
|
75
|
+
git_addr ||= get_repo_url
|
76
|
+
branch ||= @default_branch
|
75
77
|
|
76
78
|
log :info, "Re-downloading the source repository of " +
|
77
79
|
"#{@name.style "pkg-name"}"
|
@@ -83,7 +85,7 @@ module Dr
|
|
83
85
|
src_dir = "#{tmp}/src"
|
84
86
|
FileUtils.mkdir_p src_dir
|
85
87
|
|
86
|
-
checkout
|
88
|
+
checkout branch, src_dir
|
87
89
|
|
88
90
|
unless File.exists? "#{tmp}/src/debian/control"
|
89
91
|
log :err, "The debian packaging files not found in the repository"
|
@@ -115,6 +117,25 @@ module Dr
|
|
115
117
|
FileUtils.rm_rf src_dir
|
116
118
|
FileUtils.mv "#{tmp}/git", "#{src_dir}"
|
117
119
|
end
|
120
|
+
|
121
|
+
@default_branch = branch
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_configuration
|
125
|
+
md_file = "#{@repo.location}/packages/#{@name}/metadata"
|
126
|
+
if File.exists? md_file
|
127
|
+
Utils::symbolise_keys YAML.load_file md_file
|
128
|
+
else
|
129
|
+
{}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def set_configuration(config)
|
134
|
+
# TODO: Some validation needed
|
135
|
+
md_file = "#{@repo.location}/packages/#{@name}/metadata"
|
136
|
+
File.open(md_file, "w") do |f|
|
137
|
+
YAML.dump Utils::stringify_symbols(config), f
|
138
|
+
end
|
118
139
|
end
|
119
140
|
|
120
141
|
def build(branch=nil, force=false)
|
@@ -139,7 +160,13 @@ module Dr
|
|
139
160
|
Dir.mktmpdir do |src_dir|
|
140
161
|
checkout branch, src_dir
|
141
162
|
|
142
|
-
|
163
|
+
version_string = get_version "#{src_dir}/debian/changelog"
|
164
|
+
unless version_string
|
165
|
+
log :err, "Couldn't get the version string from the changelog"
|
166
|
+
raise "The changelog format doesn't seem be right"
|
167
|
+
end
|
168
|
+
|
169
|
+
version = PkgVersion.new version_string
|
143
170
|
log :info, "Source version: #{version.source.style "version"}"
|
144
171
|
|
145
172
|
while build_exists? version
|
@@ -168,14 +195,28 @@ module Dr
|
|
168
195
|
repo_arches = @repo.get_architectures
|
169
196
|
pkg_arches = get_architectures("#{src_dir}/debian/control")
|
170
197
|
arches = case
|
171
|
-
when pkg_arches.include?("any")
|
198
|
+
when pkg_arches.include?("any")
|
172
199
|
repo_arches
|
200
|
+
when pkg_arches.include?("all")
|
201
|
+
["all"]
|
173
202
|
else
|
174
203
|
repo_arches & pkg_arches
|
175
204
|
end
|
176
205
|
|
206
|
+
if repo_arches.length == 0
|
207
|
+
log :error, "#{@name.style "pkg-name"} cannot be build for any of " +
|
208
|
+
"the architectures supported by this repository"
|
209
|
+
raise "Unable to build the package for this repository"
|
210
|
+
end
|
211
|
+
|
212
|
+
benv = :default
|
213
|
+
src_meta = get_configuration
|
214
|
+
if src_meta.has_key? :build_environment
|
215
|
+
benv = src_meta[:build_environment].to_sym
|
216
|
+
end
|
217
|
+
|
177
218
|
arches.each do |arch|
|
178
|
-
@repo.buildroot(arch).open do |br|
|
219
|
+
@repo.buildroot(arch, benv).open do |br|
|
179
220
|
log :info, "Building the #{@name.style "pkg-name"} package " +
|
180
221
|
"version #{version.to_s.style "version"} for #{arch}"
|
181
222
|
|
data/lib/dr/package.rb
CHANGED
@@ -42,6 +42,14 @@ module Dr
|
|
42
42
|
FileUtils.rm_rf "#{@repo.location}/packages/#{@name}/builds/#{version}"
|
43
43
|
end
|
44
44
|
|
45
|
+
def get_configuration
|
46
|
+
{}
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_configuration(config)
|
50
|
+
raise "This package isn't configurable"
|
51
|
+
end
|
52
|
+
|
45
53
|
def <=>(o)
|
46
54
|
self.name <=> o.name
|
47
55
|
end
|
data/lib/dr/repo.rb
CHANGED
@@ -8,6 +8,7 @@ require "dr/shellcmd"
|
|
8
8
|
require "dr/logger"
|
9
9
|
require "dr/gnupg"
|
10
10
|
require "dr/buildroot"
|
11
|
+
require "dr/utils"
|
11
12
|
|
12
13
|
require "fileutils"
|
13
14
|
require "yaml"
|
@@ -24,13 +25,6 @@ module Dr
|
|
24
25
|
@location = File.expand_path loc
|
25
26
|
|
26
27
|
@packages_dir = "#{@location}/packages"
|
27
|
-
|
28
|
-
meta = "#{@location}/metadata"
|
29
|
-
begin
|
30
|
-
@metadata = YAML.load_file(meta)
|
31
|
-
rescue
|
32
|
-
@metadata = {}
|
33
|
-
end
|
34
28
|
end
|
35
29
|
|
36
30
|
def setup(conf)
|
@@ -78,13 +72,27 @@ module Dr
|
|
78
72
|
FileUtils.mkdir_p @packages_dir
|
79
73
|
FileUtils.mkdir_p "#{@location}/buildroots"
|
80
74
|
|
81
|
-
|
75
|
+
metadata = {
|
76
|
+
"default_build_environment" => conf[:build_environment].to_s
|
77
|
+
}
|
82
78
|
File.open("#{@location}/metadata", "w" ) do |out|
|
83
|
-
|
79
|
+
out.write metadata.to_yaml
|
84
80
|
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_configuration
|
84
|
+
meta_file = "#{@location}/metadata"
|
85
|
+
if File.exists? meta_file
|
86
|
+
Utils::symbolise_keys YAML.load_file(meta_file)
|
87
|
+
else
|
88
|
+
{}
|
89
|
+
end
|
90
|
+
end
|
85
91
|
|
86
|
-
|
87
|
-
|
92
|
+
def set_configuration(new_metadata)
|
93
|
+
# TODO: Some validation needed
|
94
|
+
File.open("#{@location}/metadata", "w" ) do |out|
|
95
|
+
out.write Utils::stringify_symbols(new_metadata).to_yaml
|
88
96
|
end
|
89
97
|
end
|
90
98
|
|
@@ -109,9 +117,13 @@ module Dr
|
|
109
117
|
pkgs.sort
|
110
118
|
end
|
111
119
|
|
112
|
-
def buildroot(arch)
|
120
|
+
def buildroot(arch, build_env=:default)
|
121
|
+
if build_env == :default
|
122
|
+
build_env = get_configuration[:default_build_environment].to_sym
|
123
|
+
end
|
124
|
+
|
113
125
|
cache_dir = "#{@location}/buildroots/"
|
114
|
-
BuildRoot.new
|
126
|
+
BuildRoot.new build_env, arch, cache_dir
|
115
127
|
end
|
116
128
|
|
117
129
|
def get_package(name)
|
@@ -371,16 +383,6 @@ module Dr
|
|
371
383
|
nil
|
372
384
|
end
|
373
385
|
|
374
|
-
private
|
375
|
-
def get_key
|
376
|
-
File.open "#{@location}/archive/conf/distributions", "r" do |f|
|
377
|
-
f.each_line do |line|
|
378
|
-
m = line.match /^SignWith: (.+)/
|
379
|
-
return m.captures[0] if m
|
380
|
-
end
|
381
|
-
end
|
382
|
-
end
|
383
|
-
|
384
386
|
def is_used?(pkg_name, version=nil)
|
385
387
|
versions_by_suite = get_subpackage_versions pkg_name
|
386
388
|
versions_by_suite.inject(false) do |rslt, hash_pair|
|
@@ -392,5 +394,15 @@ module Dr
|
|
392
394
|
end
|
393
395
|
end
|
394
396
|
end
|
397
|
+
|
398
|
+
private
|
399
|
+
def get_key
|
400
|
+
File.open "#{@location}/archive/conf/distributions", "r" do |f|
|
401
|
+
f.each_line do |line|
|
402
|
+
m = line.match /^SignWith: (.+)/
|
403
|
+
return m.captures[0] if m
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
395
407
|
end
|
396
408
|
end
|
data/lib/dr/utils.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright (C) 2014 Kano Computing Ltd.
|
2
|
+
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
|
3
|
+
|
4
|
+
module Dr
|
5
|
+
module Utils
|
6
|
+
def self.symbolise_keys(hash)
|
7
|
+
if hash.is_a? Hash
|
8
|
+
hash.inject({}) do |new_hash, (key, value)|
|
9
|
+
new_hash[key.to_sym] = symbolise_keys value
|
10
|
+
new_hash
|
11
|
+
end
|
12
|
+
else
|
13
|
+
hash
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.stringify_keys(hash)
|
18
|
+
return hash unless hash.is_a? Hash
|
19
|
+
|
20
|
+
hash.inject({}) do |new_hash, (key, value)|
|
21
|
+
new_hash[key.to_s] = stringify_keys value
|
22
|
+
new_hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.stringify_symbols(var)
|
27
|
+
case
|
28
|
+
when var.is_a?(Hash)
|
29
|
+
var.inject({}) do |new_hash, (key, value)|
|
30
|
+
new_hash[key.to_s] = stringify_keys value
|
31
|
+
new_hash
|
32
|
+
end
|
33
|
+
when var.is_a?(Array)
|
34
|
+
var.map {|e| stringify_symbols e}
|
35
|
+
when var.is_a?(Symbol)
|
36
|
+
var.to_s
|
37
|
+
else
|
38
|
+
var
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/dr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Radek Pazdera
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -116,10 +116,10 @@ files:
|
|
116
116
|
- dr.conf-example
|
117
117
|
- dr.spec
|
118
118
|
- lib/dr.rb
|
119
|
+
- lib/dr/build_environments.rb
|
119
120
|
- lib/dr/buildroot.rb
|
120
121
|
- lib/dr/config.rb
|
121
122
|
- lib/dr/debpackage.rb
|
122
|
-
- lib/dr/distros.rb
|
123
123
|
- lib/dr/gitpackage.rb
|
124
124
|
- lib/dr/gnupg.rb
|
125
125
|
- lib/dr/logger.rb
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/dr/pkgversion.rb
|
128
128
|
- lib/dr/repo.rb
|
129
129
|
- lib/dr/shellcmd.rb
|
130
|
+
- lib/dr/utils.rb
|
130
131
|
- lib/dr/version.rb
|
131
132
|
homepage: http://github.com/KanoComputing/kano-package-system
|
132
133
|
licenses:
|
@@ -155,3 +156,4 @@ summary: dr stands for debian-repository. It is a packaging tool that helps you
|
|
155
156
|
distribute and maintain you own disto packages and repositories. It's in a very
|
156
157
|
early stage, NOT READY for production.
|
157
158
|
test_files: []
|
159
|
+
has_rdoc:
|