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