class Rscons::JobSet

Class to keep track of a set of jobs that need to be performed.

Public Class Methods

new(build_dependencies, side_effects) click to toggle source

Create a JobSet

@param build_dependencies [Hash]

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

@param side_effects [Hash]

Hash mapping targets to a set of side-effect files. A job 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.
# File lib/rscons/job_set.rb, line 16
def initialize(build_dependencies, side_effects)
  @jobs = {}
  @build_dependencies = build_dependencies
  @side_effects = side_effects
end

Public Instance Methods

add_job(options) click to toggle source

Add a job to the JobSet.

@param options [Hash]

Options.

@option options [Symbol, String] :target

Build target name.

@option options [Builder] :builder

The {Builder} to use to build the target.

@option options [Array<String>] :sources

Source file name(s).

@option options [Hash] :vars

Construction variable overrides.
# File lib/rscons/job_set.rb, line 34
def add_job(options)
  # We allow multiple jobs to be registered per target for cases like:
  #   env.Directory("dest")
  #   env.Install("dest", "bin")
  #   env.Install("dest", "share")
  @jobs[options[:target]] ||= []
  @jobs[options[:target]] << options
end
clear!() click to toggle source

Remove all jobs from the JobSet.

# File lib/rscons/job_set.rb, line 88
def clear!
  @jobs.clear
end
get_next_job_to_run(targets_still_building) click to toggle source

Get the next job that is ready to run from the JobSet.

This method will remove the job from the JobSet.

@param targets_still_building [Array<String>]

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

@return [nil, Hash]

The next job to run.
# 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() click to toggle source

Get the JobSet size.

@return [Integer]

JobSet size.
# File lib/rscons/job_set.rb, line 96
def size
  @jobs.size
end