pass extra construction variables to Builder#run()
This commit is contained in:
parent
75f2418570
commit
837dff9374
@ -1,5 +1,5 @@
|
|||||||
class MySource < Rscons::Builder
|
class MySource < Rscons::Builder
|
||||||
def run(target, sources, cache, env)
|
def run(target, sources, cache, env, vars = {})
|
||||||
File.open(target, 'w') do |fh|
|
File.open(target, 'w') do |fh|
|
||||||
fh.puts <<EOF
|
fh.puts <<EOF
|
||||||
#define THE_VALUE 5678
|
#define THE_VALUE 5678
|
||||||
|
@ -38,12 +38,12 @@ module Rscons
|
|||||||
source.has_suffix?(env['CXXSUFFIX']))
|
source.has_suffix?(env['CXXSUFFIX']))
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(target, sources, cache, env)
|
def run(target, sources, cache, env, vars = {})
|
||||||
vars = {
|
vars = vars.merge({
|
||||||
'TARGET' => target,
|
'TARGET' => target,
|
||||||
'SOURCES' => sources,
|
'SOURCES' => sources,
|
||||||
'DEPFILE' => target.set_suffix('.mf'),
|
'DEPFILE' => target.set_suffix('.mf'),
|
||||||
}
|
})
|
||||||
com_prefix = if sources.first.has_suffix?(env['ASSUFFIX'])
|
com_prefix = if sources.first.has_suffix?(env['ASSUFFIX'])
|
||||||
'AS'
|
'AS'
|
||||||
elsif sources.first.has_suffix?(env['CSUFFIX'])
|
elsif sources.first.has_suffix?(env['CSUFFIX'])
|
||||||
|
@ -14,19 +14,19 @@ module Rscons
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(target, sources, cache, env)
|
def run(target, sources, cache, env, vars = {})
|
||||||
# build sources to linkable objects
|
# 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
|
if objects
|
||||||
use_cxx = sources.map do |s|
|
use_cxx = sources.map do |s|
|
||||||
s.has_suffix?(env['CXXSUFFIX'])
|
s.has_suffix?(env['CXXSUFFIX'])
|
||||||
end.any?
|
end.any?
|
||||||
ld_alt = use_cxx ? env['CXX'] : env['CC']
|
ld_alt = use_cxx ? env['CXX'] : env['CC']
|
||||||
vars = {
|
vars = vars.merge({
|
||||||
'TARGET' => target,
|
'TARGET' => target,
|
||||||
'SOURCES' => objects,
|
'SOURCES' => objects,
|
||||||
'LD' => env['LD'] || ld_alt,
|
'LD' => env['LD'] || ld_alt,
|
||||||
}
|
})
|
||||||
command = env.build_command(env['LDCOM'], vars)
|
command = env.build_command(env['LDCOM'], vars)
|
||||||
unless cache.up_to_date?(target, command, objects)
|
unless cache.up_to_date?(target, command, objects)
|
||||||
return false unless env.execute("LD #{target}", command)
|
return false unless env.execute("LD #{target}", command)
|
||||||
|
@ -141,7 +141,7 @@ module Rscons
|
|||||||
@targets[target][:source],
|
@targets[target][:source],
|
||||||
cache,
|
cache,
|
||||||
self,
|
self,
|
||||||
*@targets[target][:args])
|
@targets[target][:vars] || {})
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
@ -193,11 +193,12 @@ module Rscons
|
|||||||
alias_method :orig_method_missing, :method_missing
|
alias_method :orig_method_missing, :method_missing
|
||||||
def method_missing(method, *args)
|
def method_missing(method, *args)
|
||||||
if @builders.has_key?(method.to_s)
|
if @builders.has_key?(method.to_s)
|
||||||
target, source, *rest = args
|
target, source, vars, *rest = args
|
||||||
source = [source] unless source.is_a?(Array)
|
source = [source] unless source.is_a?(Array)
|
||||||
@targets[target] = {
|
@targets[target] = {
|
||||||
builder: @builders[method.to_s],
|
builder: @builders[method.to_s],
|
||||||
source: source,
|
source: source,
|
||||||
|
vars: vars,
|
||||||
args: rest,
|
args: rest,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -236,7 +237,7 @@ module Rscons
|
|||||||
# @param suffixes [Array] List of suffixes to try to convert source files into.
|
# @param suffixes [Array] List of suffixes to try to convert source files into.
|
||||||
# @param cache [Cache] The Cache.
|
# @param cache [Cache] The Cache.
|
||||||
# Return a list of the converted file names.
|
# 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|
|
sources.map do |source|
|
||||||
if source.has_suffix?(suffixes)
|
if source.has_suffix?(suffixes)
|
||||||
source
|
source
|
||||||
@ -246,7 +247,7 @@ module Rscons
|
|||||||
converted_fname = get_build_fname(source, suffix)
|
converted_fname = get_build_fname(source, suffix)
|
||||||
builder = @builders.values.find { |b| b.produces?(converted_fname, source, self) }
|
builder = @builders.values.find { |b| b.produces?(converted_fname, source, self) }
|
||||||
if builder
|
if builder
|
||||||
converted = builder.run(converted_fname, [source], cache, self)
|
converted = builder.run(converted_fname, [source], cache, self, vars)
|
||||||
return nil unless converted
|
return nil unless converted
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
@ -8,8 +8,12 @@ module Rscons
|
|||||||
# Create a VarSet
|
# Create a VarSet
|
||||||
# @param vars [Hash] Optional initial variables.
|
# @param vars [Hash] Optional initial variables.
|
||||||
def initialize(vars = {})
|
def initialize(vars = {})
|
||||||
|
if vars.is_a?(VarSet)
|
||||||
|
@vars = vars.clone.vars
|
||||||
|
else
|
||||||
@vars = vars
|
@vars = vars
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Access the value of variable as a particular type
|
# Access the value of variable as a particular type
|
||||||
# @param key [String, Symbol] The variable name.
|
# @param key [String, Symbol] The variable name.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user