albanpeignier-rake-debian-build 1.0 → 1.0.1

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
+ lib/ruby_pbuilder.rb
18
+ rake-debian-build.gemspec
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,124 @@
1
+ = Gepetto
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 tarball download, dpkg-buildpackage, dch, pbuilder, dupload, builds for stable/testing/unstable/hardy/intrepid i386/amd64, etc ...
10
+
11
+ == FEATURES:
12
+
13
+ * sources download (tarball 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:
25
+
26
+ require 'debian/build'
27
+ include Debian::Build
28
+
29
+ require 'debian/build/config'
30
+
31
+ namespace "package" do
32
+
33
+ Package.new(:hpklinux) do |p|
34
+ p.version = '3.08.05'
35
+ p.debian_increment = 2
36
+
37
+ p.source_provider = TarballSourceProvider.new('http://www.rivendellaudio.org/ftpdocs/audioscience/hpklinux-#{version}.tar.bz2')
38
+ end
39
+
40
+ main_source_provider = TarballSourceProvider.new('http://www.rivendellaudio.org/ftpdocs/#{name}/#{name}-#{version}.tar.gz')
41
+
42
+ Package.new(:rivendell) do |p|
43
+ p.version = '1.3.0'
44
+ p.debian_increment = 1
45
+ p.source_provider = main_source_provider
46
+ end
47
+
48
+ Package.new(:gpio) do |p|
49
+ p.version = '1.0.0'
50
+ p.debian_increment = 2
51
+ p.source_provider = main_source_provider
52
+ end
53
+
54
+ ModulePackage.new('gpio-module')
55
+
56
+ ModulePackage.new('hpklinux-module')
57
+
58
+ end
59
+
60
+ require 'debian/build/tasks'
61
+
62
+ Configure your environement (in config.rb) :
63
+
64
+ Distribution.mirrors = {
65
+ :debian => 'http://localhost:9999/debian',
66
+ :ubuntu => 'http://localhost:9999/ubuntu'
67
+ }
68
+
69
+ Uploader.default.host = "debian.tryphon.org"
70
+ Uploader.default.nickname = "tryphon"
71
+
72
+ Setup your environment:
73
+
74
+ rake setup
75
+
76
+ Create pbuilder images:
77
+
78
+ rake pbuilder:create
79
+
80
+ Build all source package
81
+
82
+ rake packages:sources
83
+
84
+ Build all binary package
85
+
86
+ rake packages:binaries
87
+
88
+ Upload all packages
89
+
90
+ rake packages:upload
91
+
92
+ == REQUIREMENTS:
93
+
94
+ * pbuilder, dupload, devscripts
95
+
96
+ == INSTALL:
97
+
98
+ gem sources -a http://gems.github.com
99
+ sudo gem install albanpeignier-rake-debian-build
100
+
101
+ == LICENSE:
102
+
103
+ (The MIT License)
104
+
105
+ Copyright (c) 2009 Alban Peignier
106
+
107
+ Permission is hereby granted, free of charge, to any person obtaining
108
+ a copy of this software and associated documentation files (the
109
+ 'Software'), to deal in the Software without restriction, including
110
+ without limitation the rights to use, copy, modify, merge, publish,
111
+ distribute, sublicense, and/or sell copies of the Software, and to
112
+ permit persons to whom the Software is furnished to do so, subject to
113
+ the following conditions:
114
+
115
+ The above copyright notice and this permission notice shall be
116
+ included in all copies or substantial portions of the Software.
117
+
118
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
119
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
120
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
121
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
122
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
123
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
124
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
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.1') do |p|
6
+ p.developer("Alban Peignier", "alban.peignier@free.fr")
7
+ p.summary = "Rake tasks to build debian packages"
8
+
9
+ p.rubyforge_name = p.name # TODO this is default value
10
+
11
+ p.clean_globs |= %w[**/.DS_Store *~]
12
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
13
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
14
+ p.rsync_args = '-av --delete --ignore-errors'
15
+ end
16
+
17
+ desc 'Recreate Manifest.txt to include ALL files'
18
+ task :manifest do
19
+ `rake check_manifest | patch -p0 > Manifest.txt`
20
+ end
21
+
22
+ desc "Generate a #{$hoe.name}.gemspec file"
23
+ task :gemspec do
24
+ File.open("#{$hoe.name}.gemspec", "w") do |file|
25
+ file.puts $hoe.spec.to_ruby
26
+ end
27
+ 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}.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, :intrepid ].include? distribution
50
+ end
51
+
52
+ @@local_names = { :stable => 'lenny', :testing => 'squeeze', :intrepid => 'ubuntu', :hardy => 'hardy' }
53
+ def local_name
54
+ @@local_names[distribution]
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,45 @@
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.rsync Dir["#{platform.build_result_directory}/#{package}-*.deb"], platform.distribution
33
+ end
34
+ end
35
+
36
+ # TODO : remove this mock
37
+ namespace :source do
38
+ task :all
39
+ end
40
+
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,179 @@
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
+ unless distribution.ubuntu?
38
+ if distribution.unstable?
39
+ sh "dch #{dch_options} --distribution 'unstable' --release ''"
40
+ else
41
+ sh "dch #{dch_options} --local #{distribution.local_name} --distribution #{distribution} 'Release from unstable'"
42
+ end
43
+ else
44
+ if distribution.unstable?
45
+ sh "dch #{dch_options} --local ubuntu --distribution #{distribution} 'Release from debian/unstable'"
46
+ else
47
+ sh "dch #{dch_options} --local #{distribution.local_name} --distribution #{distribution} 'Release from unstable'"
48
+ end
49
+ end
50
+
51
+ dpkg_buildpackage_options = []
52
+
53
+ if signing_key
54
+ dpkg_buildpackage_options << "-k#{signing_key}"
55
+ else
56
+ dpkg_buildpackage_options << "-us -uc"
57
+ end
58
+
59
+ if ENV['ORIGINAL_SOURCE']
60
+ dpkg_buildpackage_options << "-sa"
61
+ end
62
+
63
+ sh "dpkg-buildpackage -rfakeroot #{dpkg_buildpackage_options.join(' ')} -S -I.git"
64
+ end
65
+ end
66
+ end
67
+
68
+ desc "Build source packages for #{package} #{version}"
69
+ task :all => Distribution.all.collect { |distribution| distribution.task_name }
70
+ end
71
+
72
+ namespace :pbuild do
73
+ Platform.each do |platform|
74
+ desc "Pbuild #{platform} binary package for #{package} #{version}"
75
+ task platform.task_name do |t, args|
76
+ pbuilder_options = {
77
+ :logfile => "#{platform.build_result_directory}/pbuilder-#{package}-#{debian_version}.log"
78
+ }
79
+ platform.pbuilder(pbuilder_options).exec :build, dsc_file(platform)
80
+ end
81
+ end
82
+
83
+ desc "Pbuild binary package for #{package} #{version} (on #{default_platforms.join(', ')})"
84
+ task :all => default_platforms.collect { |platform| platform.task_name }
85
+
86
+ end
87
+
88
+ desc "Upload packages for #{package} #{version}"
89
+ task "upload" do
90
+ changes_files = Dir.glob("#{sources_directory}/#{package}_#{debian_version}*_source.changes")
91
+
92
+ Platform.each do |platform|
93
+ platform_changes_files = Dir.glob("#{platform.build_result_directory}/#{package}_#{debian_version}*_#{platform.architecture}.changes")
94
+
95
+ unless platform_changes_files.empty?
96
+ # deb packages for architect all shouldn't be uploaded twice
97
+ sh "sed -i '/_all.deb/ d' #{platform_changes_files.join(' ')}" if platform.architecture != 'i386'
98
+
99
+ changes_files << platform_changes_files
100
+ end
101
+ end
102
+
103
+ changes_files.flatten!
104
+
105
+ Uploader.default.dupload changes_files
106
+ end
107
+
108
+ desc "Clean files created for #{package} #{version}"
109
+ task "clean" do
110
+ Platform.each do |platform|
111
+ rm_f package_files(platform.build_result_directory)
112
+ end
113
+
114
+ rm_f package_source_files
115
+
116
+ rm_f "#{sources_directory}/#{source_tarball_name}"
117
+ rm_f "#{sources_directory}/#{orig_source_tarball_name}"
118
+ rm_rf "#{source_directory}"
119
+ end
120
+ end
121
+ end
122
+
123
+ def dsc_file(platform)
124
+ suffix =
125
+ if local_name = platform.local_name
126
+ "#{local_name}1"
127
+ else
128
+ ""
129
+ end
130
+ File.expand_path "#{Package.build_directory}/sources/#{package}_#{debian_version}#{suffix}.dsc"
131
+ end
132
+
133
+ def copy_debian_files
134
+ rm_rf "#{source_directory}/debian"
135
+ cp_r "#{package}/debian", "#{source_directory}/debian"
136
+ end
137
+
138
+ def sources_directory
139
+ "#{Package.build_directory}/sources"
140
+ end
141
+
142
+ def orig_source_tarball_name
143
+ "#{package}_#{version}.orig.tar.gz"
144
+ end
145
+
146
+ def source_directory
147
+ "#{sources_directory}/#{name}-#{version}"
148
+ end
149
+
150
+ def debian_version
151
+ "#{version}-#{debian_increment}"
152
+ end
153
+
154
+ def package_files(directory = '.')
155
+ fileparts = [ name.to_s ]
156
+ case name
157
+ when :hpklinux
158
+ fileparts << 'libhpi'
159
+ when :rivendell
160
+ fileparts << 'librivendell'
161
+ end
162
+
163
+ fileparts.inject([]) do |files, filepart|
164
+ files + Dir.glob("#{directory}/#{filepart}*#{debian_version}*")
165
+ end
166
+ end
167
+
168
+ def package_source_files
169
+ %w{.dsc .tar.gz _source.changes}.collect do |extension|
170
+ "#{sources_directory}/#{package}_#{debian_version}#{extension}"
171
+ end
172
+ end
173
+
174
+ def package_deb_files(directory = '.')
175
+ package_files(directory).find_all { |f| f.match /\.deb$/ }
176
+ end
177
+
178
+ end
179
+ 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,112 @@
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
+
16
+ def initialize(distribution, architecture)
17
+ @distribution = distribution
18
+ @architecture = architecture
19
+ end
20
+
21
+ def self.supported_architectures
22
+ %w{i386 amd64}
23
+ end
24
+
25
+ def self.all
26
+ @@all ||=
27
+ Distribution.all.collect do |distribution|
28
+ supported_architectures.collect { |architecture| Platform.new(distribution, architecture) }
29
+ end.flatten
30
+ end
31
+
32
+ def self.each(&block)
33
+ all.each &block
34
+ end
35
+
36
+ def build_result_directory
37
+ File.expand_path "#{Platform.build_directory}/binaries/#{distribution}/#{architecture}"
38
+ end
39
+
40
+ def pbuilder_base_file
41
+ "/var/cache/pbuilder/base-#{distribution}-#{architecture}.tgz"
42
+ end
43
+
44
+ def pbuilder_enabled?
45
+ File.exists? pbuilder_base_file
46
+ end
47
+
48
+ def pbuilder(options = {})
49
+ PBuilder.new do |p|
50
+ p[:basetgz] = pbuilder_base_file
51
+ p[:othermirror] = "'deb file:#{build_result_directory} ./'"
52
+ p[:bindmounts] = p[:buildresult] = build_result_directory
53
+ p[:distribution] = distribution
54
+ p[:hookdir] = default_hooks_directory
55
+
56
+ # to use i386 on amd64 architecture
57
+ p[:debootstrapopts] = [ "--arch=#{architecture}" ]
58
+ p[:debbuildopts] = [ "-a#{architecture}", '-b' ]
59
+
60
+ p[:mirror] = mirror
61
+
62
+ if flavor == :ubuntu
63
+ # cdebootstrap fails with ubuntu
64
+ p[:components] = "'main universe'"
65
+ p[:debootstrap] = 'debootstrap'
66
+ end
67
+
68
+ p.options = options
69
+
70
+ p.before_exec Proc.new {
71
+ prepare_build_result_directory
72
+ prepare_default_hooks
73
+ }
74
+ end
75
+ end
76
+
77
+ def default_hooks_directory
78
+ "#{Package.build_directory}/tmp/hooks"
79
+ end
80
+
81
+ def prepare_build_result_directory
82
+ mkdir_p build_result_directory
83
+
84
+ Dir.chdir(build_result_directory) do
85
+ sh "/usr/bin/dpkg-scanpackages . /dev/null > Packages"
86
+ end
87
+ end
88
+
89
+ def prepare_default_hooks
90
+ mkdir_p default_hooks_directory
91
+
92
+ apt_update_hook_file = "#{default_hooks_directory}/D80apt-get-update"
93
+ unless File.exists?(apt_update_hook_file)
94
+ File.open(apt_update_hook_file, "w") do |f|
95
+ f.puts "#!/bin/sh"
96
+ f.puts "apt-get update"
97
+ end
98
+
99
+ FileUtils.chmod 0755, apt_update_hook_file
100
+ end
101
+ end
102
+
103
+ def to_s(separator = '/')
104
+ "#{distribution}#{separator}#{architecture}"
105
+ end
106
+
107
+ def task_name
108
+ to_s '_'
109
+ end
110
+
111
+ end
112
+ end
@@ -0,0 +1,75 @@
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
+ unless @tarball_url
44
+ def package.get_binding
45
+ binding
46
+ end
47
+
48
+ @tarball_url = eval( '"' + @url + '"', package.get_binding)
49
+ end
50
+
51
+ @tarball_url
52
+ end
53
+
54
+ def tarball_name
55
+ File.basename URI.parse(tarball_url).path
56
+ end
57
+
58
+ def orig_tarball_name
59
+ package.orig_source_tarball_name
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
66
+ class AptSourceProvider
67
+ include FileUtils
68
+
69
+ def retrieve(package)
70
+ sh "apt-get source #{package.name}"
71
+ end
72
+
73
+ end
74
+
75
+ 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
+ @@default = Uploader.new
9
+ def self.default; @@default end
10
+
11
+ # TODO nickname could be used to determinate incoming and host
12
+ attr_accessor :nickname
13
+ attr_accessor :incoming, :host
14
+
15
+ def initialize
16
+ self.incoming = '/var/lib/debarchiver/incoming'
17
+ end
18
+
19
+ def lock(&block)
20
+ raise "No defined host, can't create lock file in ssh" unless host
21
+
22
+ begin
23
+ sh "ssh #{host} touch #{lock_file}"
24
+ yield
25
+ ensure
26
+ sh "ssh #{host} rm -f #{lock_file}"
27
+ end
28
+ end
29
+
30
+ def lock_file
31
+ File.join(incoming, "debarchiver.lock")
32
+ end
33
+
34
+ def dupload(*changes_files)
35
+ options = ['-t', nickname] if nickname
36
+ sh *["dupload", options, changes_files].flatten.compact
37
+ end
38
+
39
+ def rsync(target_directory, *files)
40
+ sh "rsync -av #{files.join(' ')} #{host}:#{incoming}/#{target_directory}"
41
+ 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,14 @@
1
+ require "ruby_pbuilder/build_directory_methods"
2
+ require "ruby_pbuilder/helper_methods"
3
+
4
+ require "ruby_pbuilder/distribution"
5
+ require "ruby_pbuilder/platform"
6
+
7
+ require "ruby_pbuilder/pbuilder"
8
+
9
+ require "ruby_pbuilder/source_providers"
10
+
11
+ require "ruby_pbuilder/abstract_package"
12
+ require "ruby_pbuilder/package"
13
+ require "ruby_pbuilder/module_package"
14
+
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rake-debian-build}
5
+ s.version = "1.0.1"
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-04-12}
10
+ s.email = ["alban.peignier@free.fr"]
11
+ s.extra_rdoc_files = ["Manifest.txt"]
12
+ 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", "lib/ruby_pbuilder.rb", "rake-debian-build.gemspec", "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"]
13
+ s.has_rdoc = true
14
+ s.rdoc_options = ["--main", "README.txt"]
15
+ s.require_paths = ["lib"]
16
+ s.rubyforge_project = %q{rake-debian-build}
17
+ s.rubygems_version = %q{1.3.1}
18
+ s.summary = %q{Rake tasks to build debian packages}
19
+
20
+ if s.respond_to? :specification_version then
21
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
22
+ s.specification_version = 2
23
+
24
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
+ s.add_development_dependency(%q<hoe>, [">= 1.12.1"])
26
+ else
27
+ s.add_dependency(%q<hoe>, [">= 1.12.1"])
28
+ end
29
+ else
30
+ s.add_dependency(%q<hoe>, [">= 1.12.1"])
31
+ end
32
+ end
@@ -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,73 @@
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" do
34
+
35
+ before(:each) do
36
+ @uploader.stub!(:sh)
37
+
38
+ @uploader.host = "host"
39
+ @uploader.stub!(:lock_file).and_return("lock")
40
+ end
41
+
42
+ it "should raise an error when no host is defined" do
43
+ @uploader.host = nil
44
+ lambda { @uploader.lock { } }.should raise_error
45
+ end
46
+
47
+ it "should create a lock file in ssh" do
48
+ @uploader.should_receive(:sh).with("ssh host touch lock")
49
+ @uploader.lock { }
50
+ end
51
+
52
+ it "should remove the lock file in ssh" do
53
+ @uploader.should_receive(:sh).with("ssh host rm -f lock")
54
+ @uploader.lock { }
55
+ end
56
+
57
+ end
58
+
59
+ describe "rsync" do
60
+
61
+ before(:each) do
62
+ @uploader.host = "host"
63
+ @uploader.incoming = "/path/to/incoming"
64
+ end
65
+
66
+ it "should rsync givenl files to incoming target directory" do
67
+ @uploader.should_receive(:sh).with("rsync -av #{@files.join(' ')} host:/path/to/incoming/target")
68
+ @uploader.rsync("target",@files)
69
+ end
70
+
71
+ end
72
+
73
+ 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,29 @@
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
+ end
28
+
29
+ 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: albanpeignier-rake-debian-build
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alban Peignier
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-11 00:00:00 -07:00
12
+ date: 2009-04-12 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -29,10 +29,33 @@ executables: []
29
29
 
30
30
  extensions: []
31
31
 
32
- extra_rdoc_files: []
33
-
34
- files: []
35
-
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
+ - lib/ruby_pbuilder.rb
52
+ - rake-debian-build.gemspec
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
36
59
  has_rdoc: true
37
60
  homepage:
38
61
  post_install_message: