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

Harald Sitter apachelogger-guest at moszumanska.debian.org
Wed Mar 25 12:01:20 UTC 2015


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

The following commit has been merged in the master branch:
commit b7c9086279656c8523107f17c6e7c192270e0020
Author: Harald Sitter <sitter at kde.org>
Date:   Wed Mar 25 13:01:16 2015 +0100

    implement a global override for upstream_scm
    
    global overrides are stored in one file, versus per branch as we had
    previously. per branch setting turned out to be a really bad choice
    because we merge stable -> unstable and since stable's override changes
    ever so often we'd have to undo the change in unstable each time, this is
    very annoying and crappy and causes pointless commits. so... instead we
    have the global override which presently trumps the repo override (which
    is slightly weird). it does so for now as repo overrides may be in place
    where we don't want or need them. once someone does a cleanup run across
    all repos we can either switch the order around or drop repo overrides
    entirely. personally I'd prefer only using the global override so
    we can easily expand and manage overrides.
---
 data/upstream-scm.yml     |   7 ++++
 lib/ci/upstream_scm.rb    | 104 ++++++++++++++++++++++++++++++++++++++++------
 lib/projects.rb           |   7 +---
 test/test_upstream_scm.rb |  20 +++++++--
 4 files changed, 116 insertions(+), 22 deletions(-)

diff --git a/data/upstream-scm.yml b/data/upstream-scm.yml
new file mode 100644
index 0000000..4c31b95
--- /dev/null
+++ b/data/upstream-scm.yml
@@ -0,0 +1,7 @@
+git.debian.org:/git/pkg-kde/plasma/*:
+  kubuntu_stable:
+    branch: Plasma/5.2
+git.debian.org:/git/pkg-kde/qt/*:
+  kubuntu_unstable:
+    url: https://gitorious.org/qt/<%= name >.git
+    branch: 5.4
diff --git a/lib/ci/upstream_scm.rb b/lib/ci/upstream_scm.rb
index c73aea1..17be5fc 100644
--- a/lib/ci/upstream_scm.rb
+++ b/lib/ci/upstream_scm.rb
@@ -1,35 +1,113 @@
+require 'erb'
 require 'json'
+require 'yaml'
 
 # Construct an upstream scm instance and fold in overrides set via
 # meta/upstream_scm.json.
 class UpstreamSCM
+  # Binding context for SCM overrides.
+  # SCM overrides can use ERB syntax to access properties of the context.
+  # Overrides can not access the UpstreamSCM directly!
+  class BindingContext
+    # @return [String] name of the packaging SCM (i.e. basename of path)
+    attr_reader :name
+    # @return [String] full repo URL of the packaging SCM
+    attr_reader :packaging_repo
+    # @return [String] full branch of the packaging SCM
+    attr_reader :packaging_branch
+
+    def initialize(scm)
+      @name = scm.instance_variable_get(:@name)
+      @packaging_repo = scm.instance_variable_get(:@packaging_repo)
+      @packaging_branch = scm.instance_variable_get(:@packaging_branch)
+    end
+
+    public :binding
+  end
+
+  # @return [String] a type identifier (e.g. 'git', 'svn')
   attr_reader :type
+  # @return [String] valid git URL to the SCM
   attr_reader :url
+  # @return [String] git branch of the SCM to use
   attr_reader :branch
 
-  # FIXME: I really don't like how we have to eat name here in order to compose
-  # a default. it's all sorts of meh. Maybe deduce from debian/changelog or
-  # git origin's name?
-  def initialize(name, working_directory)
+  # Constructs an upstream SCM description from a packaging SCM description.
+  #
+  # Upstream SCM settings default to sane KDE settings and can be overridden
+  # via data/upstraem-scm-map.yml. The override file supports pattern matching
+  # according to File.fnmatch and ERB templating using a {BindingContext}.
+  #
+  # @param packaging_repo [String] git URL of the packaging repo
+  # @param packaging_branch [String] branch of the packaging repo
+  # @param working_directory [String] local directory path of directory
+  #   containing debian/ (this is only used for repo-specific overrides)
+  def initialize(packaging_repo, packaging_branch, working_directory = Dir.pwd)
+    @packaging_repo = packaging_repo
+    @packaging_branch = packaging_branch
+    @name = File.basename(packaging_repo)
     @directory = working_directory
 
     @type = 'git'
-    @url = "git://anongit.kde.org/#{name.chomp('-qt4')}"
+    @url = "git://anongit.kde.org/#{@name.chomp('-qt4')}"
     @branch = 'master'
 
-    @type = override['type'] || @type
-    @url = override['url'] || @url
-    @branch = override['branch'] || @branch
+    global_override!
+    repo_override!
   end
 
   private
 
-  def override
-    return @override if defined?(@override)
+  def best_pattern(patterns, reference)
+    best = nil
+    patterns.each do |pattern|
+      next unless File.fnmatch(pattern, reference)
+      best ||= pattern
+      # If best_pattern matches the pattern at hand the new pattern is better
+      # yet as it is a more restrictive version of the current best pattern.
+      best = pattern if File.fnmatch(best, pattern)
+      # If the pattern is a precise match we might as well stop here.
+      break if best == reference
+    end
+    best
+  end
+
+  def override_apply(override)
+    context = BindingContext.new(self)
+
+    [:type, :url, :branch].each do |var|
+      override_value = override.fetch(var.to_s, nil)
+      next unless override_value
+      # Version would be float. Coerce into string.
+      override_value = override_value.to_s
+      override_value = ERB.new(override_value).result(context.binding)
+      next unless override_value
+      instance_variable_set("@#{var}", override_value)
+    end
+  end
+
+  def global_override_load
+    base = File.expand_path(File.dirname(File.dirname(File.dirname(__FILE__))))
+    file = File.join(base, 'data', 'upstream-scm.yml')
+    YAML.load(File.read(file))
+  end
+
+  def global_override!
+    overrides = global_override_load
+    repo_pattern = best_pattern(overrides.keys, @packaging_repo)
+    return unless repo_pattern
+
+    branches = overrides[repo_pattern]
+    branch_pattern = best_pattern(branches.keys, @packaging_branch)
+    return unless branch_pattern
+
+    override_apply(branches[branch_pattern])
+  end
 
-    @override = {}
+  def repo_override!
+    overrides = {}
     file_path = File.join(@directory, 'debian/meta/upstream_scm.json')
-    @override = JSON.parse(File.read(file_path)) if File.exist?(file_path)
-    @override.freeze
+    overrides = JSON.parse(File.read(file_path)) if File.exist?(file_path)
+    override_apply(overrides) unless overrides.empty?
   end
 end
diff --git a/lib/projects.rb b/lib/projects.rb
index fc3d74d..eec3cf3 100644
--- a/lib/projects.rb
+++ b/lib/projects.rb
@@ -94,12 +94,7 @@ class Project
         end
 
         unless Debian::Source.new(Dir.pwd).format.type == :native
-          @upstream_scm = UpstreamSCM.new(name, Dir.pwd)
-          # FIXME: why is this not a repo side override?
-          if component == 'qt'
-            @upstream_scm.instance_variable_set(:@url, "https://gitorious.org/qt/#{name}.git")
-            @upstream_scm.instance_variable_set(:@branch, '5.4')
-          end
+          @upstream_scm = UpstreamSCM.new(@packaging_scm, "kubuntu_#{type}")
         end
 
         # FIXME: Probably should be converted to a symbol at a later point
diff --git a/test/test_upstream_scm.rb b/test/test_upstream_scm.rb
index 62c43a0..77cd290 100644
--- a/test/test_upstream_scm.rb
+++ b/test/test_upstream_scm.rb
@@ -4,14 +4,28 @@ require_relative 'lib/testcase'
 # Test ci/upstream_scm
 class UpstreamSCMTest < TestCase
   def test_defaults
-    scm = UpstreamSCM.new('breeze-qt4', '/')
+    scm = UpstreamSCM.new('breeze-qt4', 'kubuntu_unstable', '/')
     assert_equal('git', scm.type)
     assert_equal('git://anongit.kde.org/breeze', scm.url)
     assert_equal('master', scm.branch)
   end
 
+  # FIXME: this currenctly tests live config because upstream_scm has no way
+  # to override the global config
+  def test_global_override
+    base = 'git.debian.org:/git/pkg-kde'
+    workspace = "#{base}/plasma/plasma-workspace"
+    qt = "#{base}/qt/qtbase"
+    scm = UpstreamSCM.new(workspace, 'kubuntu_stable', '/')
+    assert_equal('Plasma/5.2', scm.branch)
+    scm = UpstreamSCM.new(workspace, 'kubuntu_unstable', '/')
+    assert_equal('master', scm.branch)
+    scm = UpstreamSCM.new(qt, 'kubuntu_unstable', '/')
+    assert_equal('5.4', scm.branch)
+  end
+
   def test_override
-    scm = UpstreamSCM.new('trololo', data)
+    scm = UpstreamSCM.new('trololo', 'kubuntu_unstable', data)
     assert_equal('git2', scm.type)
     assert_equal('urlolo', scm.url)
     assert_equal('brunch', scm.branch)
@@ -20,7 +34,7 @@ class UpstreamSCMTest < TestCase
   def test_override_branch_only
     # Make sure defaults fall through correctly. If only branch is overridden
     # the rest should use the default values.
-    scm = UpstreamSCM.new('trololo', data)
+    scm = UpstreamSCM.new('trololo', 'kubuntu_unstable', data)
     assert_equal('git', scm.type)
     assert_equal('git://anongit.kde.org/trololo', scm.url)
     assert_equal('brunch', scm.branch)

-- 
ci-tooling packaging



More information about the pkg-kde-commits mailing list