From 837dff93749f1f9906397222756015ac74fc7b9b Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 12 Sep 2013 22:57:22 -0400 Subject: [PATCH] pass extra construction variables to Builder#run() --- build_tests/custom_builder/build.rb | 2 +- lib/rscons/builders/object.rb | 6 +++--- lib/rscons/builders/program.rb | 8 ++++---- lib/rscons/environment.rb | 9 +++++---- lib/rscons/varset.rb | 6 +++++- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/build_tests/custom_builder/build.rb b/build_tests/custom_builder/build.rb index 3b7bebc..2734914 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, env) + def run(target, sources, cache, env, vars = {}) File.open(target, 'w') do |fh| fh.puts < target, 'SOURCES' => sources, 'DEPFILE' => target.set_suffix('.mf'), - } + }) com_prefix = if sources.first.has_suffix?(env['ASSUFFIX']) 'AS' elsif sources.first.has_suffix?(env['CSUFFIX']) diff --git a/lib/rscons/builders/program.rb b/lib/rscons/builders/program.rb index d7eec0f..64ef954 100644 --- a/lib/rscons/builders/program.rb +++ b/lib/rscons/builders/program.rb @@ -14,19 +14,19 @@ module Rscons } end - def run(target, sources, cache, env) + def run(target, sources, cache, env, vars = {}) # build sources to linkable objects - objects = env.build_sources(sources, [env['OBJSUFFIX'], env['LIBSUFFIX']].flatten, cache) + objects = env.build_sources(sources, [env['OBJSUFFIX'], env['LIBSUFFIX']].flatten, cache, vars) if objects use_cxx = sources.map do |s| s.has_suffix?(env['CXXSUFFIX']) end.any? ld_alt = use_cxx ? env['CXX'] : env['CC'] - vars = { + vars = vars.merge({ 'TARGET' => target, 'SOURCES' => objects, 'LD' => env['LD'] || ld_alt, - } + }) command = env.build_command(env['LDCOM'], vars) unless cache.up_to_date?(target, command, objects) return false unless env.execute("LD #{target}", command) diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 53c4d2c..782909b 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -141,7 +141,7 @@ module Rscons @targets[target][:source], cache, self, - *@targets[target][:args]) + @targets[target][:vars] || {}) else false end @@ -193,11 +193,12 @@ module Rscons alias_method :orig_method_missing, :method_missing def method_missing(method, *args) if @builders.has_key?(method.to_s) - target, source, *rest = args + target, source, vars, *rest = args source = [source] unless source.is_a?(Array) @targets[target] = { builder: @builders[method.to_s], source: source, + vars: vars, args: rest, } else @@ -236,7 +237,7 @@ module Rscons # @param suffixes [Array] List of suffixes to try to convert source files into. # @param cache [Cache] The Cache. # Return a list of the converted file names. - def build_sources(sources, suffixes, cache) + def build_sources(sources, suffixes, cache, vars = {}) sources.map do |source| if source.has_suffix?(suffixes) source @@ -246,7 +247,7 @@ module Rscons converted_fname = get_build_fname(source, suffix) builder = @builders.values.find { |b| b.produces?(converted_fname, source, self) } if builder - converted = builder.run(converted_fname, [source], cache, self) + converted = builder.run(converted_fname, [source], cache, self, vars) return nil unless converted break end diff --git a/lib/rscons/varset.rb b/lib/rscons/varset.rb index a97f9d2..e8e7755 100644 --- a/lib/rscons/varset.rb +++ b/lib/rscons/varset.rb @@ -8,7 +8,11 @@ module Rscons # Create a VarSet # @param vars [Hash] Optional initial variables. def initialize(vars = {}) - @vars = vars + if vars.is_a?(VarSet) + @vars = vars.clone.vars + else + @vars = vars + end end # Access the value of variable as a particular type