Sha256: 848c5db038ad7ebafc8c353595f44934ab047074caeaeda57a77cb71cd4b84c2

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

# Author::    Nicolas Pouillard  <ertai@lrde.epita.fr>.
# Copyright:: Copyright (c) 2004, 2005 TTK team. All rights reserved.
# License::   LGPL
# $Id: PackageCollection.rb 567 2005-04-13 08:00:06Z polrop $


module TTK

  module Strategies

    class PackageCollection < Composite
      include Concrete

      def prologue 
        super
        @dependencies = Pathname.new(@dependencies)
        @deps = YAML::load(@dependencies.read)
        @order = @deps.tsort_from(@target)
        @order.each do |dep|
          @symtbl["#{dep}_install_dir".to_sym] = "<<pwd>>/#{dep}"
          create(Import) do |t|
            t.name = dep
            t.import = "#{dep}.yml"
            t.symtbl[:configure_flags] =
              @deps[dep].map { |d| "--with-#{d}=<<pwd>>/#{d}" }.join(' ')
            t.fatal = true
          end
        end
      end
      protected :prologue

      attribute :dependencies, 'the dependency file', :mandatory
      attribute :target,       'the target package name'

    end # class PackageCollection

  end # module Strategies

end # module TTK



require 'tsort'

class Hash
  include TSort
  
  alias tsort_each_node each_key

  def tsort_each_child(node, &block)
    fetch(node).each(&block)
  end

  def tsort_each_from ( node=nil, &block )
    return tsort_each(&block) if node.nil?
    each_strongly_connected_component_from(node) do |component|
      if component.size == 1
        block[component.first]
      else
        raise Cyclic, "topological sort failed: #{component.inspect}"
      end
    end
  end

  def tsort_from ( node=nil )
    return tsort if node.nil?
    result = []
    tsort_each_from(node) { |n| result << n }
    result
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ttk-0.1.576 lib/ttk/strategies/PackageCollection.rb
ttk-0.1.580 lib/ttk/strategies/PackageCollection.rb
ttk-0.1.579 lib/ttk/strategies/PackageCollection.rb