pass extra construction variables to Builder#run()
This commit is contained in:
parent
75f2418570
commit
837dff9374
@ -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
|
||||
|
@ -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'])
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -8,8 +8,12 @@ module Rscons
|
||||
# Create a VarSet
|
||||
# @param vars [Hash] Optional initial variables.
|
||||
def initialize(vars = {})
|
||||
if vars.is_a?(VarSet)
|
||||
@vars = vars.clone.vars
|
||||
else
|
||||
@vars = vars
|
||||
end
|
||||
end
|
||||
|
||||
# Access the value of variable as a particular type
|
||||
# @param key [String, Symbol] The variable name.
|
||||
|
Loading…
x
Reference in New Issue
Block a user