move default builder classes into Rscons::Builders namespace module
This commit is contained in:
parent
cdb3352b4e
commit
5362f761e6
@ -14,9 +14,9 @@ require "rscons/builders/program"
|
|||||||
# Namespace module for rscons classes
|
# Namespace module for rscons classes
|
||||||
module Rscons
|
module Rscons
|
||||||
DEFAULT_BUILDERS = [
|
DEFAULT_BUILDERS = [
|
||||||
Library,
|
:Library,
|
||||||
Object,
|
:Object,
|
||||||
Program,
|
:Program,
|
||||||
]
|
]
|
||||||
|
|
||||||
class BuildError < RuntimeError; end
|
class BuildError < RuntimeError; end
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
require "fileutils"
|
require "fileutils"
|
||||||
|
|
||||||
module Rscons
|
module Rscons
|
||||||
|
# Namespace module in which to store builders for convenient grouping
|
||||||
|
module Builders; end
|
||||||
|
|
||||||
# Class to hold an object that knows how to build a certain type of file.
|
# Class to hold an object that knows how to build a certain type of file.
|
||||||
class Builder
|
class Builder
|
||||||
# Return the name of the builder.
|
# Return the name of the builder.
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
require 'fileutils'
|
|
||||||
|
|
||||||
module Rscons
|
module Rscons
|
||||||
# A default RScons builder that produces a static library archive.
|
module Builders
|
||||||
class Library < Builder
|
# A default RScons builder that produces a static library archive.
|
||||||
def default_variables(env)
|
class Rscons::Builders::Library < Rscons::Builder
|
||||||
{
|
def default_variables(env)
|
||||||
'AR' => 'ar',
|
{
|
||||||
'LIBSUFFIX' => '.a',
|
'AR' => 'ar',
|
||||||
'ARFLAGS' => [],
|
'LIBSUFFIX' => '.a',
|
||||||
'ARCMD' => ['${AR}', 'rcs', '${ARFLAGS}', '${_TARGET}', '${_SOURCES}']
|
'ARFLAGS' => [],
|
||||||
}
|
'ARCMD' => ['${AR}', 'rcs', '${ARFLAGS}', '${_TARGET}', '${_SOURCES}']
|
||||||
end
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def run(target, sources, cache, env, vars)
|
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, vars)
|
objects = env.build_sources(sources, [env['OBJSUFFIX'], env['LIBSUFFIX']].flatten, cache, vars)
|
||||||
if objects
|
if objects
|
||||||
vars = vars.merge({
|
vars = vars.merge({
|
||||||
'_TARGET' => target,
|
'_TARGET' => target,
|
||||||
'_SOURCES' => objects,
|
'_SOURCES' => objects,
|
||||||
})
|
})
|
||||||
command = env.build_command(env['ARCMD'], vars)
|
command = env.build_command(env['ARCMD'], vars)
|
||||||
standard_build("AR #{target}", target, command, objects, env, cache)
|
standard_build("AR #{target}", target, command, objects, env, cache)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,79 +1,81 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
# A default RScons builder which knows how to produce an object file from
|
module Builders
|
||||||
# various types of source files.
|
# A default RScons builder which knows how to produce an object file from
|
||||||
class Object < Builder
|
# various types of source files.
|
||||||
KNOWN_SUFFIXES = {
|
class Object < Builder
|
||||||
"AS" => "ASSUFFIX",
|
KNOWN_SUFFIXES = {
|
||||||
"CC" => "CSUFFIX",
|
"AS" => "ASSUFFIX",
|
||||||
"CXX" => "CXXSUFFIX",
|
"CC" => "CSUFFIX",
|
||||||
"DC" => "DSUFFIX",
|
"CXX" => "CXXSUFFIX",
|
||||||
}
|
"DC" => "DSUFFIX",
|
||||||
|
|
||||||
def default_variables(env)
|
|
||||||
{
|
|
||||||
'OBJSUFFIX' => '.o',
|
|
||||||
|
|
||||||
'AS' => '${CC}',
|
|
||||||
'ASFLAGS' => [],
|
|
||||||
'ASSUFFIX' => '.S',
|
|
||||||
'ASPPPATH' => '${CPPPATH}',
|
|
||||||
'ASPPFLAGS' => '${CPPFLAGS}',
|
|
||||||
'ASDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
|
|
||||||
'ASCMD' => ['${AS}', '-c', '-o', '${_TARGET}', '${ASDEPGEN}', '-I${ASPPPATH}', '${ASPPFLAGS}', '${ASFLAGS}', '${_SOURCES}'],
|
|
||||||
|
|
||||||
'CPPFLAGS' => [],
|
|
||||||
'CPPPATH' => [],
|
|
||||||
|
|
||||||
'CC' => 'gcc',
|
|
||||||
'CFLAGS' => [],
|
|
||||||
'CSUFFIX' => '.c',
|
|
||||||
'CCDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
|
|
||||||
'CCCMD' => ['${CC}', '-c', '-o', '${_TARGET}', '${CCDEPGEN}', '-I${CPPPATH}', '${CPPFLAGS}', '${CFLAGS}', '${_SOURCES}'],
|
|
||||||
|
|
||||||
'CXX' => 'g++',
|
|
||||||
'CXXFLAGS' => [],
|
|
||||||
'CXXSUFFIX' => '.cc',
|
|
||||||
'CXXDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
|
|
||||||
'CXXCMD' =>['${CXX}', '-c', '-o', '${_TARGET}', '${CXXDEPGEN}', '-I${CPPPATH}', '${CPPFLAGS}', '${CXXFLAGS}', '${_SOURCES}'],
|
|
||||||
|
|
||||||
'DC' => 'gdc',
|
|
||||||
'DFLAGS' => [],
|
|
||||||
'DSUFFIX' => '.d',
|
|
||||||
'D_IMPORT_PATH' => [],
|
|
||||||
'DCCMD' => ['${DC}', '-c', '-o', '${_TARGET}', '-I${D_IMPORT_PATH}', '${DFLAGS}', '${_SOURCES}'],
|
|
||||||
}
|
}
|
||||||
end
|
|
||||||
|
|
||||||
def produces?(target, source, env)
|
def default_variables(env)
|
||||||
target.has_suffix?(env['OBJSUFFIX']) and KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
{
|
||||||
source.has_suffix?(env[suffix_var])
|
'OBJSUFFIX' => '.o',
|
||||||
|
|
||||||
|
'AS' => '${CC}',
|
||||||
|
'ASFLAGS' => [],
|
||||||
|
'ASSUFFIX' => '.S',
|
||||||
|
'ASPPPATH' => '${CPPPATH}',
|
||||||
|
'ASPPFLAGS' => '${CPPFLAGS}',
|
||||||
|
'ASDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
|
||||||
|
'ASCMD' => ['${AS}', '-c', '-o', '${_TARGET}', '${ASDEPGEN}', '-I${ASPPPATH}', '${ASPPFLAGS}', '${ASFLAGS}', '${_SOURCES}'],
|
||||||
|
|
||||||
|
'CPPFLAGS' => [],
|
||||||
|
'CPPPATH' => [],
|
||||||
|
|
||||||
|
'CC' => 'gcc',
|
||||||
|
'CFLAGS' => [],
|
||||||
|
'CSUFFIX' => '.c',
|
||||||
|
'CCDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
|
||||||
|
'CCCMD' => ['${CC}', '-c', '-o', '${_TARGET}', '${CCDEPGEN}', '-I${CPPPATH}', '${CPPFLAGS}', '${CFLAGS}', '${_SOURCES}'],
|
||||||
|
|
||||||
|
'CXX' => 'g++',
|
||||||
|
'CXXFLAGS' => [],
|
||||||
|
'CXXSUFFIX' => '.cc',
|
||||||
|
'CXXDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
|
||||||
|
'CXXCMD' =>['${CXX}', '-c', '-o', '${_TARGET}', '${CXXDEPGEN}', '-I${CPPPATH}', '${CPPFLAGS}', '${CXXFLAGS}', '${_SOURCES}'],
|
||||||
|
|
||||||
|
'DC' => 'gdc',
|
||||||
|
'DFLAGS' => [],
|
||||||
|
'DSUFFIX' => '.d',
|
||||||
|
'D_IMPORT_PATH' => [],
|
||||||
|
'DCCMD' => ['${DC}', '-c', '-o', '${_TARGET}', '-I${D_IMPORT_PATH}', '${DFLAGS}', '${_SOURCES}'],
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def run(target, sources, cache, env, vars)
|
def produces?(target, source, env)
|
||||||
vars = vars.merge({
|
target.has_suffix?(env['OBJSUFFIX']) and KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
||||||
'_TARGET' => target,
|
source.has_suffix?(env[suffix_var])
|
||||||
'_SOURCES' => sources,
|
|
||||||
'_DEPFILE' => target.set_suffix('.mf'),
|
|
||||||
})
|
|
||||||
com_prefix = KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
|
||||||
sources.first.has_suffix?(env[suffix_var])
|
|
||||||
end.tap do |v|
|
|
||||||
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
|
|
||||||
end.first
|
|
||||||
command = env.build_command(env["#{com_prefix}CMD"], vars)
|
|
||||||
unless cache.up_to_date?(target, command, sources, env)
|
|
||||||
cache.mkdir_p(File.dirname(target))
|
|
||||||
FileUtils.rm_f(target)
|
|
||||||
return false unless env.execute("#{com_prefix} #{target}", command)
|
|
||||||
deps = sources
|
|
||||||
if File.exists?(vars['_DEPFILE'])
|
|
||||||
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], target)
|
|
||||||
FileUtils.rm_f(vars['_DEPFILE'])
|
|
||||||
end
|
end
|
||||||
cache.register_build(target, command, deps.uniq, env)
|
|
||||||
end
|
end
|
||||||
target
|
|
||||||
|
def run(target, sources, cache, env, vars)
|
||||||
|
vars = vars.merge({
|
||||||
|
'_TARGET' => target,
|
||||||
|
'_SOURCES' => sources,
|
||||||
|
'_DEPFILE' => target.set_suffix('.mf'),
|
||||||
|
})
|
||||||
|
com_prefix = KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
||||||
|
sources.first.has_suffix?(env[suffix_var])
|
||||||
|
end.tap do |v|
|
||||||
|
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
|
||||||
|
end.first
|
||||||
|
command = env.build_command(env["#{com_prefix}CMD"], vars)
|
||||||
|
unless cache.up_to_date?(target, command, sources, env)
|
||||||
|
cache.mkdir_p(File.dirname(target))
|
||||||
|
FileUtils.rm_f(target)
|
||||||
|
return false unless env.execute("#{com_prefix} #{target}", command)
|
||||||
|
deps = sources
|
||||||
|
if File.exists?(vars['_DEPFILE'])
|
||||||
|
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], target)
|
||||||
|
FileUtils.rm_f(vars['_DEPFILE'])
|
||||||
|
end
|
||||||
|
cache.register_build(target, command, deps.uniq, env)
|
||||||
|
end
|
||||||
|
target
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,39 +1,41 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
# A default RScons builder that knows how to link object files into an
|
module Builders
|
||||||
# executable program.
|
# A default RScons builder that knows how to link object files into an
|
||||||
class Program < Builder
|
# executable program.
|
||||||
def default_variables(env)
|
class Rscons::Builders::Program < Rscons::Builder
|
||||||
{
|
def default_variables(env)
|
||||||
'LD' => nil,
|
{
|
||||||
'OBJSUFFIX' => '.o',
|
'LD' => nil,
|
||||||
'LIBSUFFIX' => '.a',
|
'OBJSUFFIX' => '.o',
|
||||||
'LDFLAGS' => [],
|
'LIBSUFFIX' => '.a',
|
||||||
'LIBPATH' => [],
|
'LDFLAGS' => [],
|
||||||
'LIBS' => [],
|
'LIBPATH' => [],
|
||||||
'LDCMD' => ['${LD}', '-o', '${_TARGET}', '${LDFLAGS}', '${_SOURCES}', '-L${LIBPATH}', '-l${LIBS}']
|
'LIBS' => [],
|
||||||
}
|
'LDCMD' => ['${LD}', '-o', '${_TARGET}', '${LDFLAGS}', '${_SOURCES}', '-L${LIBPATH}', '-l${LIBS}']
|
||||||
end
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def run(target, sources, cache, env, vars)
|
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, vars)
|
objects = env.build_sources(sources, [env['OBJSUFFIX'], env['LIBSUFFIX']].flatten, cache, vars)
|
||||||
return false unless objects
|
return false unless objects
|
||||||
ld = if env["LD"]
|
ld = if env["LD"]
|
||||||
env["LD"]
|
env["LD"]
|
||||||
elsif sources.find {|s| s.has_suffix?(env["DSUFFIX"])}
|
elsif sources.find {|s| s.has_suffix?(env["DSUFFIX"])}
|
||||||
env["DC"]
|
env["DC"]
|
||||||
elsif sources.find {|s| s.has_suffix?(env["CXXSUFFIX"])}
|
elsif sources.find {|s| s.has_suffix?(env["CXXSUFFIX"])}
|
||||||
env["CXX"]
|
env["CXX"]
|
||||||
else
|
else
|
||||||
env["CC"]
|
env["CC"]
|
||||||
end
|
end
|
||||||
vars = vars.merge({
|
vars = vars.merge({
|
||||||
'_TARGET' => target,
|
'_TARGET' => target,
|
||||||
'_SOURCES' => objects,
|
'_SOURCES' => objects,
|
||||||
'LD' => ld,
|
'LD' => ld,
|
||||||
})
|
})
|
||||||
command = env.build_command(env['LDCMD'], vars)
|
command = env.build_command(env['LDCMD'], vars)
|
||||||
standard_build("LD #{target}", target, command, objects, env, cache)
|
standard_build("LD #{target}", target, command, objects, env, cache)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -34,7 +34,9 @@ module Rscons
|
|||||||
@build_dirs = []
|
@build_dirs = []
|
||||||
@build_hooks = []
|
@build_hooks = []
|
||||||
unless options[:exclude_builders]
|
unless options[:exclude_builders]
|
||||||
DEFAULT_BUILDERS.each do |builder_class|
|
DEFAULT_BUILDERS.each do |builder_class_name|
|
||||||
|
builder_class = Builders.const_get(builder_class_name)
|
||||||
|
builder_class or raise "Could not find builder class #{builder_class_name}"
|
||||||
add_builder(builder_class.new)
|
add_builder(builder_class.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -48,7 +48,7 @@ module Rscons
|
|||||||
it "adds the builder to the list of builders" do
|
it "adds the builder to the list of builders" do
|
||||||
env = Environment.new(exclude_builders: true)
|
env = Environment.new(exclude_builders: true)
|
||||||
env.builders.keys.should == []
|
env.builders.keys.should == []
|
||||||
env.add_builder(Rscons::Object.new)
|
env.add_builder(Rscons::Builders::Object.new)
|
||||||
env.builders.keys.should == ["Object"]
|
env.builders.keys.should == ["Object"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user