diff --git a/build_tests/custom_builder/build.rb b/build_tests/custom_builder/build.rb index 20c9bfd..3b7bebc 100644 --- a/build_tests/custom_builder/build.rb +++ b/build_tests/custom_builder/build.rb @@ -1,5 +1,5 @@ class MySource < Rscons::Builder - def run(target, sources, cache) + def run(target, sources, cache, env) File.open(target, 'w') do |fh| fh.puts < target, 'SOURCES' => sources, 'DEPFILE' => target.set_suffix('.mf'), } - command = @env.build_command(@env['CCCOM'], vars) + command = env.build_command(env['CCCOM'], vars) unless cache.up_to_date?(target, command, sources) - return false unless @env.execute("CC #{target}", command) + return false unless env.execute("CC #{target}", command) deps = sources if File.exists?(vars['DEPFILE']) - deps += @env.parse_makefile_deps(vars['DEPFILE'], target) + deps += env.parse_makefile_deps(vars['DEPFILE'], target) FileUtils.rm_f(vars['DEPFILE']) end cache.register_build(target, command, deps.uniq) diff --git a/lib/rscons/builders/program.rb b/lib/rscons/builders/program.rb index c0d1437..ff1f084 100644 --- a/lib/rscons/builders/program.rb +++ b/lib/rscons/builders/program.rb @@ -12,27 +12,27 @@ module Rscons } end - def run(target, sources, cache) + def run(target, sources, cache, env) # convert sources to object file names sources = sources.map do |source| - if source.has_suffix?([@env['OBJSUFFIX'], @env['LIBSUFFIX']]) + if source.has_suffix?([env['OBJSUFFIX'], env['LIBSUFFIX']]) source else - o_file = @env.get_build_fname(source, @env['OBJSUFFIX', :string]) - builder = @env.builders.values.find { |b| b.produces?(o_file, source) } + o_file = env.get_build_fname(source, env['OBJSUFFIX', :string]) + builder = env.builders.values.find { |b| b.produces?(o_file, source, env) } builder or raise "No builder found to convert input source #{source.inspect} to an object file." - builder.run(o_file, [source], cache) or break + builder.run(o_file, [source], cache, env) or break end end if sources vars = { 'TARGET' => target, 'SOURCES' => sources, - 'LD' => @env['LD'] || @env['CC'], # TODO: figure out whether to use CC or CXX + 'LD' => env['LD'] || env['CC'], # TODO: figure out whether to use CC or CXX } - command = @env.build_command(@env['LDCOM'], vars) + command = env.build_command(env['LDCOM'], vars) unless cache.up_to_date?(target, command, sources) - return false unless @env.execute("LD #{target}", command) + return false unless env.execute("LD #{target}", command) cache.register_build(target, command, sources) end target diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 353ef49..1f1e3f2 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -21,7 +21,7 @@ module Rscons exclude_builders = Set.new(@varset[:exclude_builders] || []) DEFAULT_BUILDERS.each do |builder_class| unless exclude_builders.include?(builder_class.short_name) - add_builder(builder_class.new(self)) + add_builder(builder_class.new) end end end @@ -81,6 +81,7 @@ module Rscons @targets[target][:builder].run(target, @targets[target][:source], cache, + self, *@targets[target][:args]) else false