From 9c13634eaf9fc491dbfd5673b3f34dac2b71a8b1 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 17 May 2017 08:47:17 -0400 Subject: [PATCH] start adding support for threaded commands in Environment#run_builder --- lib/rscons/environment.rb | 44 +++++++++++++++++++++++++++------- lib/rscons/threaded_command.rb | 5 ++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index e5a57a9..74f3c11 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -512,29 +512,39 @@ module Rscons # @param sources [Array] List of source files. # @param cache [Cache] The Cache. # @param vars [Hash] Extra variables to pass to the builder. + # @param options [Hash] Options. + # @option options [Boolean] :allow_delayed_execution + # @since 1.10.0 + # Allow a threaded command to be scheduled but not yet completed before + # this method returns. # # @return [String,false] Return value from the {Builder}'s +run+ method. - def run_builder(builder, target, sources, cache, vars) + def run_builder(builder, target, sources, cache, vars, options = {}) vars = @varset.merge(vars) + build_operation = { + builder: builder, + target: target, + sources: sources, + vars: vars, + env: self, + } call_build_hooks = lambda do |sec| @build_hooks[sec].each do |build_hook_block| - build_operation = { - builder: builder, - target: target, - sources: sources, - vars: vars, - env: self, - } build_hook_block.call(build_operation) end end + + # Invoke pre-build hooks. call_build_hooks[:pre] + use_new_run_method_signature = begin builder.method(:run).arity == 1 rescue NameError false end + + # Call the builder's #run method. if use_new_run_method_signature rv = builder.run( target: target, @@ -545,7 +555,23 @@ module Rscons else rv = builder.run(target, sources, cache, self, vars) end - call_build_hooks[:post] if rv + + if rv.is_a?(ThreadedCommand) + if options[:allow_delayed_execution] + # Store the build operation so the post-build hooks can be called + # with it when the threaded command completes. + rv.build_operation = build_operation + else + # Delayed command execution is not allowed, so we need to execute + # the command and finalize the builder now. + # TODO + #rv = builder.finalize() + call_build_hooks[:post] if rv + end + else + call_build_hooks[:post] if rv + end + rv end diff --git a/lib/rscons/threaded_command.rb b/lib/rscons/threaded_command.rb index e885d50..4ee4bff 100644 --- a/lib/rscons/threaded_command.rb +++ b/lib/rscons/threaded_command.rb @@ -13,6 +13,11 @@ module Rscons # be passed back into the builder's #finalize method. attr_reader :builder_info + # @return [Hash] + # Field for Rscons to store the build operation while this threaded + # command is executing. + attr_accessor :build_operation + # Create a ThreadedCommand object. # # @param command [Array]