From 1af3c5c9a4a8880f3f3ed7408b2e7e4b86757749 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 24 May 2017 15:13:59 -0400 Subject: [PATCH] pass Builder#run options into Builder#finalize also --- lib/rscons/builder.rb | 22 ++++++++++++++++------ lib/rscons/builders/object.rb | 9 +++++---- lib/rscons/environment.rb | 31 ++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/lib/rscons/builder.rb b/lib/rscons/builder.rb index 9bf8898..cee9016 100644 --- a/lib/rscons/builder.rb +++ b/lib/rscons/builder.rb @@ -145,19 +145,29 @@ module Rscons # Finalize a build operation. # - # This method is called after the {#run} method if the {#run} method does - # not return an error. + # This method is called after the {#run} method if the {#run} method + # returns a {ThreadedCommand} object. # # @param options [Hash] # Options. + # @option options [String] :target + # Target file name. + # @option options [Array] :sources + # Source file name(s). + # @option options [Cache] :cache + # The Cache object. + # @option options [Environment] :env + # The Environment executing the builder. + # @option options [Hash,VarSet] :vars + # Extra construction variables. + # @option options [Object] :setup_info + # Whatever value was returned from this builder's {#setup} method call. # @option options [true,false,nil] :command_status # If the {#run} method returns a {ThreadedCommand}, this field will # contain the return value from executing the command with # Kernel.system(). - # @option options [Object] :builder_info - # If the {#run} method returns a {ThreadedCommand}, this field will - # contain the value passed in to the :builder_info field of the - # {ThreadedCommand} object. + # @option options [ThreadedCommand] :tc + # The {ThreadedCommand} object that was returned by the #run method. # # @return [String,false] # Name of the target file on success or false on failure. diff --git a/lib/rscons/builders/object.rb b/lib/rscons/builders/object.rb index b9229b2..fe1671f 100644 --- a/lib/rscons/builders/object.rb +++ b/lib/rscons/builders/object.rb @@ -88,6 +88,8 @@ module Rscons '_SOURCES' => sources, '_DEPFILE' => Rscons.set_suffix(target, env.expand_varref("${DEPFILESUFFIX}", vars)), }) + # Store vars back into options so new keys are accessible in #finalize. + options[:vars] = vars com_prefix = KNOWN_SUFFIXES.find do |compiler, suffix_var| sources.first.end_with?(*env.expand_varref("${#{suffix_var}}")) end.tap do |v| @@ -101,8 +103,7 @@ module Rscons FileUtils.rm_f(target) ThreadedCommand.new( command, - short_description: "#{com_prefix} #{target}", - builder_info: options.merge(vars: vars, command: command)) + short_description: "#{com_prefix} #{target}") end end @@ -114,12 +115,12 @@ module Rscons # Name of the target file on success or nil on failure. def finalize(options) if options[:command_status] - target, deps, cache, env, vars, command = options[:builder_info].values_at(:target, :sources, :cache, :env, :vars, :command) + target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars) if File.exists?(vars['_DEPFILE']) deps += Environment.parse_makefile_deps(vars['_DEPFILE'], target) FileUtils.rm_f(vars['_DEPFILE']) end - cache.register_build(target, command, deps.uniq, env) + cache.register_build(target, options[:tc].command, deps.uniq, env) target end end diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 4a8335d..0246592 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -322,9 +322,7 @@ module Rscons # Process all completed {ThreadedCommand} objects. completed_tcs.each do |tc| - result = tc.build_operation[:builder].finalize( - command_status: tc.thread.value, - builder_info: tc.builder_info) + result = finalize_builder(tc) if result @build_hooks[:post].each do |build_hook_block| build_hook_block.call(tc.build_operation) @@ -594,18 +592,15 @@ module Rscons end if rv.is_a?(ThreadedCommand) + # Store the build operation so the post-build hooks can be called + # with it when the threaded command completes. + rv.build_operation = build_operation start_threaded_command(rv) - 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 + unless options[:allow_delayed_execution] # Delayed command execution is not allowed, so we need to execute # the command and finalize the builder now. tc = wait_for_threaded_commands(which: [rv]) - rv = builder.finalize( - command_status: tc.thread.value, - builder_info: tc.builder_info) + rv = finalize_builder(tc) if rv call_build_hooks[:post] else @@ -885,6 +880,20 @@ module Rscons command.map { |c| c =~ /\s/ ? "'#{c}'" : c }.join(' ') end + # Call a builder's #finalize method after a ThreadedCommand terminates. + # + # @param tc [ThreadedCommand] + # The ThreadedCommand returned from the builder's #run method. + # + # @return [String, false] + # Result of Builder#finalize. + def finalize_builder(tc) + tc.build_operation[:builder].finalize( + tc.build_operation.merge( + command_status: tc.thread.value, + tc: tc)) + end + # Parse dependencies for a given target from a Makefile. # # This method is used internally by Rscons builders.