Class: Rscons::JobSet

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(build_dependencies, side_effects) ⇒ JobSet

Create a JobSet

Parameters:

  • 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.

  • 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.


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.

Parameters:

  • options (Hash)

    Options.

Options Hash (options):

  • :target (Symbol, String)

    Build target name.

  • :builder (Builder)

    The Builder to use to build the target.

  • :sources (Array<String>)

    Source file name(s).

  • :vars (Hash)

    Construction variable overrides.


34
35
36
37
38
39
40
41
# 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!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.

Parameters:

  • 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.

Returns:

  • (nil, Hash)

    The next job to run.


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

#sizeInteger

Get the JobSet size.

Returns:

  • (Integer)

    JobSet size.


96
97
98
# File 'lib/rscons/job_set.rb', line 96

def size
  @jobs.size
end