Sha256: fe20438697722978438068620648f20a349cceb5fe67debe40c815d8eab3eea1

Contents?: true

Size: 1.92 KB

Versions: 4

Compression:

Stored size: 1.92 KB

Contents

#!/usr/bin/env ruby

class QtRebuild
  attr_reader :pkgs_to_build_keys, :build_keys_to_pkgs

  def self.version
    IO.read(File.join(File.dirname(__FILE__), '../../VERSION')).strip
  end

  def initialize
    @pkgs_to_build_keys = {}
    @build_keys_to_pkgs = {}
  end

  # scan the installed packages looking for qt dependents that
  # have build keys.  These are the files than should be rebuilt
  # whenever qt's API changes.
  def scan
    qt_packages = `qlist -IC x11-libs/qt:4`.split("\n")

    dependents = []
    qt_packages.each do |pkg|
      dependents += `equery -q depends \"#{pkg}\"`.split("\n")
    end
    dependents = dependents.uniq.compact.sort

    dependents.each do |pkg|
      build_keys = []
      so_files = `qlist -Co #{pkg}`.split("\n").select{|file| file =~ /\.so(\..+|)$/}
      so_files.each do |file|
        if `strings #{file} | grep buildkey` =~ /^build\s*key[=:\s]\s*(\S.*)\s*$/i
          build_keys << $1
        end
      end
      build_keys = build_keys.compact.uniq
      unless build_keys.empty?
        @pkgs_to_build_keys[pkg] = build_keys
        build_keys.each do |key|
          @build_keys_to_pkgs[key] ||= []
          @build_keys_to_pkgs[key] << pkg
        end
      end
    end
  end

  def to_set
    buf = []
    @build_keys_to_pkgs.keys.sort.each do |key|
      pkgs = @build_keys_to_pkgs[key]
      pkgs.each do |pkg|
        buf << '=' + pkg
      end
    end
    buf.compact.uniq
  end

  def emerge(pretend, nocolor)
    buf = []
    buf << 'emerge'
    buf << '--oneshot'
    buf << '--pretend' if pretend
    buf << '--nocolor' if nocolor
    buf += to_set
    puts `#{buf.join(' ')}`
  end

  def to_s
    buf = []
    @build_keys_to_pkgs.keys.sort.each do |key|
      buf << "# Build key:  #{key}"
      pkgs = @build_keys_to_pkgs[key]
      pkgs.each do |pkg|
        buf << pkg
      end
    end
    buf.compact.uniq.sort.join("\n")
  end

  def build_keys
    @build_keys_to_pkgs.keys
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
royw-qt-rebuild-0.1.3 lib/qt-rebuild/qt-rebuild.rb
royw-qt-rebuild-0.1.5 lib/qt-rebuild/qt-rebuild.rb
royw-qt-rebuild-0.1.6 lib/qt-rebuild/qt-rebuild.rb
royw-qt-rebuild-0.1.7 lib/qt-rebuild/qt-rebuild.rb