Class: Debian::Build::Package

Inherits:
AbstractPackage show all
Defined in:
lib/debian/build/package.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractPackage

#default_platforms, #initialize, #requires_sources?, #to_s

Methods included from BuildDirectoryMethods

#build_directory, #build_directory=

Methods included from HelperMethods

#get, #sudo, #uncompress

Constructor Details

This class inherits a constructor from Debian::Build::AbstractPackage

Instance Attribute Details

#debian_incrementObject

Returns the value of attribute debian_increment.



5
6
7
# File 'lib/debian/build/package.rb', line 5

def debian_increment
  @debian_increment
end

#exclude_from_buildObject

Returns the value of attribute exclude_from_build.



5
6
7
# File 'lib/debian/build/package.rb', line 5

def exclude_from_build
  @exclude_from_build
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/debian/build/package.rb', line 4

def name
  @name
end

#packageObject

Returns the value of attribute package.



5
6
7
# File 'lib/debian/build/package.rb', line 5

def package
  @package
end

#signing_keyObject

Returns the value of attribute signing_key.



5
6
7
# File 'lib/debian/build/package.rb', line 5

def signing_key
  @signing_key
end

#source_providerObject

Returns the value of attribute source_provider.



5
6
7
# File 'lib/debian/build/package.rb', line 5

def source_provider
  @source_provider
end

#versionObject

Returns the value of attribute version.



5
6
7
# File 'lib/debian/build/package.rb', line 5

def version
  @version
end

Instance Method Details

#changes_filesObject



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/debian/build/package.rb', line 160

def changes_files
  changes_files = Dir.glob("#{sources_directory}/#{package}_#{debian_version}*_source.changes")

  Platform.each do |platform|
    platform_changes_files = Dir.glob("#{platform.build_result_directory}/#{package}_#{debian_version}*_#{platform.architecture}.changes")

    unless platform_changes_files.empty?
      # deb packages for architect all shouldn't be uploaded twice
      sh "sed -i '/_all.deb/ d' #{platform_changes_files.join(' ')}" if platform.architecture != 'i386'

      changes_files << platform_changes_files
    end
  end

  changes_files.flatten!
  changes_files
end

#copy_debian_filesObject



135
136
137
138
# File 'lib/debian/build/package.rb', line 135

def copy_debian_files
  rm_rf "#{source_directory}/debian"
  cp_r debian_directory, "#{source_directory}/debian"
end

#debian_directoryObject



140
141
142
# File 'lib/debian/build/package.rb', line 140

def debian_directory
  ["debian", "#{package}/debian"].find { |d| File.exists?(d) }
end

#debian_versionObject



156
157
158
# File 'lib/debian/build/package.rb', line 156

def debian_version
  "#{version}-#{debian_increment}"   
end

#defineObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/debian/build/package.rb', line 22

def define
  load_debian_version_from_changelog
  raise "Version must be set" if version.nil?

  namespace @name do
    namespace "source" do

      desc "Retrieve source for #{package} #{version}"
      task "directory" do
        mkdir_p sources_directory
        Dir.chdir(sources_directory) do
          @source_provider.retrieve(self)
        end

        copy_debian_files
      end

      Distribution.each do |distribution|
        desc "Build source package for #{package} #{version} on #{distribution}"
        task distribution.task_name => :directory do
          copy_debian_files

          dch_options="--preserve --force-distribution"
          Dir.chdir(source_directory) do  
            if not distribution.ubuntu? and distribution.unstable?
              sh "dch #{dch_options} --distribution 'unstable' --release ''"              
            else
              sh "dch #{dch_options} --local #{local_name(distribution)} --distribution #{distribution} 'Release from unstable'"
            end

            dpkg_buildpackage_options = []

            if signing_key
              dpkg_buildpackage_options << "-k#{signing_key}"
            else
              dpkg_buildpackage_options << "-us -uc"
            end

            if ENV['ORIGINAL_SOURCE']
              dpkg_buildpackage_options << "-sa"
            end

            sh "dpkg-buildpackage -rfakeroot #{dpkg_buildpackage_options.join(' ')} -S -I.git"
          end
        end
      end
      
      desc "Build source packages for #{package} #{version}"
      task :all => Distribution.all.collect { |distribution| distribution.task_name }
    end

    namespace :pbuild do
      Platform.each do |platform|
        desc "Pbuild #{platform} binary package for #{package} #{version}"
        task platform.task_name do |t, args|
          pbuilder_options = {
            :logfile => "#{platform.build_result_directory}/pbuilder-#{package}-#{debian_version}.log"
          }
          platform.pbuilder(pbuilder_options).exec :build, dsc_file(platform)
        end
      end

      desc "Pbuild binary package for #{package} #{version} (on #{default_platforms.join(', ')})"
      task :all => default_platforms.collect { |platform| platform.task_name }

    end

    desc "Upload packages for #{package} #{version}"
    task "upload" do
      Uploader.default.dupload changes_files
    end

    desc "Run lintian on package #{package}"
    task "lintian" do
      redirect = ENV['LINTIAN_OUTPUT'] ? ">> #{ENV['LINTIAN_OUTPUT']}" : ""
      sh "lintian #{changes_files.join(' ')} #{redirect}"
    end

    desc "Clean files created for #{package} #{version}"
    task "clean" do
      cleaned_files = []

      Platform.each do |platform|
        cleaned_files.push *package_files(platform.build_result_directory)
      end

      cleaned_files.push *package_source_files
      cleaned_files.push  "#{sources_directory}/#{orig_source_tarball_name}"

      rm_f cleaned_files unless cleaned_files.empty?
      rm_rf source_directory if File.directory?(source_directory)
    end
  end
end

#dsc_file(platform) ⇒ Object



125
126
127
128
129
130
131
132
133
# File 'lib/debian/build/package.rb', line 125

def dsc_file(platform)
  suffix = 
    if local_name = local_name(platform)
      "#{local_name}1"
    else
      ""
    end
  File.expand_path "#{Package.build_directory}/sources/#{package}_#{debian_version}#{suffix}.dsc"
end

#get_bindingObject



202
203
204
# File 'lib/debian/build/package.rb', line 202

def get_binding
  binding
end

#initObject



7
8
9
10
11
12
# File 'lib/debian/build/package.rb', line 7

def init
  @debian_increment = 1
  # TODO use a class attribute
  @signing_key = ENV['KEY']
  @source_provider = AptSourceProvider.new
end

#load_debian_version_from_changelogObject



14
15
16
17
18
19
20
# File 'lib/debian/build/package.rb', line 14

def load_debian_version_from_changelog
  first_changelog_line = IO.readlines("debian/changelog").first
  if first_changelog_line =~ /^#{package} \(([0-9.]+)-([0-9]+)\)/
    self.version = $1
    self.debian_increment = $2
  end
end

#local_name(distribution) ⇒ Object



117
118
119
120
121
122
123
# File 'lib/debian/build/package.rb', line 117

def local_name(distribution)
  unless distribution.unstable?
    distribution.local_name
  else
    "ubuntu" if distribution.ubuntu?  
  end
end

#orig_source_tarball_nameObject



148
149
150
# File 'lib/debian/build/package.rb', line 148

def orig_source_tarball_name
  "#{package}_#{version}.orig.tar.gz"
end

#package_deb_files(directory = '.') ⇒ Object



198
199
200
# File 'lib/debian/build/package.rb', line 198

def package_deb_files(directory = '.')
  package_files(directory).find_all { |f| f.match /\.deb$/ }
end

#package_files(directory = '.') ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/debian/build/package.rb', line 178

def package_files(directory = '.')
  fileparts = [ name.to_s ]
  case name
  when :hpklinux
    fileparts << 'libhpi'
  when :rivendell
    fileparts << 'librivendell'
  end

  fileparts.inject([]) do |files, filepart|
    files + Dir.glob("#{directory}/#{filepart}*#{debian_version}*")
  end
end

#package_source_filesObject



192
193
194
195
196
# File 'lib/debian/build/package.rb', line 192

def package_source_files
  %w{.dsc .tar.gz _source.changes}.collect do |extension|
    "#{sources_directory}/#{package}_#{debian_version}#{extension}"
  end
end

#source_directoryObject



152
153
154
# File 'lib/debian/build/package.rb', line 152

def source_directory
  "#{sources_directory}/#{name}-#{version}"
end

#sources_directoryObject



144
145
146
# File 'lib/debian/build/package.rb', line 144

def sources_directory
  "#{Package.build_directory}/sources"
end