Class: Rscons::BuilderSet

Inherits:
Hash
  • Object
show all
Defined in:
lib/rscons/builder_set.rb

Overview

Class to keep track of a set of builders to be executed.

Instance Method Summary collapse

Constructor Details

#initialize(build_dependencies, side_effects) ⇒ BuilderSet

Create a BuilderSet.

Parameters:

  • build_dependencies (Hash)

    Hash mapping targets to a set of build dependencies. A builder will not be returned as ready to run if any of its dependencies are still building.

  • side_effects (Set)

    Set of side-effect files. A builder will not be returned as ready to run if any of its dependencies is a side-effect of another target that has not yet been built.



15
16
17
18
19
# File 'lib/rscons/builder_set.rb', line 15

def initialize(build_dependencies, side_effects)
  super()
  @build_dependencies = build_dependencies
  @side_effects = side_effects
end

Instance Method Details

#<<(builder) ⇒ Object

Add a builder to the BuilderSet.

Parameters:



25
26
27
28
29
30
31
32
# File 'lib/rscons/builder_set.rb', line 25

def <<(builder)
  # We allow multiple builders to be registered per target for cases like:
  #   env.Directory("dest")
  #   env.Install("dest", "bin")
  #   env.Install("dest", "share")
  self[builder.target] ||= []
  self[builder.target] << builder
end

#build_steps_remainingInteger

Return the number of remaining build steps.

Returns:

  • (Integer)

    The number of remaining build steps.



38
39
40
41
42
# File 'lib/rscons/builder_set.rb', line 38

def build_steps_remaining
  self.reduce(0) do |result, (target, builders)|
    result + builders.select {|b| not b.nop?}.size
  end
end

#get_next_builder_to_run(targets_still_building) ⇒ nil, Builder

Get the next builder that is ready to run from the BuilderSet.

This method will remove the builder from the BuilderSet.

Parameters:

  • targets_still_building (Array<String>)

    Targets that are not finished building. This is used to avoid returning a builder as available to run if it depends on one of the targets that are still building as a source.

Returns:

  • (nil, Builder)

    The next builder to run.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rscons/builder_set.rb', line 55

def get_next_builder_to_run(targets_still_building)
  to_build = self.find do |target, builders|
    deps = builders.first.sources + (@build_dependencies[target] || []).to_a
    # All dependencies must have been built for this target to be ready to
    # build.
    deps.all? do |dep|
      !(targets_still_building.include?(dep) ||
        self.include?(dep) ||
        @side_effects.include?(dep))
    end
  end

  if to_build
    target, builders = *to_build
    builder = builders.first
    if builders.size > 1
      builders.slice!(0)
    else
      self.delete(target)
    end
    return builder
  end

  # If there is a builder to run, and nothing is still building, but we did
  # not find a builder to run above, then there might be a circular
  # dependency introduced by the user.
  if (self.size > 0) and targets_still_building.empty?
    raise "Could not find a runnable builder. Possible circular dependency for #{self.keys.first}"
  end
end