Object: simplify handling of known suffixes

This commit is contained in:
Josh Holtrop 2013-11-05 15:25:10 -05:00
parent ed11b05b97
commit b1cdd3d1db

View File

@ -2,6 +2,13 @@ module Rscons
# A default RScons builder which knows how to produce an object file from # A default RScons builder which knows how to produce an object file from
# various types of source files. # various types of source files.
class Object < Builder class Object < Builder
KNOWN_SUFFIXES = {
"AS" => "ASSUFFIX",
"CC" => "CSUFFIX",
"CXX" => "CXXSUFFIX",
"DC" => "DSUFFIX",
}
def default_variables(env) def default_variables(env)
{ {
'OBJSUFFIX' => '.o', 'OBJSUFFIX' => '.o',
@ -38,11 +45,9 @@ module Rscons
end end
def produces?(target, source, env) def produces?(target, source, env)
target.has_suffix?(env['OBJSUFFIX']) and ( target.has_suffix?(env['OBJSUFFIX']) and KNOWN_SUFFIXES.find do |compiler, suffix_var|
source.has_suffix?(env['ASSUFFIX']) or source.has_suffix?(env[suffix_var])
source.has_suffix?(env['CSUFFIX']) or end
source.has_suffix?(env['CXXSUFFIX']) or
source.has_suffix?(env['DSUFFIX']))
end end
def run(target, sources, cache, env, vars = {}) def run(target, sources, cache, env, vars = {})
@ -51,17 +56,11 @@ module Rscons
'_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 = KNOWN_SUFFIXES.find do |compiler, suffix_var|
'AS' sources.first.has_suffix?(env[suffix_var])
elsif sources.first.has_suffix?(env['CSUFFIX']) end.tap do |v|
'CC' v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
elsif sources.first.has_suffix?(env['CXXSUFFIX']) end.first
'CXX'
elsif sources.first.has_suffix?(env['DSUFFIX'])
'DC'
else
raise "Error: unknown input file type: #{sources.first.inspect}"
end
command = env.build_command(env["#{com_prefix}COM"], vars) command = env.build_command(env["#{com_prefix}COM"], vars)
unless cache.up_to_date?(target, command, sources) unless cache.up_to_date?(target, command, sources)
cache.mkdir_p(File.dirname(target)) cache.mkdir_p(File.dirname(target))