delay building targets that depend on builds registered with Environment#register_builds

This commit is contained in:
Josh Holtrop 2017-05-17 15:45:04 -04:00
parent 4ed584701a
commit e694199f33
2 changed files with 16 additions and 9 deletions

View File

@ -39,8 +39,9 @@ module Rscons
# when the block returns, the {#process} method is automatically called. # when the block returns, the {#process} method is automatically called.
def initialize(options = {}) def initialize(options = {})
@threaded_commands = Set.new @threaded_commands = Set.new
@registered_build_dependencies = {}
@varset = VarSet.new @varset = VarSet.new
@job_set = JobSet.new @job_set = JobSet.new(@registered_build_dependencies)
@user_deps = {} @user_deps = {}
@builders = {} @builders = {}
@build_dirs = [] @build_dirs = []
@ -328,7 +329,7 @@ module Rscons
# Process all completed {ThreadedCommand} objects. # Process all completed {ThreadedCommand} objects.
completed_tcs.each do |tc| completed_tcs.each do |tc|
result = builder.finalize( result = tc.build_operation[:builder].finalize(
command_status: tc.thread.value, command_status: tc.thread.value,
builder_info: tc.builder_info) builder_info: tc.builder_info)
if result if result
@ -517,6 +518,8 @@ module Rscons
# #
# @since 1.10.0 # @since 1.10.0
# #
# @param target [String]
# The target that depends on these builds.
# @param sources [Array<String>] # @param sources [Array<String>]
# List of source file(s) to build. # List of source file(s) to build.
# @param suffixes [Array<String>] # @param suffixes [Array<String>]
@ -526,7 +529,8 @@ module Rscons
# #
# @return [Array<String>] # @return [Array<String>]
# List of the output file name(s). # List of the output file name(s).
def register_builds(sources, suffixes, vars) def register_builds(target, sources, suffixes, vars)
@registered_build_dependencies[target] ||= Set.new
sources.map do |source| sources.map do |source|
if source.end_with?(*suffixes) if source.end_with?(*suffixes)
source source
@ -540,6 +544,7 @@ module Rscons
if builder if builder
output_fname = attempt_output_fname output_fname = attempt_output_fname
self.__send__(builder.name, output_fname, source, vars) self.__send__(builder.name, output_fname, source, vars)
@registered_build_dependencies[target] << output_fname
break break
end end
end end

View File

@ -5,8 +5,13 @@ module Rscons
class JobSet class JobSet
# Create a JobSet # Create a JobSet
def initialize #
# @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.
def initialize(build_dependencies)
@jobs = {} @jobs = {}
@build_dependencies = build_dependencies
end end
# Add a job to the JobSet. # Add a job to the JobSet.
@ -42,13 +47,10 @@ module Rscons
# @return [nil, Hash] # @return [nil, Hash]
# The next job to run. # The next job to run.
def get_next_job_to_run(targets_still_building) def get_next_job_to_run(targets_still_building)
attempted_targets = Set.new
@jobs.keys.each do |target| @jobs.keys.each do |target|
attempted_targets << target
skip = false skip = false
@jobs[target][0][:sources].each do |src| (@jobs[target][0][:sources] + (@build_dependencies[target] || []).to_a).each do |src|
if @jobs.include?(src) and not attempted_targets.include?(src) if @jobs.include?(src)
# Skip this target because it depends on another target later in # Skip this target because it depends on another target later in
# the job set. # the job set.
skip = true skip = true