rake-debian-build 1.0.6

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.
data/Manifest.txt ADDED
@@ -0,0 +1,24 @@
1
+ Manifest.txt
2
+ README.rdoc
3
+ Rakefile
4
+ lib/debian/build.rb
5
+ lib/debian/build/abstract_package.rb
6
+ lib/debian/build/build_directory_methods.rb
7
+ lib/debian/build/config.rb
8
+ lib/debian/build/distribution.rb
9
+ lib/debian/build/helper_methods.rb
10
+ lib/debian/build/module_package.rb
11
+ lib/debian/build/package.rb
12
+ lib/debian/build/pbuilder.rb
13
+ lib/debian/build/platform.rb
14
+ lib/debian/build/source_providers.rb
15
+ lib/debian/build/tasks.rb
16
+ lib/debian/build/uploader.rb
17
+ rake-debian-build.gemspec
18
+ script/pbuilder
19
+ spec/debian/build/source_providers_spec.rb
20
+ spec/debian/build/uploader_spec.rb
21
+ spec/spec_helper.rb
22
+ tasks/packages.rake
23
+ tasks/pbuilder.rake
24
+ tasks/setup.rake
data/README.rdoc ADDED
@@ -0,0 +1,125 @@
1
+ = Rake Debian Build
2
+
3
+ * http://github.com/albanpeignier/rake-debian-build
4
+
5
+ == DESCRIPTION:
6
+
7
+ A rake task suite to build debian/ubuntu packages.
8
+
9
+ Manage for your apt-get source or tar-ball download, dpkg-buildpackage, dch, pbuilder, dupload, builds for stable/testing/unstable/hardy/intrepid i386/amd64, etc ...
10
+
11
+ == FEATURES:
12
+
13
+ * sources download (tar-ball or apt-get source)
14
+ * source packaging
15
+ * binary packaging
16
+ * upload
17
+ * pbuilder encapsulation
18
+ * support multiple platforms : debian/ubuntu, stable/testing/unstable/hardy/intrepid, i386/amd64
19
+ * build everything in a command line
20
+ * remote build
21
+
22
+ == SYNOPSIS:
23
+
24
+ Define your packages in your Rakefile. For example (from {Rivendell Debian packages}[http://github.com/albanpeignier/rivendell-debian]) :
25
+
26
+ require 'rubygems'
27
+ require 'debian/build'
28
+ include Debian::Build
29
+
30
+ require 'debian/build/config'
31
+
32
+ namespace "package" do
33
+
34
+ Package.new(:hpklinux) do |p|
35
+ p.version = '3.08.05'
36
+ p.debian_increment = 2
37
+
38
+ p.source_provider = TarballSourceProvider.new('http://www.rivendellaudio.org/ftpdocs/audioscience/hpklinux-#{version}.tar.bz2')
39
+ end
40
+
41
+ main_source_provider = TarballSourceProvider.new('http://www.rivendellaudio.org/ftpdocs/#{name}/#{name}-#{version}.tar.gz')
42
+
43
+ Package.new(:rivendell) do |p|
44
+ p.version = '1.3.0'
45
+ p.debian_increment = 1
46
+ p.source_provider = main_source_provider
47
+ end
48
+
49
+ Package.new(:gpio) do |p|
50
+ p.version = '1.0.0'
51
+ p.debian_increment = 2
52
+ p.source_provider = main_source_provider
53
+ end
54
+
55
+ ModulePackage.new('gpio-module')
56
+
57
+ ModulePackage.new('hpklinux-module')
58
+
59
+ end
60
+
61
+ require 'debian/build/tasks'
62
+
63
+ Configure your environment (in config.rb) :
64
+
65
+ Distribution.mirrors = {
66
+ :debian => 'http://localhost:9999/debian',
67
+ :ubuntu => 'http://localhost:9999/ubuntu'
68
+ }
69
+
70
+ Uploader.default.host = "debian.tryphon.org"
71
+ Uploader.default.nickname = "tryphon"
72
+
73
+ Setup your environment:
74
+
75
+ rake setup
76
+
77
+ Create pbuilder images:
78
+
79
+ rake pbuilder:create
80
+
81
+ Build all source package
82
+
83
+ rake packages:sources
84
+
85
+ Build all binary package
86
+
87
+ rake packages:binaries
88
+
89
+ Upload all packages
90
+
91
+ rake packages:upload
92
+
93
+ == REQUIREMENTS:
94
+
95
+ * pbuilder, dupload, devscripts
96
+
97
+ == INSTALL:
98
+
99
+ gem sources -a http://gems.github.com
100
+ sudo gem install albanpeignier-rake-debian-build
101
+
102
+ == LICENSE:
103
+
104
+ (The MIT License)
105
+
106
+ Copyright (c) 2009 Alban Peignier
107
+
108
+ Permission is hereby granted, free of charge, to any person obtaining
109
+ a copy of this software and associated documentation files (the
110
+ 'Software'), to deal in the Software without restriction, including
111
+ without limitation the rights to use, copy, modify, merge, publish,
112
+ distribute, sublicense, and/or sell copies of the Software, and to
113
+ permit persons to whom the Software is furnished to do so, subject to
114
+ the following conditions:
115
+
116
+ The above copyright notice and this permission notice shall be
117
+ included in all copies or substantial portions of the Software.
118
+
119
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
120
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
121
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
122
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
123
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
124
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
125
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ %w[rubygems hoe].each { |f| require f }
2
+
3
+ # Generate all the Rake tasks
4
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
5
+ $hoe = Hoe.new('rake-debian-build', '1.0.6') do |p|
6
+ p.developer("Alban Peignier", "alban.peignier@free.fr")
7
+ p.summary = "Rake tasks to build debian packages"
8
+ p.url = "http://github.com/albanpeignier/rake-debian-build"
9
+
10
+ p.rubyforge_name = p.name # TODO this is default value
11
+
12
+ p.clean_globs |= %w[**/.DS_Store *~]
13
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
14
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
15
+ p.rsync_args = '-av --delete --ignore-errors'
16
+ end
17
+
18
+ desc 'Recreate Manifest.txt to include ALL files'
19
+ task :manifest do
20
+ `rake check_manifest | patch -p0 > Manifest.txt`
21
+ end
22
+
23
+ desc "Generate a #{$hoe.name}.gemspec file"
24
+ task :gemspec do
25
+ File.open("#{$hoe.name}.gemspec", "w") do |file|
26
+ file.puts $hoe.spec.to_ruby
27
+ end
28
+ end
@@ -0,0 +1,42 @@
1
+ require 'rake/tasklib'
2
+
3
+ module Debian::Build
4
+
5
+ @packages = []
6
+
7
+ def self.packages
8
+ @packages
9
+ end
10
+
11
+ class AbstractPackage < Rake::TaskLib
12
+ include HelperMethods
13
+ extend BuildDirectoryMethods
14
+
15
+ attr_reader :name
16
+ attr_accessor :package, :exclude_from_build
17
+
18
+ def initialize(name)
19
+ @name = @package = name
20
+
21
+ init
22
+ yield self if block_given?
23
+ define
24
+
25
+ Debian::Build.packages << name.to_sym
26
+ end
27
+
28
+ def init
29
+ end
30
+
31
+ def default_platforms
32
+ unless exclude_from_build
33
+ Platform.all
34
+ else
35
+ Platform.all.reject do |platform|
36
+ platform.to_s.match exclude_from_build
37
+ end
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ module Debian::Build
2
+ module BuildDirectoryMethods
3
+
4
+ @@build_directory = '/var/tmp/debian'
5
+
6
+ def build_directory=(directory)
7
+ @@build_directory = directory
8
+ end
9
+
10
+ def build_directory
11
+ @@build_directory or '/var/tmp/debian'
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1 @@
1
+ require 'config' if File.exists? 'config.rb'
@@ -0,0 +1,66 @@
1
+ module Debian::Build
2
+ class Distribution
3
+ extend BuildDirectoryMethods
4
+
5
+ attr_reader :flavor, :distribution
6
+
7
+ def initialize(flavor, distribution)
8
+ @flavor = flavor
9
+ @distribution = distribution.to_sym
10
+ end
11
+
12
+ def self.all
13
+ @@all ||= debian_distributions + ubuntu_distributions
14
+ end
15
+
16
+ def self.each(&block)
17
+ all.each &block
18
+ end
19
+
20
+ def self.debian_distributions
21
+ @@debian_distributions ||=
22
+ %w{stable testing unstable}.collect { |distribution| Distribution.new(:debian, distribution) }
23
+ end
24
+
25
+ def self.ubuntu_distributions
26
+ @@ubuntu_distributions ||=
27
+ %w{hardy intrepid jaunty}.collect { |distribution| Distribution.new(:ubuntu, distribution) }
28
+ end
29
+
30
+ def source_result_directory
31
+ File.expand_path "#{Platform.build_directory}/sources/#{distribution}"
32
+ end
33
+
34
+ @@mirrors = { :debian => "http://ftp.debian.org/debian", :ubuntu => 'http://archive.ubuntu.com/ubuntu' }
35
+
36
+ def self.mirrors=(mirrors)
37
+ @@mirrors.update(mirrors)
38
+ end
39
+
40
+ def mirror
41
+ @@mirrors[flavor]
42
+ end
43
+
44
+ def ubuntu?
45
+ flavor == :ubuntu
46
+ end
47
+
48
+ def unstable?
49
+ [ :unstable, :jaunty ].include? distribution
50
+ end
51
+
52
+ @@local_names = { :stable => 'lenny', :testing => 'squeeze' }
53
+ def local_name
54
+ @@local_names.fetch(distribution,self.to_s)
55
+ end
56
+
57
+ def to_s
58
+ distribution.to_s
59
+ end
60
+
61
+ def task_name
62
+ to_s
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,25 @@
1
+ module Debian::Build
2
+ module HelperMethods
3
+
4
+ def sudo(*args)
5
+ sh (["sudo"] + args).join(' ')
6
+ end
7
+
8
+ def uncompress(archive)
9
+ options =
10
+ case archive
11
+ when /bz2$/
12
+ "-j"
13
+ when /gz/
14
+ "-z"
15
+ end
16
+
17
+ sh "tar -xf #{archive} #{options}"
18
+ end
19
+
20
+ def get(url)
21
+ sh "wget -m --no-directories #{url}"
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,49 @@
1
+ module Debian::Build
2
+ class ModulePackage < AbstractPackage
3
+
4
+ def module_name
5
+ package.gsub(/-module$/,'')
6
+ end
7
+
8
+ def define
9
+ namespace @name do
10
+ namespace :pbuild do
11
+ Platform.each do |platform|
12
+ desc "Pbuild #{platform} binary package for #{package}"
13
+ task platform.task_name do |t, args|
14
+ cp "execute-module-assistant", "#{AbstractPackage.build_directory}/tmp"
15
+
16
+ pbuilder_options = {
17
+ :logfile => "#{platform.build_result_directory}/pbuilder-#{package}.log"
18
+ }
19
+
20
+ platform.pbuilder(pbuilder_options).exec :execute, "-- #{AbstractPackage.build_directory}/tmp/execute-module-assistant #{module_name} #{platform.architecture} #{platform.build_result_directory}"
21
+ end
22
+ end
23
+
24
+ desc "Pbuild binary package for #{package} (on #{default_platforms.join(', ')})"
25
+ task :all => default_platforms.collect { |platform| platform.task_name }
26
+
27
+ end
28
+
29
+ desc "Upload packages for #{package}"
30
+ task "upload" do
31
+ Platform.each do |platform|
32
+ Uploader.default.rsync platform.distribution, Dir["#{platform.build_result_directory}/#{package}-*.deb"]
33
+ end
34
+ end
35
+
36
+ task "lintian" do
37
+ # TODO : implement lintian on ModulePackage
38
+ end
39
+
40
+ # TODO : remove this mock
41
+ namespace :source do
42
+ task :all
43
+ end
44
+
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,197 @@
1
+ module Debian::Build
2
+ class Package < AbstractPackage
3
+
4
+ attr_reader :name
5
+ attr_accessor :package, :version, :signing_key, :debian_increment, :exclude_from_build, :source_provider
6
+
7
+ def init
8
+ @debian_increment = 1
9
+ # TODO use a class attribute
10
+ @signing_key = ENV['KEY']
11
+ @source_provider = AptSourceProvider.new
12
+ end
13
+
14
+ def define
15
+ raise "Version must be set" if version.nil?
16
+
17
+ namespace @name do
18
+ namespace "source" do
19
+
20
+ desc "Retrieve source for #{package} #{version}"
21
+ task "directory" do
22
+ mkdir_p sources_directory
23
+ Dir.chdir(sources_directory) do
24
+ @source_provider.retrieve(self)
25
+ end
26
+
27
+ copy_debian_files
28
+ end
29
+
30
+ Distribution.each do |distribution|
31
+ desc "Build source package for #{package} #{version} on #{distribution}"
32
+ task distribution.task_name => :directory do
33
+ copy_debian_files
34
+
35
+ dch_options="--preserve --force-distribution"
36
+ Dir.chdir(source_directory) do
37
+ if not distribution.ubuntu? and distribution.unstable?
38
+ sh "dch #{dch_options} --distribution 'unstable' --release ''"
39
+ else
40
+ sh "dch #{dch_options} --local #{local_name(distribution)} --distribution #{distribution} 'Release from unstable'"
41
+ end
42
+
43
+ dpkg_buildpackage_options = []
44
+
45
+ if signing_key
46
+ dpkg_buildpackage_options << "-k#{signing_key}"
47
+ else
48
+ dpkg_buildpackage_options << "-us -uc"
49
+ end
50
+
51
+ if ENV['ORIGINAL_SOURCE']
52
+ dpkg_buildpackage_options << "-sa"
53
+ end
54
+
55
+ sh "dpkg-buildpackage -rfakeroot #{dpkg_buildpackage_options.join(' ')} -S -I.git"
56
+ end
57
+ end
58
+ end
59
+
60
+ desc "Build source packages for #{package} #{version}"
61
+ task :all => Distribution.all.collect { |distribution| distribution.task_name }
62
+ end
63
+
64
+ namespace :pbuild do
65
+ Platform.each do |platform|
66
+ desc "Pbuild #{platform} binary package for #{package} #{version}"
67
+ task platform.task_name do |t, args|
68
+ pbuilder_options = {
69
+ :logfile => "#{platform.build_result_directory}/pbuilder-#{package}-#{debian_version}.log"
70
+ }
71
+ platform.pbuilder(pbuilder_options).exec :build, dsc_file(platform)
72
+ end
73
+ end
74
+
75
+ desc "Pbuild binary package for #{package} #{version} (on #{default_platforms.join(', ')})"
76
+ task :all => default_platforms.collect { |platform| platform.task_name }
77
+
78
+ end
79
+
80
+ desc "Upload packages for #{package} #{version}"
81
+ task "upload" do
82
+ Uploader.default.dupload changes_files
83
+ end
84
+
85
+ desc "Run lintian on package #{package}"
86
+ task "lintian" do
87
+ redirect = ENV['LINTIAN_OUTPUT'] ? ">> #{ENV['LINTIAN_OUTPUT']}" : ""
88
+ sh "lintian #{changes_files.join(' ')} #{redirect}"
89
+ end
90
+
91
+ desc "Clean files created for #{package} #{version}"
92
+ task "clean" do
93
+ Platform.each do |platform|
94
+ rm_f package_files(platform.build_result_directory)
95
+ end
96
+
97
+ rm_f package_source_files
98
+
99
+ rm_f "#{sources_directory}/#{source_tarball_name}"
100
+ rm_f "#{sources_directory}/#{orig_source_tarball_name}"
101
+ rm_rf "#{source_directory}"
102
+ end
103
+ end
104
+ end
105
+
106
+ def local_name(distribution)
107
+ unless distribution.unstable?
108
+ distribution.local_name
109
+ else
110
+ "ubuntu" if distribution.ubuntu?
111
+ end
112
+ end
113
+
114
+ def dsc_file(platform)
115
+ suffix =
116
+ if local_name = local_name(platform)
117
+ "#{local_name}1"
118
+ else
119
+ ""
120
+ end
121
+ File.expand_path "#{Package.build_directory}/sources/#{package}_#{debian_version}#{suffix}.dsc"
122
+ end
123
+
124
+ def copy_debian_files
125
+ rm_rf "#{source_directory}/debian"
126
+ cp_r debian_directory, "#{source_directory}/debian"
127
+ end
128
+
129
+ def debian_directory
130
+ ["debian", "#{package}/debian"].find { |d| File.exists?(d) }
131
+ end
132
+
133
+ def sources_directory
134
+ "#{Package.build_directory}/sources"
135
+ end
136
+
137
+ def orig_source_tarball_name
138
+ "#{package}_#{version}.orig.tar.gz"
139
+ end
140
+
141
+ def source_directory
142
+ "#{sources_directory}/#{name}-#{version}"
143
+ end
144
+
145
+ def debian_version
146
+ "#{version}-#{debian_increment}"
147
+ end
148
+
149
+ def changes_files
150
+ changes_files = Dir.glob("#{sources_directory}/#{package}_#{debian_version}*_source.changes")
151
+
152
+ Platform.each do |platform|
153
+ platform_changes_files = Dir.glob("#{platform.build_result_directory}/#{package}_#{debian_version}*_#{platform.architecture}.changes")
154
+
155
+ unless platform_changes_files.empty?
156
+ # deb packages for architect all shouldn't be uploaded twice
157
+ sh "sed -i '/_all.deb/ d' #{platform_changes_files.join(' ')}" if platform.architecture != 'i386'
158
+
159
+ changes_files << platform_changes_files
160
+ end
161
+ end
162
+
163
+ changes_files.flatten!
164
+ changes_files
165
+ end
166
+
167
+ def package_files(directory = '.')
168
+ fileparts = [ name.to_s ]
169
+ case name
170
+ when :hpklinux
171
+ fileparts << 'libhpi'
172
+ when :rivendell
173
+ fileparts << 'librivendell'
174
+ end
175
+
176
+ fileparts.inject([]) do |files, filepart|
177
+ files + Dir.glob("#{directory}/#{filepart}*#{debian_version}*")
178
+ end
179
+ end
180
+
181
+ def package_source_files
182
+ %w{.dsc .tar.gz _source.changes}.collect do |extension|
183
+ "#{sources_directory}/#{package}_#{debian_version}#{extension}"
184
+ end
185
+ end
186
+
187
+ def package_deb_files(directory = '.')
188
+ package_files(directory).find_all { |f| f.match /\.deb$/ }
189
+ end
190
+
191
+ def get_binding
192
+ binding
193
+ end
194
+
195
+ end
196
+
197
+ end
@@ -0,0 +1,79 @@
1
+ module Debian::Build
2
+ class PBuilder
3
+ extend BuildDirectoryMethods
4
+ include HelperMethods
5
+
6
+ @@default_build_host = nil
7
+
8
+ def self.default_build_host=(host)
9
+ @@default_build_host = host
10
+ end
11
+
12
+ def initialize
13
+ @options = {}
14
+ @before_exec_callbacks = []
15
+
16
+ yield self if block_given?
17
+ end
18
+
19
+ def build_host
20
+ @@default_build_host
21
+ end
22
+
23
+ def [](option)
24
+ @options[option.to_sym]
25
+ end
26
+
27
+ def []=(option, value)
28
+ @options[option.to_sym] = value
29
+ end
30
+
31
+ def options=(options)
32
+ @options = @options.update options
33
+ end
34
+
35
+ def options_arguments
36
+ @options.collect do |option, argument|
37
+ command_option = "--#{option}"
38
+ case argument
39
+ when true
40
+ command_option
41
+ when Array
42
+ argument.collect { |a| "#{command_option} #{a}" }
43
+ else
44
+ "#{command_option} #{argument}"
45
+ end
46
+ end.flatten
47
+ end
48
+
49
+ def before_exec(proc)
50
+ @before_exec_callbacks << proc
51
+ end
52
+
53
+ def exec(command, *arguments)
54
+ @before_exec_callbacks.each { |c| c.call }
55
+
56
+ if build_host
57
+ remote_exec command, *arguments
58
+ else
59
+ sudo "pbuilder", command, *(options_arguments + arguments)
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ def remote_exec(command, *arguments)
66
+ local_build_directory = PBuilder.build_directory
67
+ remote_build_directory = "/var/tmp/debian"
68
+
69
+ sh "rsync -av --no-owner --no-group --no-perms --cvs-exclude --exclude=Rakefile --delete #{local_build_directory}/ #{build_host}:#{remote_build_directory}/"
70
+
71
+ quoted_arguments = (options_arguments + arguments).join(' ').gsub("'","\\\\\"")
72
+ quoted_arguments = quoted_arguments.gsub(local_build_directory, remote_build_directory)
73
+
74
+ sh "ssh #{build_host} \"cd #{remote_build_directory}; sudo pbuilder #{command} #{quoted_arguments}\""
75
+ sh "rsync -av --no-owner --no-group --no-perms #{build_host}:#{remote_build_directory}/ #{local_build_directory}"
76
+ end
77
+
78
+ end
79
+ end
@@ -0,0 +1,115 @@
1
+ module Debian::Build
2
+ class Platform
3
+ extend BuildDirectoryMethods
4
+
5
+ attr_reader :architecture
6
+
7
+ def method_missing(method, *args, &block)
8
+ if @distribution.respond_to? method
9
+ @distribution.send method, *args
10
+ else
11
+ super
12
+ end
13
+ end
14
+
15
+ def initialize(distribution, architecture)
16
+ @distribution = distribution
17
+ @architecture = architecture
18
+ end
19
+
20
+ def self.find_by_name(name)
21
+ self.all.find { |p| p.to_s == name }
22
+ end
23
+
24
+ def self.supported_architectures
25
+ %w{i386 amd64}
26
+ end
27
+
28
+ def self.all
29
+ @@all ||=
30
+ Distribution.all.collect do |distribution|
31
+ supported_architectures.collect { |architecture| Platform.new(distribution, architecture) }
32
+ end.flatten
33
+ end
34
+
35
+ def self.each(&block)
36
+ all.each &block
37
+ end
38
+
39
+ def build_result_directory
40
+ File.expand_path "#{Platform.build_directory}/binaries/#{distribution}/#{architecture}"
41
+ end
42
+
43
+ def pbuilder_base_file
44
+ "/var/cache/pbuilder/base-#{distribution}-#{architecture}.tgz"
45
+ end
46
+
47
+ def pbuilder_enabled?
48
+ File.exists? pbuilder_base_file
49
+ end
50
+
51
+ def pbuilder(options = {})
52
+ PBuilder.new do |p|
53
+ p[:basetgz] = pbuilder_base_file
54
+ p[:othermirror] = "'deb file:#{build_result_directory} ./|deb http://www.debian-multimedia.org #{distribution} main '"
55
+ p[:bindmounts] = p[:buildresult] = build_result_directory
56
+ p[:distribution] = distribution
57
+ p[:hookdir] = default_hooks_directory
58
+
59
+ # to use i386 on amd64 architecture
60
+ p[:debootstrapopts] = [ "--arch=#{architecture}" ]
61
+ p[:debbuildopts] = [ "-a#{architecture}", '-b' ]
62
+
63
+ p[:mirror] = mirror
64
+
65
+ if flavor == :ubuntu
66
+ # cdebootstrap fails with ubuntu
67
+ p[:components] = "'main universe'"
68
+ p[:debootstrap] = 'debootstrap'
69
+ end
70
+
71
+ p.options = options
72
+
73
+ p.before_exec Proc.new {
74
+ prepare_build_result_directory
75
+ prepare_default_hooks
76
+ }
77
+ end
78
+ end
79
+
80
+ def default_hooks_directory
81
+ "#{Package.build_directory}/tmp/hooks"
82
+ end
83
+
84
+ def prepare_build_result_directory
85
+ mkdir_p build_result_directory
86
+
87
+ Dir.chdir(build_result_directory) do
88
+ sh "/usr/bin/dpkg-scanpackages . /dev/null > Packages"
89
+ end
90
+ end
91
+
92
+ def prepare_default_hooks
93
+ mkdir_p default_hooks_directory
94
+
95
+ apt_update_hook_file = "#{default_hooks_directory}/D80apt-get-update"
96
+ unless File.exists?(apt_update_hook_file)
97
+ File.open(apt_update_hook_file, "w") do |f|
98
+ f.puts "#!/bin/sh"
99
+ f.puts "apt-get update"
100
+ end
101
+
102
+ FileUtils.chmod 0755, apt_update_hook_file
103
+ end
104
+ end
105
+
106
+ def to_s(separator = '/')
107
+ "#{distribution}#{separator}#{architecture}"
108
+ end
109
+
110
+ def task_name
111
+ to_s '_'
112
+ end
113
+
114
+ end
115
+ end
@@ -0,0 +1,99 @@
1
+ require 'fileutils'
2
+ require 'uri'
3
+
4
+ module Debian::Build
5
+
6
+ class TarballSourceProvider
7
+ include FileUtils
8
+ include Debian::Build::HelperMethods
9
+
10
+ def initialize(url)
11
+ @url = url
12
+ end
13
+
14
+ def retrieve(package)
15
+ PackageRetriever.new(@url, package).retrieve
16
+ end
17
+
18
+ class PackageRetriever
19
+ include FileUtils
20
+ include Debian::Build::HelperMethods
21
+
22
+ attr_reader :package
23
+
24
+ def initialize(url, package)
25
+ @url, @package = url, package
26
+ end
27
+
28
+ def retrieve
29
+ get tarball_url
30
+ uncompress tarball_name
31
+ prepare_orig_tarball
32
+ end
33
+
34
+ def prepare_orig_tarball
35
+ if tarball_name.match /bz2$/
36
+ sh "bunzip2 -c #{tarball_name} | gzip -c > #{orig_tarball_name}" unless File.exists?(orig_tarball_name)
37
+ else
38
+ sh "ln -fs #{tarball_name} #{orig_tarball_name}"
39
+ end
40
+ end
41
+
42
+ def tarball_url
43
+ @tarball_url ||= eval( '"' + @url + '"', package.get_binding)
44
+ end
45
+
46
+ def tarball_name
47
+ File.basename URI.parse(tarball_url).path
48
+ end
49
+
50
+ def orig_tarball_name
51
+ package.orig_source_tarball_name
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ class AptSourceProvider
59
+ include FileUtils
60
+
61
+ def retrieve(package)
62
+ sh "apt-get source #{package.name}"
63
+ end
64
+
65
+ end
66
+
67
+ class DebianTarballProvider
68
+
69
+ def initialize(tarball_name_pattern = nil)
70
+ @tarball_name_pattern = tarball_name_pattern
71
+ end
72
+
73
+ def tarball_name_pattern
74
+ @tarball_name_pattern ||= '#{name}-#{version}.tgz'
75
+ end
76
+
77
+ def tarball_name(package)
78
+ eval( '"' + tarball_name_pattern + '"', package.get_binding)
79
+ end
80
+
81
+ def retrieve(package)
82
+ mkdir_p package.source_directory
83
+ sh "cp #{Rake.original_dir}/#{tarball_name(package)} #{package.source_directory}"
84
+ end
85
+
86
+ end
87
+
88
+ class GitExportProvider
89
+
90
+ def retrieve(package)
91
+ mkdir_p package.source_directory
92
+ Dir.chdir(Rake.original_dir) do
93
+ sh "git archive HEAD | tar -xf - -C #{package.source_directory}"
94
+ end
95
+ end
96
+
97
+ end
98
+
99
+ end
@@ -0,0 +1 @@
1
+ Dir[File.join(File.dirname(__FILE__), %w[.. .. .. tasks], '**/*.rake')].each { |rake| load rake }
@@ -0,0 +1,45 @@
1
+ require 'fileutils'
2
+
3
+ module Debian::Build
4
+
5
+ class Uploader
6
+ include FileUtils
7
+
8
+ # TODO nickname could be used to determinate incoming and host
9
+ attr_accessor :nickname
10
+ attr_accessor :incoming, :host
11
+
12
+ def initialize
13
+ self.incoming = '/var/lib/debarchiver/incoming'
14
+ end
15
+
16
+ def lock(&block)
17
+ raise "No defined host, can't create lock file in ssh" unless host
18
+
19
+ begin
20
+ sh "ssh #{host} touch #{lock_file}"
21
+ yield
22
+ ensure
23
+ sh "ssh #{host} rm -f #{lock_file}"
24
+ end
25
+ end
26
+
27
+ def lock_file
28
+ File.join(self.incoming, "debarchiver.lock")
29
+ end
30
+
31
+ def dupload(*changes_files)
32
+ options = ['-t', nickname] if nickname
33
+ sh *["dupload", options, changes_files].flatten.compact
34
+ end
35
+
36
+ def rsync(target_directory, *files)
37
+ sh "rsync -av #{files.join(' ')} #{host}:#{incoming}/#{target_directory}"
38
+ end
39
+
40
+ @@default = Uploader.new
41
+ def self.default; @@default end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,21 @@
1
+ module Debian
2
+ module Build
3
+ end
4
+ end
5
+
6
+ require "debian/build/build_directory_methods"
7
+ require "debian/build/helper_methods"
8
+
9
+ require "debian/build/distribution"
10
+ require "debian/build/platform"
11
+
12
+ require "debian/build/pbuilder"
13
+
14
+ require "debian/build/source_providers"
15
+
16
+ require "debian/build/uploader"
17
+
18
+ require "debian/build/abstract_package"
19
+ require "debian/build/package"
20
+ require "debian/build/module_package"
21
+
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rake-debian-build}
5
+ s.version = "1.0.5"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Alban Peignier"]
9
+ s.date = %q{2009-09-15}
10
+ s.description = %q{}
11
+ s.email = ["alban.peignier@free.fr"]
12
+ s.extra_rdoc_files = ["Manifest.txt"]
13
+ s.files = ["Manifest.txt", "README.rdoc", "Rakefile", "lib/debian/build.rb", "lib/debian/build/abstract_package.rb", "lib/debian/build/build_directory_methods.rb", "lib/debian/build/config.rb", "lib/debian/build/distribution.rb", "lib/debian/build/helper_methods.rb", "lib/debian/build/module_package.rb", "lib/debian/build/package.rb", "lib/debian/build/pbuilder.rb", "lib/debian/build/platform.rb", "lib/debian/build/source_providers.rb", "lib/debian/build/tasks.rb", "lib/debian/build/uploader.rb", "rake-debian-build.gemspec", "script/pbuilder", "spec/debian/build/source_providers_spec.rb", "spec/debian/build/uploader_spec.rb", "spec/spec_helper.rb", "tasks/packages.rake", "tasks/pbuilder.rake", "tasks/setup.rake"]
14
+ s.homepage = %q{http://github.com/albanpeignier/rake-debian-build}
15
+ s.rdoc_options = ["--main", "README.txt"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{rake-debian-build}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{Rake tasks to build debian packages}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ s.add_development_dependency(%q<hoe>, [">= 2.3.3"])
27
+ else
28
+ s.add_dependency(%q<hoe>, [">= 2.3.3"])
29
+ end
30
+ else
31
+ s.add_dependency(%q<hoe>, [">= 2.3.3"])
32
+ end
33
+ end
data/script/pbuilder ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'debian/build'
6
+
7
+ platform = Debian::Build::Platform.find_by_name(ARGV.shift)
8
+ platform.pbuilder.exec :build, ARGV.shift
@@ -0,0 +1,91 @@
1
+ require File.join(File.dirname(__FILE__), '../../spec_helper')
2
+
3
+ describe TarballSourceProvider do
4
+
5
+ before(:each) do
6
+ @package = Package.new(:test) do |p|
7
+ p.version = "1.0"
8
+ end
9
+ @url = 'dummy'
10
+ @provider = TarballSourceProvider.new(@url)
11
+
12
+ @retriever = TarballSourceProvider::PackageRetriever.new @url, @package
13
+ end
14
+
15
+ it "should create a PackageRetriever with url and package" do
16
+ @retriever.stub!(:retrieve)
17
+
18
+ TarballSourceProvider::PackageRetriever.should_receive(:new).with(@url, @package).and_return(@retriever)
19
+ @provider.retrieve(@package)
20
+ end
21
+
22
+ it "should retrieve with created PackageRetriever" do
23
+ TarballSourceProvider::PackageRetriever.stub!(:new).and_return(@retriever)
24
+ @retriever.should_receive(:retrieve)
25
+ @provider.retrieve(@package)
26
+ end
27
+
28
+ describe TarballSourceProvider::PackageRetriever do
29
+
30
+ describe "tarball_url" do
31
+
32
+ def retriever(url)
33
+ TarballSourceProvider::PackageRetriever.new url, @package
34
+ end
35
+
36
+ it 'should replace #{...} with package attributes' do
37
+ retriever('#{name}').tarball_url.should == @package.name.to_s
38
+ end
39
+
40
+ end
41
+
42
+ describe "tarball_name" do
43
+
44
+ it "should be filename in tarball_url" do
45
+ @retriever.stub!(:tarball_url).and_return("http://test/path/to/expected_tarball_name")
46
+ @retriever.tarball_name.should == "expected_tarball_name"
47
+ end
48
+
49
+ end
50
+
51
+ describe "prepare_orig_tarball" do
52
+
53
+ it "should create a link to tarball_name with orig_tarball_name when tarball isn't a bzip file" do
54
+ @retriever.stub!(:tarball_name).and_return("tarball.gz")
55
+ @retriever.stub!(:orig_tarball_name).and_return("orig_tarball.gz")
56
+
57
+ @retriever.should_receive(:sh).with("ln -fs tarball.gz orig_tarball.gz")
58
+ @retriever.prepare_orig_tarball
59
+ end
60
+
61
+ it "should create a gzip tarball from a bzip tarball" do
62
+ @retriever.stub!(:tarball_name).and_return("tarball.bz2")
63
+
64
+ @retriever.stub!(:orig_tarball_name).and_return("orig_tarball.gz")
65
+ File.stub!(:exists?).and_return(false)
66
+
67
+ @retriever.should_receive(:sh).with("bunzip2 -c tarball.bz2 | gzip -c > orig_tarball.gz")
68
+ @retriever.prepare_orig_tarball
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+
77
+ describe AptSourceProvider do
78
+
79
+ before(:each) do
80
+ @provider = AptSourceProvider.new
81
+ @package = Package.new(:test) do |p|
82
+ p.version = "1.0"
83
+ end
84
+ end
85
+
86
+ it "should run apt-get source" do
87
+ @provider.should_receive(:sh).with("apt-get source test")
88
+ @provider.retrieve(@package)
89
+ end
90
+
91
+ end
@@ -0,0 +1,82 @@
1
+ require File.join(File.dirname(__FILE__), '../../spec_helper')
2
+
3
+ describe Uploader do
4
+
5
+ it "should have a Uploader instance in Uploader.default" do
6
+ Uploader.default.should be_instance_of Uploader
7
+ end
8
+
9
+ before(:each) do
10
+ @uploader = Uploader.new
11
+
12
+ @files = Array.new(3) { |i| "file_#{i}" }
13
+ end
14
+
15
+ it "should have a default incoming '/var/lib/debarchiver/incoming'" do
16
+ @uploader.incoming.should == '/var/lib/debarchiver/incoming'
17
+ end
18
+
19
+ it "should have a lock file debarchiver.lock in incoming" do
20
+ @uploader.incoming = "path/to/incoming"
21
+ @uploader.lock_file.should == "path/to/incoming/debarchiver.lock"
22
+ end
23
+
24
+ describe "dupload" do
25
+
26
+ it "should run dupload with specified changes files" do
27
+ @uploader.should_receive(:sh).with("dupload", *@files)
28
+ @uploader.dupload(@files)
29
+ end
30
+
31
+ end
32
+
33
+ describe "lock file" do
34
+
35
+ it "should be debarchiver.lock in incoming directory" do
36
+ @uploader.incoming = "path/to/incoming"
37
+ @uploader.lock_file.should == "path/to/incoming/debarchiver.lock"
38
+ end
39
+
40
+ end
41
+
42
+ describe "lock" do
43
+
44
+ before(:each) do
45
+ @uploader.stub!(:sh)
46
+
47
+ @uploader.host = "host"
48
+ @uploader.stub!(:lock_file).and_return("lock")
49
+ end
50
+
51
+ it "should raise an error when no host is defined" do
52
+ @uploader.host = nil
53
+ lambda { @uploader.lock { } }.should raise_error
54
+ end
55
+
56
+ it "should create a lock file in ssh" do
57
+ @uploader.should_receive(:sh).with("ssh host touch lock")
58
+ @uploader.lock { }
59
+ end
60
+
61
+ it "should remove the lock file in ssh" do
62
+ @uploader.should_receive(:sh).with("ssh host rm -f lock")
63
+ @uploader.lock { }
64
+ end
65
+
66
+ end
67
+
68
+ describe "rsync" do
69
+
70
+ before(:each) do
71
+ @uploader.host = "host"
72
+ @uploader.incoming = "/path/to/incoming"
73
+ end
74
+
75
+ it "should rsync givenl files to incoming target directory" do
76
+ @uploader.should_receive(:sh).with("rsync -av #{@files.join(' ')} host:/path/to/incoming/target")
77
+ @uploader.rsync("target",@files)
78
+ end
79
+
80
+ end
81
+
82
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec'
2
+
3
+ lib_path = File.join(File.dirname(__FILE__),"..","lib")
4
+ $:.unshift lib_path unless $:.include?(lib_path)
5
+
6
+ require "debian/build"
7
+ include Debian::Build
@@ -0,0 +1,36 @@
1
+ namespace "packages" do
2
+ desc "Create packages source for all packages"
3
+
4
+ desc "Build source packages for #{Debian::Build.packages.join(' ')}"
5
+ task :sources
6
+
7
+ desc "Build binary packages for #{Debian::Build.packages.join(' ')}"
8
+ task :binaries
9
+
10
+ desc "Upload packages for #{Debian::Build.packages.join(' ')}"
11
+ task :upload
12
+
13
+ Debian::Build.packages.each do |package|
14
+ task :sources => "package:#{package}:source:all"
15
+ task :binaries => "package:#{package}:pbuild:all"
16
+ task :clean => "package:#{package}:clean"
17
+ end
18
+
19
+ task :upload do
20
+ Debian::Build::Uploader.default.lock do
21
+ Debian::Build.packages.each do |package|
22
+ Rake::Task["package:#{package}:upload"].invoke
23
+ end
24
+ end
25
+ end
26
+
27
+ task :lintian do
28
+ lintian_sub_tasks = Debian::Build.packages.collect do |package|
29
+ "package:#{package}:lintian"
30
+ end
31
+ sh "rake #{lintian_sub_tasks.join(' ')} | sort -u > lintian-#{Time.now.strftime("%Y%m%d%H%M")}.txt"
32
+ end
33
+
34
+ end
35
+
36
+ task :packages => [ "packages:sources", "packages:binaries", "packages:upload" ]
@@ -0,0 +1,33 @@
1
+ namespace :pbuilder do
2
+ include Debian::Build::HelperMethods
3
+
4
+ desc "Install pbuilder"
5
+ task :setup do
6
+ sudo "apt-get install pbuilder"
7
+ end
8
+
9
+ namespace "create" do
10
+ Debian::Build::Platform.each do |platform|
11
+ desc "Create pbuilder base image for #{platform}"
12
+ task platform.task_name do
13
+ platform.pbuilder.exec :create unless platform.pbuilder_enabled?
14
+ end
15
+ end
16
+ end
17
+ task :create => Platform.all.collect { |platform| "create:#{platform.task_name}" }
18
+
19
+ desc "Update pbuilder"
20
+ task :update do
21
+ Debian::Build::Platform.each do |platform|
22
+ platform.pbuilder.exec :update
23
+ end
24
+ end
25
+
26
+ desc "Update pbuilder by overriding config"
27
+ task :update_config do
28
+ Debian::Build::Platform.each do |platform|
29
+ platform.pbuilder("override-config" => true).exec :update
30
+ end
31
+ end
32
+
33
+ end
data/tasks/setup.rake ADDED
@@ -0,0 +1,16 @@
1
+ task :setup => "pbuilder:setup" do
2
+ sudo "apt-get install devscripts"
3
+ end
4
+
5
+ namespace :setup do
6
+
7
+ task :ubuntu do
8
+ get 'http://fr.archive.ubuntu.com/ubuntu/pool/main/u/ubuntu-keyring/ubuntu-keyring_2008.03.04_all.deb'
9
+ sudo "dpkg -i ubuntu-keyring_2008.03.04_all.deb"
10
+ end
11
+
12
+ end
13
+
14
+ task "clean" => "packages:clean" do
15
+ rm_rf "build"
16
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake-debian-build
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Alban Peignier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-01 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.3
24
+ version:
25
+ description: ""
26
+ email:
27
+ - alban.peignier@free.fr
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - Manifest.txt
34
+ files:
35
+ - Manifest.txt
36
+ - README.rdoc
37
+ - Rakefile
38
+ - lib/debian/build.rb
39
+ - lib/debian/build/abstract_package.rb
40
+ - lib/debian/build/build_directory_methods.rb
41
+ - lib/debian/build/config.rb
42
+ - lib/debian/build/distribution.rb
43
+ - lib/debian/build/helper_methods.rb
44
+ - lib/debian/build/module_package.rb
45
+ - lib/debian/build/package.rb
46
+ - lib/debian/build/pbuilder.rb
47
+ - lib/debian/build/platform.rb
48
+ - lib/debian/build/source_providers.rb
49
+ - lib/debian/build/tasks.rb
50
+ - lib/debian/build/uploader.rb
51
+ - rake-debian-build.gemspec
52
+ - script/pbuilder
53
+ - spec/debian/build/source_providers_spec.rb
54
+ - spec/debian/build/uploader_spec.rb
55
+ - spec/spec_helper.rb
56
+ - tasks/packages.rake
57
+ - tasks/pbuilder.rake
58
+ - tasks/setup.rake
59
+ has_rdoc: true
60
+ homepage: http://github.com/albanpeignier/rake-debian-build
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --main
66
+ - README.txt
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project: rake-debian-build
84
+ rubygems_version: 1.3.5
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Rake tasks to build debian packages
88
+ test_files: []
89
+