diff --git a/build_tests/clone_env/clone_all.rb b/build_tests/clone_env/clone_all.rb index d8e064c..6da6e39 100644 --- a/build_tests/clone_env/clone_all.rb +++ b/build_tests/clone_env/clone_all.rb @@ -1,11 +1,11 @@ build do env1 = Environment.new(echo: :command) do |env| env['CFLAGS'] = '-O2' - env.add_build_hook do |build_op| - build_op[:vars]['CPPFLAGS'] = '-DSTRING="Hello"' + env.add_build_hook do |builder| + builder.vars['CPPFLAGS'] = '-DSTRING="Hello"' end - env.add_post_build_hook do |build_op| - $stdout.puts "post #{build_op[:target]}" + env.add_post_build_hook do |builder| + $stdout.puts "post #{builder.target}" end env.Program('program.exe', Dir['src/*.c']) end diff --git a/build_tests/simple/register_target_in_build_hook.rb b/build_tests/simple/register_target_in_build_hook.rb index 7ef07a7..6366a98 100644 --- a/build_tests/simple/register_target_in_build_hook.rb +++ b/build_tests/simple/register_target_in_build_hook.rb @@ -1,9 +1,9 @@ build do Environment.new do |env| env.Program("simple.exe", Dir["*.c"]) - env.add_build_hook do |build_op| - if build_op[:target].end_with?(".o") - env.Disassemble("#{build_op[:target]}.txt", build_op[:target]) + env.add_build_hook do |builder| + if builder.target.end_with?(".o") + env.Disassemble("#{builder.target}.txt", builder.target) end end end diff --git a/build_tests/typical/build_hooks.rb b/build_tests/typical/build_hooks.rb index f1a210f..4c96e24 100644 --- a/build_tests/typical/build_hooks.rb +++ b/build_tests/typical/build_hooks.rb @@ -1,11 +1,11 @@ build do Environment.new(echo: :command) do |env| env.append('CPPPATH' => Rscons.glob('src/**/*/')) - env.add_build_hook do |build_op| - if File.basename(build_op[:target]) == "one.o" - build_op[:vars]["CFLAGS"] << "-O1" - elsif File.basename(build_op[:target]) == "two.o" - build_op[:vars]["CFLAGS"] << "-O2" + env.add_build_hook do |builder| + if File.basename(builder.target) == "one.o" + builder.vars["CFLAGS"] << "-O1" + elsif File.basename(builder.target) == "two.o" + builder.vars["CFLAGS"] << "-O2" end end env.Program('build_hook.exe', Rscons.glob('src/**/*.c')) diff --git a/build_tests/typical/build_hooks_override_vars.rb b/build_tests/typical/build_hooks_override_vars.rb index 98e3f2d..023ccee 100644 --- a/build_tests/typical/build_hooks_override_vars.rb +++ b/build_tests/typical/build_hooks_override_vars.rb @@ -1,14 +1,14 @@ build do Environment.new(echo: :command) do |env| env.append('CPPPATH' => Rscons.glob('src/**')) - env.add_build_hook do |build_op| - if build_op[:builder].name == "Object" && build_op[:sources].first =~ %r{one\.c} - build_op[:vars]["CFLAGS"] << "-O1" - build_op[:sources] = ['src/two/two.c'] - elsif build_op[:builder].name == "Object" && build_op[:target] =~ %r{two\.o} - new_vars = build_op[:vars].clone + env.add_build_hook do |builder| + if builder.name == "Object" && builder.sources.first =~ %r{one\.c} + builder.vars["CFLAGS"] << "-O1" + builder.sources = ['src/two/two.c'] + elsif builder.name == "Object" && builder.target =~ %r{two\.o} + new_vars = builder.vars.clone new_vars["CFLAGS"] << "-O2" - build_op[:vars] = new_vars + builder.vars = new_vars end end env.Object('one.o', 'src/one/one.c') diff --git a/build_tests/typical/post_build_hook_expansion.rb b/build_tests/typical/post_build_hook_expansion.rb index 805816b..ffac3c1 100644 --- a/build_tests/typical/post_build_hook_expansion.rb +++ b/build_tests/typical/post_build_hook_expansion.rb @@ -2,8 +2,8 @@ build do Environment.new do |env| env["CPPPATH"] << "src/two" env.Object("one.o", "src/one/one.c") - env.add_post_build_hook do |build_op| - if build_op[:target] == "one.o" + env.add_post_build_hook do |builder| + if builder.target == "one.o" env["MODULE"] = "two" env.Object("${MODULE}.o", "src/${MODULE}/${MODULE}.c") end diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 2d04b9e..748821c 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -267,7 +267,7 @@ module Rscons job = nil else targets_still_building = @threaded_commands.map do |tc| - tc.build_operation[:target] + tc.builder.target end job = @job_set.get_next_job_to_run(targets_still_building) end @@ -280,8 +280,7 @@ module Rscons result = run_builder(job[:builder], job[:target], job[:sources], - cache, - job[:vars]) + cache) unless result failure = "Failed to build #{job[:target]}" Ansi.write($stderr, :red, failure, :reset, "\n") @@ -307,13 +306,13 @@ module Rscons result = finalize_builder(tc) if result @build_hooks[:post].each do |build_hook_block| - build_hook_block.call(tc.build_operation) + build_hook_block.call(tc.builder) end else unless @echo == :command print_failed_command(tc.command) end - failure = "Failed to build #{tc.build_operation[:target]}" + failure = "Failed to build #{tc.builder.target}" Ansi.write($stderr, :red, failure, :reset, "\n") break end @@ -515,39 +514,34 @@ module Rscons # @param target [String] The target output file. # @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] # @since 1.10.0 # Options. # # @return [String,false] Return value from the {Builder}'s +run+ method. - def run_builder(builder, target, sources, cache, vars, options = {}) - vars = @varset.merge(vars) + def run_builder(builder, target, sources, cache, options = {}) + builder.vars = @varset.merge(builder.vars) build_operation = { builder: builder, target: target, sources: sources, cache: cache, env: self, - vars: vars, + vars: builder.vars, } call_build_hooks = lambda do |sec| @build_hooks[sec].each do |build_hook_block| - build_hook_block.call(build_operation) + build_hook_block.call(builder) end end # Invoke pre-build hooks. call_build_hooks[:pre] - # TODO: remove build_operation fields and just pass in the Builder. - builder.sources = build_operation[:sources] - builder.vars = build_operation[:vars] - # Call the builder's #run method. rv = builder.run(build_operation) - (@side_effects[build_operation[:target]] || []).each do |side_effect_file| + (@side_effects[builder.target] || []).each do |side_effect_file| # Register side-effect files as build targets so that a Cache clean # operation will remove them. cache.register_build(side_effect_file, nil, [], self) @@ -556,6 +550,8 @@ module Rscons 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.builder = builder + # TODO: remove rv.build_operation = build_operation start_threaded_command(rv) else @@ -746,7 +742,7 @@ module Rscons # @return [String, false] # Result of Builder#finalize. def finalize_builder(tc) - tc.build_operation[:builder].finalize( + tc.builder.finalize( tc.build_operation.merge( command_status: tc.thread.value, tc: tc)) diff --git a/lib/rscons/threaded_command.rb b/lib/rscons/threaded_command.rb index 323212b..4e3cbbd 100644 --- a/lib/rscons/threaded_command.rb +++ b/lib/rscons/threaded_command.rb @@ -8,11 +8,6 @@ module Rscons # The command to execute. attr_reader :command - # @return [Object] - # Arbitrary object to store builder-specific info. This object value will - # be passed back into the builder's #finalize method. - attr_reader :builder_info - # @return [String] # Short description of the command. This will be printed to standard # output if the Environment's echo mode is :short. @@ -31,6 +26,10 @@ module Rscons # command is executing. attr_accessor :build_operation + # @return [Builder] + # {Builder} executing this command. + attr_accessor :builder + # @return [Thread] # The thread waiting on this command to terminate. attr_accessor :thread @@ -53,7 +52,6 @@ module Rscons # Options Hash to pass to Kernel#system. def initialize(command, options = {}) @command = command - @builder_info = options[:builder_info] @short_description = options[:short_description] @system_env = options[:system_env] @system_options = options[:system_options]