Class: Rscons::BuilderSet
- Inherits:
-
Hash
- Object
- Hash
- Rscons::BuilderSet
- Defined in:
- lib/rscons/builder_set.rb
Overview
Class to keep track of a set of builders to be executed.
Instance Method Summary collapse
-
#<<(builder) ⇒ Object
Add a builder to the BuilderSet.
-
#build_steps_remaining ⇒ Integer
Return the number of remaining build steps.
-
#get_next_builder_to_run(targets_still_building) ⇒ nil, Builder
Get the next builder that is ready to run from the BuilderSet.
-
#initialize(build_dependencies, side_effects) ⇒ BuilderSet
constructor
Create a BuilderSet.
Constructor Details
#initialize(build_dependencies, side_effects) ⇒ BuilderSet
Create a BuilderSet.
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.
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_remaining ⇒ Integer
Return 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.
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 |