pass extra construction variables to Builder#run()

This commit is contained in:
Josh Holtrop 2013-09-12 22:57:22 -04:00
parent 75f2418570
commit 837dff9374
5 changed files with 18 additions and 13 deletions

View File

@ -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 <<EOF
#define THE_VALUE 5678

View File

@ -38,12 +38,12 @@ module Rscons
source.has_suffix?(env['CXXSUFFIX']))
end
def run(target, sources, cache, env)
vars = {
def run(target, sources, cache, env, vars = {})
vars = vars.merge({
'TARGET' => 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'])

View File

@ -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)

View File

@ -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

View File

@ -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