Module: Cxxproject::HasDependencies

Included in:
BuildingBlock
Defined in:
lib/cxxproject/buildingblocks/has_dependencies_mixin.rb

Instance Method Summary collapse

Instance Method Details

#add_unique(res, bb) ⇒ Object



71
72
73
74
# File 'lib/cxxproject/buildingblocks/has_dependencies_mixin.rb', line 71

def add_unique(res, bb)
  res.delete(bb)
  res.push(bb)
end

#all_dependenciesObject



82
83
84
85
86
87
88
89
90
91
# File 'lib/cxxproject/buildingblocks/has_dependencies_mixin.rb', line 82

def all_dependencies()
  return @all_dependencies if @all_deps_calculated

  direct_deps.each do |d|
    d.all_dependencies_recursive(@all_dependencies, @all_dependencies_set)
  end

  @all_deps_calculated = true
  @all_dependencies
end

#all_dependencies_recursive(all_deps, all_deps_set) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/cxxproject/buildingblocks/has_dependencies_mixin.rb', line 93

def all_dependencies_recursive(all_deps, all_deps_set)
  deps = [] # needed to keep order

  direct_deps.each do |d|
    next if all_deps_set.include?d
    all_deps << d
    all_deps_set << d
    deps << d
  end

  deps.each do |d|
    d.all_dependencies_recursive(all_deps, all_deps_set)
  end
end

#collect_dependenciesObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cxxproject/buildingblocks/has_dependencies_mixin.rb', line 59

def collect_dependencies()
  res = []
  res << self
  todo = dependencies
  while not todo.empty?
    bb = resolve_by_name(todo.pop)
    add_unique(res, bb)
    todo += bb.dependencies
  end
  res
end

#convert_named_values_to_string(values) ⇒ Object



12
13
14
# File 'lib/cxxproject/buildingblocks/has_dependencies_mixin.rb', line 12

def convert_named_values_to_string(values)
  values.map { |v| v.instance_of?(String) ? v : v.name }
end

#dependenciesObject



4
5
6
# File 'lib/cxxproject/buildingblocks/has_dependencies_mixin.rb', line 4

def dependencies
  @dependencies ||= []
end

#direct_depsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cxxproject/buildingblocks/has_dependencies_mixin.rb', line 25

def direct_deps
  return @direct_deps if @direct_deps

  @all_dependencies_set = Set.new
  @all_dependencies_set << self
  @all_dependencies = [self]

  depList = helper_dependencies.length > 0 ? helper_dependencies : dependencies

  depList.each do |d|
    bb = ALL_BUILDING_BLOCKS[d]
    if not bb
      raise "Error: while reading config file for #{self.name}: dependent building block \"#{d}\" was specified but not found!"
    end
    next if @all_dependencies_set.include?bb

    @all_dependencies << bb
    @all_dependencies_set << bb

    # deps in modules may be splitted into its contents
    if ModuleBuildingBlock === bb
      bb.contents.each do |c|
        next if @all_dependencies_set.include?c
        @all_dependencies << c
        @all_dependencies_set << c
      end
    end

  end

  @direct_deps = @all_dependencies.dup
  @direct_deps
end

#helper_dependenciesObject



8
9
10
# File 'lib/cxxproject/buildingblocks/has_dependencies_mixin.rb', line 8

def helper_dependencies
  @helper_dependencies ||= []
end

#resolve_by_name(name) ⇒ Object



76
77
78
79
80
# File 'lib/cxxproject/buildingblocks/has_dependencies_mixin.rb', line 76

def resolve_by_name(name)
  res = ALL_BUILDING_BLOCKS[name]
  raise "BuildingBlock #{name} not defined" unless res
  res
end

#set_dependencies(deps) ⇒ Object



15
16
17
18
# File 'lib/cxxproject/buildingblocks/has_dependencies_mixin.rb', line 15

def set_dependencies(deps)
  @dependencies = convert_named_values_to_string(deps)
  self
end

#set_helper_dependencies(deps) ⇒ Object



20
21
22
23
# File 'lib/cxxproject/buildingblocks/has_dependencies_mixin.rb', line 20

def set_helper_dependencies(deps)
  @helper_dependencies = convert_named_values_to_string(deps)
  self
end