Add Preprocess and Disassemble builders
This commit is contained in:
parent
ee5aca275d
commit
d424facf7f
@ -6,16 +6,20 @@ require_relative "rscons/version"
|
|||||||
|
|
||||||
# default builders
|
# default builders
|
||||||
require_relative "rscons/builders/cfile"
|
require_relative "rscons/builders/cfile"
|
||||||
|
require_relative "rscons/builders/disassemble"
|
||||||
require_relative "rscons/builders/library"
|
require_relative "rscons/builders/library"
|
||||||
require_relative "rscons/builders/object"
|
require_relative "rscons/builders/object"
|
||||||
|
require_relative "rscons/builders/preprocess"
|
||||||
require_relative "rscons/builders/program"
|
require_relative "rscons/builders/program"
|
||||||
|
|
||||||
# Namespace module for rscons classes
|
# Namespace module for rscons classes
|
||||||
module Rscons
|
module Rscons
|
||||||
DEFAULT_BUILDERS = [
|
DEFAULT_BUILDERS = [
|
||||||
:CFile,
|
:CFile,
|
||||||
|
:Disassemble,
|
||||||
:Library,
|
:Library,
|
||||||
:Object,
|
:Object,
|
||||||
|
:Preprocess,
|
||||||
:Program,
|
:Program,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
25
lib/rscons/builders/disassemble.rb
Normal file
25
lib/rscons/builders/disassemble.rb
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
module Rscons
|
||||||
|
module Builders
|
||||||
|
# The Disassemble builder produces a disassembly listing of a source file.
|
||||||
|
class Disassemble < Builder
|
||||||
|
def default_variables(env)
|
||||||
|
{
|
||||||
|
"OBJDUMP" => "objdump",
|
||||||
|
"DISASM_CMD" => ["${OBJDUMP}", "${DISASM_FLAGS}", "${_SOURCES}"],
|
||||||
|
"DISASM_FLAGS" => ["--disassemble", "--source"],
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(target, sources, cache, env, vars)
|
||||||
|
vars = vars.merge("_SOURCES" => sources)
|
||||||
|
command = env.build_command(env["DISASM_CMD"], vars)
|
||||||
|
unless cache.up_to_date?(target, command, sources, env)
|
||||||
|
cache.mkdir_p(File.dirname(target))
|
||||||
|
return false unless env.execute("Disassemble #{target}", command, options: {out: target})
|
||||||
|
cache.register_build(target, command, sources, env)
|
||||||
|
end
|
||||||
|
target
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,7 +1,7 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
module Builders
|
module Builders
|
||||||
# A default Rscons builder that produces a static library archive.
|
# A default Rscons builder that produces a static library archive.
|
||||||
class Rscons::Builders::Library < Rscons::Builder
|
class Library < Builder
|
||||||
def default_variables(env)
|
def default_variables(env)
|
||||||
{
|
{
|
||||||
'AR' => 'ar',
|
'AR' => 'ar',
|
||||||
|
25
lib/rscons/builders/preprocess.rb
Normal file
25
lib/rscons/builders/preprocess.rb
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
module Rscons
|
||||||
|
module Builders
|
||||||
|
# The Preprocess builder invokes the C preprocessor
|
||||||
|
class Preprocess < Builder
|
||||||
|
def default_variables(env)
|
||||||
|
{
|
||||||
|
"CPP_CMD" => ["${_PREPROCESS_CC}", "-E", "-o", "${_TARGET}", "-I${CPPPATH}", "${CPPFLAGS}", "${CFLAGS}", "${_SOURCES}"],
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(target, sources, cache, env, vars)
|
||||||
|
pp_cc = if sources.find {|s| s.end_with?(*env["CXXSUFFIX"])}
|
||||||
|
env["CXX"]
|
||||||
|
else
|
||||||
|
env["CC"]
|
||||||
|
end
|
||||||
|
vars = vars.merge("_PREPROCESS_CC" => pp_cc,
|
||||||
|
"_TARGET" => target,
|
||||||
|
"_SOURCES" => sources)
|
||||||
|
command = env.build_command(env["CPP_CMD"], vars)
|
||||||
|
standard_build("Preprocess #{target}", target, command, sources, env, cache)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -2,7 +2,7 @@ module Rscons
|
|||||||
module Builders
|
module Builders
|
||||||
# A default Rscons builder that knows how to link object files into an
|
# A default Rscons builder that knows how to link object files into an
|
||||||
# executable program.
|
# executable program.
|
||||||
class Rscons::Builders::Program < Rscons::Builder
|
class Program < Builder
|
||||||
def default_variables(env)
|
def default_variables(env)
|
||||||
{
|
{
|
||||||
'LD' => nil,
|
'LD' => nil,
|
||||||
|
@ -454,4 +454,34 @@ EOF
|
|||||||
`./hello-d`.rstrip.should == "Hello from D!"
|
`./hello-d`.rstrip.should == "Hello from D!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "supports disassembling object files" do
|
||||||
|
test_dir("simple")
|
||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env.Object("simple.o", "simple.c")
|
||||||
|
env.Disassemble("simple.txt", "simple.o")
|
||||||
|
end
|
||||||
|
File.exists?("simple.txt").should be_true
|
||||||
|
File.read("simple.txt").should =~ /Disassembly of section .text:/
|
||||||
|
end
|
||||||
|
|
||||||
|
it "supports preprocessing C sources" do
|
||||||
|
test_dir("simple")
|
||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env.Preprocess("simplepp.c", "simple.c")
|
||||||
|
env.Program("simple", "simplepp.c")
|
||||||
|
end
|
||||||
|
File.read("simplepp.c").should =~ /# \d+ "simple.c"/
|
||||||
|
`./simple`.should == "This is a simple C program\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "supports preprocessing C++ sources" do
|
||||||
|
test_dir("simple_cc")
|
||||||
|
Rscons::Environment.new do |env|
|
||||||
|
env.Preprocess("simplepp.cc", "simple.cc")
|
||||||
|
env.Program("simple", "simplepp.cc")
|
||||||
|
end
|
||||||
|
File.read("simplepp.cc").should =~ /# \d+ "simple.cc"/
|
||||||
|
`./simple`.should == "This is a simple C++ program\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user