add Environment#wait_for_threaded_commands, use from #run_builder if delayed execution is not allowed

This commit is contained in:
Josh Holtrop 2017-05-17 09:34:19 -04:00
parent 800e7a51a4
commit 7534b29e26

View File

@ -1,6 +1,7 @@
require "fileutils" require "fileutils"
require "set" require "set"
require "shellwords" require "shellwords"
require "thwait"
module Rscons module Rscons
# The Environment class is the main programmatic interface to Rscons. It # The Environment class is the main programmatic interface to Rscons. It
@ -563,8 +564,10 @@ module Rscons
else else
# Delayed command execution is not allowed, so we need to execute # Delayed command execution is not allowed, so we need to execute
# the command and finalize the builder now. # the command and finalize the builder now.
# TODO tc = wait_for_threaded_commands(which: [rv])
#rv = builder.finalize() rv = builder.finalize(
command_status: tc.thread.value,
builder_info: tc.builder_info)
call_build_hooks[:post] if rv call_build_hooks[:post] if rv
end end
else else
@ -775,6 +778,29 @@ module Rscons
@threaded_commands << tc @threaded_commands << tc
end end
# Wait for threaded commands to complete.
#
# @param options [Hash]
# Options.
# @option options [Set<ThreadedCommand>, Array<ThreadedCommand>] :which
# Which {ThreadedCommand} objects to wait for. If not specified, this
# method will wait for any.
#
# @return [ThreadedCommand]
# The {ThreadedCommand} object that is finished.
def wait_for_threaded_commands(options = {})
raise "No threaded commands to wait for" if @threaded_commands.empty?
options[:which] ||= @threaded_commands
threads = options[:which].map(&:thread)
tw = ThreadsWait.new(*threads)
finished_thread = tw.next_wait
threaded_command = @threaded_commands.find do |tc|
tc.thread == finished_thread
end
@threaded_commands.delete(threaded_command)
threaded_command
end
# Return a string representation of a command. # Return a string representation of a command.
# #
# @param command [Array<String>] # @param command [Array<String>]