refactor some Program functionality into Environment#build_sources()
This commit is contained in:
parent
711e96cec8
commit
75f2418570
@ -15,17 +15,8 @@ module Rscons
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run(target, sources, cache, env)
|
def run(target, sources, cache, env)
|
||||||
# convert sources to object file names
|
# build sources to linkable objects
|
||||||
objects = sources.map do |source|
|
objects = env.build_sources(sources, [env['OBJSUFFIX'], env['LIBSUFFIX']].flatten, cache)
|
||||||
if source.has_suffix?([env['OBJSUFFIX'], env['LIBSUFFIX']])
|
|
||||||
source
|
|
||||||
else
|
|
||||||
o_file = env.get_build_fname(source, env['OBJSUFFIX', :string])
|
|
||||||
builder = env.builders.values.find { |b| b.produces?(o_file, source, env) }
|
|
||||||
builder or raise "No builder found to convert input source #{source.inspect} to an object file."
|
|
||||||
builder.run(o_file, [source], cache, env) or break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
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'])
|
||||||
|
@ -228,5 +228,32 @@ module Rscons
|
|||||||
end
|
end
|
||||||
deps
|
deps
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Build a list of source files into files containing one of the suffixes
|
||||||
|
# given by suffixes.
|
||||||
|
# This method is used internally by RScons builders.
|
||||||
|
# @param sources [Array] List of source files to build.
|
||||||
|
# @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)
|
||||||
|
sources.map do |source|
|
||||||
|
if source.has_suffix?(suffixes)
|
||||||
|
source
|
||||||
|
else
|
||||||
|
converted = nil
|
||||||
|
suffixes.each do |suffix|
|
||||||
|
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)
|
||||||
|
return nil unless converted
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
converted or raise "Could not find a builder to handle #{source.inspect}."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user