[SCM] ci-tooling packaging branch, master, updated. c7d4e157c7c1b63bba14b4f2ed22e06e60066191

Rohan Garg rohangarg-guest at moszumanska.debian.org
Fri Jun 12 21:59:06 UTC 2015


Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=c7d4e15

The following commit has been merged in the master branch:
commit c7d4e157c7c1b63bba14b4f2ed22e06e60066191
Author: Rohan Garg <rohan at garg.io>
Date:   Fri Jun 12 23:58:51 2015 +0200

    Refactor VcsSourceBuilder to return a CI::Source object
    
    ( This should have been there in the previous commit )
---
 lib/ci/build_source.rb | 105 +++++++++++++++++++++++++------------------------
 lib/ci/source.rb       |   6 +--
 2 files changed, 56 insertions(+), 55 deletions(-)

diff --git a/lib/ci/build_source.rb b/lib/ci/build_source.rb
index 798a6b2..31438aa 100644
--- a/lib/ci/build_source.rb
+++ b/lib/ci/build_source.rb
@@ -1,23 +1,45 @@
 require 'date'
 require 'fileutils'
+require 'yaml'
 
 require_relative '../debian/changelog'
-require_relative '../os'
 require_relative '../debian/source'
-require_relative 'source'
+require_relative '../os'
 require_relative 'build_version'
+require_relative 'source'
 
 # Class to build out source package from a VCS
 class VcsSourceBuilder
+  BUILD_DIR = 'build/'
+
+  def initialize(args = {})
+    @series = args[:series]
+    @flavor = OS::ID.to_sym
+    @data = YAML.load_file("#{File.dirname(__FILE__)}/data/maintainer.yaml")
+
+    @source = CI::Source.new
+    changelog = nil
+    Dir.chdir('packaging') do
+      @source.type = Debian::Source.new(Dir.pwd).format.type
+      changelog = Changelog.new
+      fail "Can't parse changelog!" if changelog.nil?
+    end
+
+    @source.name = changelog.name
+    build_version = CI::BuildVersion.new(changelog)
+    @source.version = build_version.base if @source.type == :native
+    @source.version = build_version.full if @source.type == :quilt
+    @tar_version = build_version.tar
+  end
+
   def copy_source
     # copy sources around
-    FileUtils.rm_r('build') if File.exist?('build')
-    FileUtils.mkpath('build/source/')
-
-    # All done for native packages
-    return if @source.format.type == :native
+    FileUtils.rm_r(BUILD_DIR) if File.exist?(BUILD_DIR)
+    FileUtils.mkpath("#{BUILD_DIR}/source")
 
-    FileUtils.cp_r(Dir.glob('source/*'), 'build/source/', verbose: true)
+    unless @source.type == :native
+      FileUtils.cp_r(Dir.glob('source/*'), 'build/source/', verbose: true)
+    end
 
     %w(.bzr .git .hg .svn).each do |vcsdir|
       FileUtils.rm_rf(Dir.glob("build/source/**/#{vcsdir}"))
@@ -25,8 +47,8 @@ class VcsSourceBuilder
   end
 
   def create_orig_tar
-    Dir.chdir('build/') do
-      tar = "#{@name}_#{@version}.orig.tar"
+    Dir.chdir(BUILD_DIR) do
+      tar = "#{@source.name}_#{@tar_version}.orig.tar"
       fail 'Failed to create a tarball' unless system("tar -cf #{tar} source")
       fail 'Failed to compress the tarball' unless system("xz -6 #{tar}")
     end
@@ -34,19 +56,20 @@ class VcsSourceBuilder
 
   def copy_packaging
     # Copy some more
-    FileUtils.cp_r(Dir.glob("packaging/*"), "build/source/", verbose: true)
+    FileUtils.cp_r(Dir.glob('packaging/*'), 'build/source/', verbose: true)
 
     # Rip out locale install
-    Dir.chdir("build/source/") do
-      Dir.glob("debian/*.install").each do |install_file_path|
+    Dir.chdir('build/source/') do
+      Dir.glob('debian/*.install').each do |install_file_path|
         # Strip localized manpages
         # e.g.  usr /share /man /  *  /man 7 /kf5options.7
-        subbed = File.open(install_file_path).read().gsub(/^.*usr\/share\/man\/(\*|\w+)\/man\d\/.*$/, '')
+        subbed = File.open(install_file_path).read.gsub(%r{^.*usr\/share\/man\/(\*|\w+)\/man\d\/.*$/}, '')
         File.open(install_file_path, 'w') do |f|
           f << subbed
         end
 
-        # FIXME: bloody workaround for kconfigwidgets and kdelibs4support containing legit locale data
+        # FIXME: bloody workaround for kconfigwidgets and kdelibs4support
+        # containing legit locale data
         next if @name == 'kconfigwidgets' ||
                 @name == 'kdelibs4support'
 
@@ -55,24 +78,27 @@ class VcsSourceBuilder
           f << subbed
         end
       end
-      # If the package is now empty, lintian override the empty warning to avoid false positives
-      Dir.glob("debian/*.install").each do |install_file_path|
+      # If the package is now empty, lintian override the empty warning
+      # to avoid false positives
+      Dir.glob('debian/*.install').each do |install_file_path|
         next unless File.open(install_file_path, 'r').read.strip.empty?
         package_name = File.basename(install_file_path, '.install')
-        lintian_overrides_path = install_file_path.gsub('.install', '.lintian-overrides')
+        lintian_overrides_path = install_file_path.gsub('.install',
+                                                        '.lintian-overrides')
         puts "#{package_name} is now empty, trying to add lintian override"
-        File.open(lintian_overrides_path, 'a') { |file| file.write("#{package_name}: empty-binary-package
") }
+        File.open(lintian_overrides_path, 'a') do |file|
+          file.write("#{package_name}: empty-binary-package
")
+        end
       end
     end
   end
 
   def log_change
     # Create changelog entry
-    Dir.chdir('build/source/') do
+    Dir.chdir("#{BUILD_DIR}/source/") do
       ENV['DEBFULLNAME'] = @data[@flavor][:name]
       ENV['DEBEMAIL'] = @data[@flavor][:email]
-      # FXIME project undefined
-      unless system("dch -b -v #{@package_version} -D #{@series} \
+      unless system("dch -b -v #{@source.version} -D #{@series} \
                     'Automatic #{@flavor.capitalize} CI Build'")
         fail 'Failed to create changelog entry'
       end
@@ -81,44 +107,19 @@ class VcsSourceBuilder
 
   def build
     # dpkg-buildpackage
-    Dir.chdir('build/source/') do
+    Dir.chdir("#{BUILD_DIR}/source/") do
       system('update-maintainer')
-      fail 'Failed to build source package' unless system('dpkg-buildpackage -us -uc -S -d')
+      return if system('dpkg-buildpackage', '-us', '-uc', '-S', '-d')
+      fail 'Could not run dpkg-buildpackage!'
     end
   end
 
-  def run(args = {})
-    @series = args[:series]
-    @flavor = OS::ID.to_sym
-
-    @data = { ubuntu: { name: 'Kubuntu CI',
-                        email: 'kubuntu-ci at lists.launchpad.net' },
-              debian: { name: 'Debian CI',
-                        email: 'null at debian.org' }
-    }
-    # version
-    changelog = nil
-    Dir.chdir('packaging') do
-      @source = Debian::Source.new(Dir.pwd)
-      changelog = Changelog.new
-    end
-
-    @name = changelog.name
-    build_version = CI::BuildVersion.new(changelog)
-    @package_version = build_version.base if @source.format.type == :native
-    @package_version = build_version.full if @source.format.type == :quilt
-    @version = build_version.tar
-
+  def run
     copy_source
     create_orig_tar
     copy_packaging
     log_change
     build
-
-    s = Source.new
-    s['name'] = @name
-    s['version'] = @version
-    s['type'] = @source.format.type
-    s
+    @source
   end
 end
diff --git a/lib/ci/source.rb b/lib/ci/source.rb
index e4c21cf..19effd3 100644
--- a/lib/ci/source.rb
+++ b/lib/ci/source.rb
@@ -3,9 +3,9 @@ require 'json'
 module CI
   # Build source descriptor
   class Source
-    attr_reader :name
-    attr_reader :version
-    attr_reader :type
+    attr_accessor :name
+    attr_accessor :version
+    attr_accessor :type
 
     def []=(key, value)
       var = "@#{key}".to_sym

-- 
ci-tooling packaging



More information about the pkg-kde-commits mailing list