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