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
# 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
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



56
57
58
# File 'lib/autoproj/ops/configuration.rb', line 56

def flatten
    @dag.topsort_iterator.to_a
end

#to_png(path) ⇒ Object

Write the hierarchy to an image (png) file



61
62
63
# File 'lib/autoproj/ops/configuration.rb', line 61

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

#verify_acyclicObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/autoproj/ops/configuration.rb', line 37

def verify_acyclic
    return if @dag.acyclic?

    Autoproj.fatal "The package sets form (a) cycle(s)"
    @dag.cycles.each_with_index do |cycle, index|
        Autoproj.fatal "== Cycle #{index}"
        (cycle + cycle[0, 1]).each_cons(2) do |a, b|
            if b.imports.include?(a)
                Autoproj.fatal "  #{b.name} depends on #{a.name} in its source.yml"
            else
                Autoproj.fatal "  #{b.name} is after #{a.name} in the package_sets section of the manifest"
            end
        end
    end

    raise ConfigError.new "cycles in package set dependencies"
end