Class: Rscons::JobSet
- Inherits:
-
Object
- Object
- Rscons::JobSet
- Defined in:
- lib/rscons/job_set.rb
Overview
Class to keep track of a set of jobs that need to be performed.
Instance Method Summary collapse
-
#add_job(options) ⇒ Object
Add a job to the JobSet.
-
#clear! ⇒ Object
Remove all jobs from the JobSet.
-
#get_next_job_to_run(targets_still_building) ⇒ nil, Hash
Get the next job that is ready to run from the JobSet.
-
#initialize(build_dependencies, side_effects) ⇒ JobSet
constructor
Create a JobSet.
-
#size ⇒ Integer
Get the JobSet size.
Constructor Details
#initialize(build_dependencies, side_effects) ⇒ JobSet
Create a JobSet
16 17 18 19 20 |
# File 'lib/rscons/job_set.rb', line 16 def initialize(build_dependencies, side_effects) @jobs = {} @build_dependencies = build_dependencies @side_effects = side_effects end |
Instance Method Details
#add_job(options) ⇒ Object
Add a job to the JobSet.
34 35 36 37 38 39 40 41 |
# File 'lib/rscons/job_set.rb', line 34 def add_job() # We allow multiple jobs to be registered per target for cases like: # env.Directory("dest") # env.Install("dest", "bin") # env.Install("dest", "share") @jobs[[:target]] ||= [] @jobs[[:target]] << end |
#clear! ⇒ Object
Remove all jobs from the JobSet.
88 89 90 |
# File 'lib/rscons/job_set.rb', line 88 def clear! @jobs.clear end |
#get_next_job_to_run(targets_still_building) ⇒ nil, Hash
Get the next job that is ready to run from the JobSet.
This method will remove the job from the JobSet.
54 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 85 |
# File 'lib/rscons/job_set.rb', line 54 def get_next_job_to_run(targets_still_building) targets_not_built_yet = targets_still_building + @jobs.keys side_effects = targets_not_built_yet.map do |target| @side_effects[target] || [] end.flatten targets_not_built_yet += side_effects @jobs.keys.each do |target| skip = false (@jobs[target][0][:sources] + (@build_dependencies[target] || []).to_a).each do |src| if targets_not_built_yet.include?(src) skip = true break end end next if skip job = @jobs[target][0] if @jobs[target].size > 1 @jobs[target].slice!(0) else @jobs.delete(target) end return job end # If there is a job to run, and nothing is still building, but we did # not find a job to run above, then there might be a circular dependency # introduced by the user. if (@jobs.size > 0) and targets_still_building.empty? raise "Could not find a runnable job. Possible circular dependency for #{@jobs.keys.first}" end end |
#size ⇒ Integer
Get the JobSet size.
96 97 98 |
# File 'lib/rscons/job_set.rb', line 96 def size @jobs.size end |