Class: Autoproj::Ops::PackageSetHierarchy

Inherits:
Object
  • Object
show all
Defined in:
lib/autoproj/ops/configuration.rb

Overview

PackageSetHierachy be used to build the hierarchy of package set imports, as directed acyclic graph (DAG) so that they can be (topologically) sorted according to their dependencies

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_sets, root_pkg_set) ⇒ PackageSetHierarchy

Returns a new instance of PackageSetHierarchy.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/autoproj/ops/configuration.rb', line 18

def initialize(package_sets, root_pkg_set)
    @dag = RGL::DirectedAdjacencyGraph.new

    package_sets.each do |p|
        p.imports.each do |dep|
            @dag.add_edge dep, p
        end
    end

    @dag.add_vertex root_pkg_set
    import_order = root_pkg_set.imports.to_a
    import_order.each_with_index do |p, index|
        if index + 1 < import_order.size
            @dag.add_edge p, import_order[index + 1]
            @dag.add_edge p, root_pkg_set
        end
    end

    unless @dag.acyclic?
        raise "The package set hierarchy contains cycles: #{@dag.cycles}"
    end
end

Instance Attribute Details

#dagObject (readonly)

Returns the value of attribute dag.



16
17
18
# File 'lib/autoproj/ops/configuration.rb', line 16

def dag
  @dag
end

Instance Method Details

#flattenObject

Flatten the hierarchy, a establish a sorting



42
43
44
# File 'lib/autoproj/ops/configuration.rb', line 42

def flatten
    @dag.topsort_iterator.to_a
end

#to_png(path) ⇒ Object

Write the hierarchy to an image (png) file



47
48
49
# File 'lib/autoproj/ops/configuration.rb', line 47

def to_png(path)
    @dag.write_to_graphic_file("png", path.gsub(".png", ""))
end