# Author:: Nicolas Pouillard . # Copyright:: Copyright (c) 2004, 2005 TTK team. All rights reserved. # License:: LGPL # $Id: PackageCollection.rb 592 2005-05-23 01:43:16Z ertai $ module TTK module Strategies # This strategy takes a set of packages with their dependencies, it # computes the topological sort, and make all packages in the right order. # # * Dependencies are given as a Yaml file. # * Installation directories are propagated by with configure options. 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] = "<>/#{dep}" create(Import) do |t| t.name = dep t.import = "#{dep}.yml" t.symtbl[:configure_flags] = @deps[dep].map { |d| "--with-#{d}=<>/#{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 # class Hash