From e694199f335a8f4459b580452168a3e288826252 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 17 May 2017 15:45:04 -0400 Subject: [PATCH] delay building targets that depend on builds registered with Environment#register_builds --- lib/rscons/environment.rb | 11 ++++++++--- lib/rscons/job_set.rb | 14 ++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 90fde90..82c7a5d 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -39,8 +39,9 @@ module Rscons # when the block returns, the {#process} method is automatically called. def initialize(options = {}) @threaded_commands = Set.new + @registered_build_dependencies = {} @varset = VarSet.new - @job_set = JobSet.new + @job_set = JobSet.new(@registered_build_dependencies) @user_deps = {} @builders = {} @build_dirs = [] @@ -328,7 +329,7 @@ module Rscons # Process all completed {ThreadedCommand} objects. completed_tcs.each do |tc| - result = builder.finalize( + result = tc.build_operation[:builder].finalize( command_status: tc.thread.value, builder_info: tc.builder_info) if result @@ -517,6 +518,8 @@ module Rscons # # @since 1.10.0 # + # @param target [String] + # The target that depends on these builds. # @param sources [Array] # List of source file(s) to build. # @param suffixes [Array] @@ -526,7 +529,8 @@ module Rscons # # @return [Array] # 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| if source.end_with?(*suffixes) source @@ -540,6 +544,7 @@ module Rscons if builder output_fname = attempt_output_fname self.__send__(builder.name, output_fname, source, vars) + @registered_build_dependencies[target] << output_fname break end end diff --git a/lib/rscons/job_set.rb b/lib/rscons/job_set.rb index beab72a..19132de 100644 --- a/lib/rscons/job_set.rb +++ b/lib/rscons/job_set.rb @@ -5,8 +5,13 @@ module Rscons class 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 = {} + @build_dependencies = build_dependencies end # Add a job to the JobSet. @@ -42,13 +47,10 @@ module Rscons # @return [nil, Hash] # The next job to run. def get_next_job_to_run(targets_still_building) - attempted_targets = Set.new - @jobs.keys.each do |target| - attempted_targets << target skip = false - @jobs[target][0][:sources].each do |src| - if @jobs.include?(src) and not attempted_targets.include?(src) + (@jobs[target][0][:sources] + (@build_dependencies[target] || []).to_a).each do |src| + if @jobs.include?(src) # Skip this target because it depends on another target later in # the job set. skip = true