fix up builders to properly use variable overrides
This commit is contained in:
parent
9d61fa0276
commit
08f2248ed7
@ -32,7 +32,7 @@ module Rscons
|
|||||||
else
|
else
|
||||||
raise "Unknown source file #{sources.first.inspect} for CFile builder"
|
raise "Unknown source file #{sources.first.inspect} for CFile builder"
|
||||||
end
|
end
|
||||||
command = env.build_command(env["#{cmd}_CMD"], vars)
|
command = env.build_command("${#{cmd}_CMD}", vars)
|
||||||
standard_build("#{cmd} #{target}", target, command, sources, env, cache)
|
standard_build("#{cmd} #{target}", target, command, sources, env, cache)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ module Rscons
|
|||||||
|
|
||||||
def run(target, sources, cache, env, vars)
|
def run(target, sources, cache, env, vars)
|
||||||
vars = vars.merge("_SOURCES" => sources)
|
vars = vars.merge("_SOURCES" => sources)
|
||||||
command = env.build_command(env["DISASM_CMD"], vars)
|
command = env.build_command("${DISASM_CMD}", vars)
|
||||||
unless cache.up_to_date?(target, command, sources, env)
|
unless cache.up_to_date?(target, command, sources, env)
|
||||||
cache.mkdir_p(File.dirname(target))
|
cache.mkdir_p(File.dirname(target))
|
||||||
return false unless env.execute("Disassemble #{target}", command, options: {out: target})
|
return false unless env.execute("Disassemble #{target}", command, options: {out: target})
|
||||||
|
@ -13,13 +13,13 @@ module Rscons
|
|||||||
|
|
||||||
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.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars).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("${ARCMD}", vars)
|
||||||
standard_build("AR #{target}", target, command, objects, env, cache)
|
standard_build("AR #{target}", target, command, objects, env, cache)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -58,11 +58,11 @@ module Rscons
|
|||||||
'_DEPFILE' => Rscons.set_suffix(target, '.mf'),
|
'_DEPFILE' => Rscons.set_suffix(target, '.mf'),
|
||||||
})
|
})
|
||||||
com_prefix = KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
com_prefix = KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
||||||
sources.first.end_with?(*env[suffix_var])
|
sources.first.end_with?(*env.expand_varref("${#{suffix_var}}"))
|
||||||
end.tap do |v|
|
end.tap do |v|
|
||||||
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
|
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
|
||||||
end.first
|
end.first
|
||||||
command = env.build_command(env["#{com_prefix}CMD"], vars)
|
command = env.build_command("${#{com_prefix}CMD}", vars)
|
||||||
unless cache.up_to_date?(target, command, sources, env)
|
unless cache.up_to_date?(target, command, sources, env)
|
||||||
cache.mkdir_p(File.dirname(target))
|
cache.mkdir_p(File.dirname(target))
|
||||||
FileUtils.rm_f(target)
|
FileUtils.rm_f(target)
|
||||||
|
@ -9,15 +9,15 @@ module Rscons
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run(target, sources, cache, env, vars)
|
def run(target, sources, cache, env, vars)
|
||||||
pp_cc = if sources.find {|s| s.end_with?(*env["CXXSUFFIX"])}
|
pp_cc = if sources.find {|s| s.end_with?(*env.expand_varref("${CXXSUFFIX}", vars))}
|
||||||
env["CXX"]
|
"${CXX}"
|
||||||
else
|
else
|
||||||
env["CC"]
|
"${CC}"
|
||||||
end
|
end
|
||||||
vars = vars.merge("_PREPROCESS_CC" => pp_cc,
|
vars = vars.merge("_PREPROCESS_CC" => pp_cc,
|
||||||
"_TARGET" => target,
|
"_TARGET" => target,
|
||||||
"_SOURCES" => sources)
|
"_SOURCES" => sources)
|
||||||
command = env.build_command(env["CPP_CMD"], vars)
|
command = env.build_command("${CPP_CMD}", vars)
|
||||||
standard_build("Preprocess #{target}", target, command, sources, env, cache)
|
standard_build("Preprocess #{target}", target, command, sources, env, cache)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,23 +17,24 @@ module Rscons
|
|||||||
|
|
||||||
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.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars).flatten, cache, vars)
|
||||||
return false unless objects
|
return false unless objects
|
||||||
ld = if env["LD"]
|
ld = env.expand_varref("${LD}", vars)
|
||||||
env["LD"]
|
ld = if ld != ""
|
||||||
elsif sources.find {|s| s.end_with?(*env["DSUFFIX"])}
|
ld
|
||||||
env["DC"]
|
elsif sources.find {|s| s.end_with?(*env.expand_varref("${DSUFFIX}", vars))}
|
||||||
elsif sources.find {|s| s.end_with?(*env["CXXSUFFIX"])}
|
"${DC}"
|
||||||
env["CXX"]
|
elsif sources.find {|s| s.end_with?(*env.expand_varref("${CXXSUFFIX}", vars))}
|
||||||
|
"${CXX}"
|
||||||
else
|
else
|
||||||
env["CC"]
|
"${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("${LDCMD}", vars)
|
||||||
standard_build("LD #{target}", target, command, objects, env, cache)
|
standard_build("LD #{target}", target, command, objects, env, cache)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -83,7 +83,7 @@ module Rscons
|
|||||||
if varref =~ /^(.*)\$\{([^}]+)\}(.*)$/
|
if varref =~ /^(.*)\$\{([^}]+)\}(.*)$/
|
||||||
prefix, varname, suffix = $1, $2, $3
|
prefix, varname, suffix = $1, $2, $3
|
||||||
varval = expand_varref(self[varname])
|
varval = expand_varref(self[varname])
|
||||||
if varval.is_a?(String)
|
if varval.is_a?(String) or varval.nil?
|
||||||
expand_varref("#{prefix}#{varval}#{suffix}")
|
expand_varref("#{prefix}#{varval}#{suffix}")
|
||||||
elsif varval.is_a?(Array)
|
elsif varval.is_a?(Array)
|
||||||
varval.map {|vv| expand_varref("#{prefix}#{vv}#{suffix}")}.flatten
|
varval.map {|vv| expand_varref("#{prefix}#{vv}#{suffix}")}.flatten
|
||||||
|
@ -223,6 +223,7 @@ module Rscons
|
|||||||
env["path"] = ["dir1", "dir2"]
|
env["path"] = ["dir1", "dir2"]
|
||||||
env["flags"] = ["-x", "-y", "${specialflag}"]
|
env["flags"] = ["-x", "-y", "${specialflag}"]
|
||||||
env["specialflag"] = "-z"
|
env["specialflag"] = "-z"
|
||||||
|
env["foo"] = {}
|
||||||
env.expand_varref(["-p${path}", "${flags}"]).should == ["-pdir1", "-pdir2", "-x", "-y", "-z"]
|
env.expand_varref(["-p${path}", "${flags}"]).should == ["-pdir1", "-pdir2", "-x", "-y", "-z"]
|
||||||
env.expand_varref("foo").should == "foo"
|
env.expand_varref("foo").should == "foo"
|
||||||
expect {env.expand_varref("${foo}")}.to raise_error /expand.a.variable.reference/
|
expect {env.expand_varref("${foo}")}.to raise_error /expand.a.variable.reference/
|
||||||
|
@ -125,7 +125,8 @@ module Rscons
|
|||||||
"CC" => "gcc",
|
"CC" => "gcc",
|
||||||
"CPPPATH" => ["dir1", "dir2"],
|
"CPPPATH" => ["dir1", "dir2"],
|
||||||
"compiler" => "${CC}",
|
"compiler" => "${CC}",
|
||||||
"cmd" => ["${CC}", "-c", "${CFLAGS}", "-I${CPPPATH}"])
|
"cmd" => ["${CC}", "-c", "${CFLAGS}", "-I${CPPPATH}"],
|
||||||
|
"hash" => {})
|
||||||
it "expands to the string itself if the string is not a variable reference" do
|
it "expands to the string itself if the string is not a variable reference" do
|
||||||
v.expand_varref("CC").should == "CC"
|
v.expand_varref("CC").should == "CC"
|
||||||
v.expand_varref("CPPPATH").should == "CPPPATH"
|
v.expand_varref("CPPPATH").should == "CPPPATH"
|
||||||
@ -151,8 +152,11 @@ module Rscons
|
|||||||
"cflag: -O2, cpppath: dir2, compiler: gcc",
|
"cflag: -O2, cpppath: dir2, compiler: gcc",
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
it "raises an error when a variable reference refers to a non-existent variable" do
|
it "returns an empty string when a variable reference refers to a non-existent variable" do
|
||||||
expect { v.expand_varref("${not_here}") }.to raise_error /I do not know how to expand a variable reference to a NilClass/
|
expect(v.expand_varref("${not_here}")).to eq("")
|
||||||
|
end
|
||||||
|
it "raises an error when a variable reference refers to an unhandled type" do
|
||||||
|
expect { v.expand_varref("${hash}") }.to raise_error /I do not know how to expand a variable reference to a Hash/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user