VarSet#expand_varref(): fix recursive expansion
This commit is contained in:
parent
66f53a23f6
commit
2e0c2688aa
@ -68,9 +68,9 @@ module Rscons
|
|||||||
prefix, varname, suffix = $1, $2, $3
|
prefix, varname, suffix = $1, $2, $3
|
||||||
varval = expand_varref(@vars[varname])
|
varval = expand_varref(@vars[varname])
|
||||||
if varval.is_a?(String)
|
if varval.is_a?(String)
|
||||||
"#{prefix}#{varval}#{suffix}"
|
expand_varref("#{prefix}#{varval}#{suffix}")
|
||||||
elsif varval.is_a?(Array)
|
elsif varval.is_a?(Array)
|
||||||
varval.map {|vv| "#{prefix}#{vv}#{suffix}"}
|
varval.map {|vv| expand_varref("#{prefix}#{vv}#{suffix}")}.flatten
|
||||||
else
|
else
|
||||||
raise "I do not know how to expand a variable reference to a #{varval.class.name}"
|
raise "I do not know how to expand a variable reference to a #{varval.class.name}"
|
||||||
end
|
end
|
||||||
|
@ -103,6 +103,14 @@ module Rscons
|
|||||||
v.expand_varref("${compiler}").should == "gcc"
|
v.expand_varref("${compiler}").should == "gcc"
|
||||||
v.expand_varref("${cmd}").should == ["gcc", "-c", "-Wall", "-O2", "-Idir1", "-Idir2"]
|
v.expand_varref("${cmd}").should == ["gcc", "-c", "-Wall", "-O2", "-Idir1", "-Idir2"]
|
||||||
end
|
end
|
||||||
|
it "resolves multiple variable references in one element by enumerating all combinations" do
|
||||||
|
v.expand_varref("cflag: ${CFLAGS}, cpppath: ${CPPPATH}, compiler: ${compiler}").should == [
|
||||||
|
"cflag: -Wall, cpppath: dir1, compiler: gcc",
|
||||||
|
"cflag: -O2, cpppath: dir1, compiler: gcc",
|
||||||
|
"cflag: -Wall, cpppath: dir2, compiler: gcc",
|
||||||
|
"cflag: -O2, cpppath: dir2, compiler: gcc",
|
||||||
|
]
|
||||||
|
end
|
||||||
it "raises an error when a variable reference refers to a non-existent variable" do
|
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/
|
expect { v.expand_varref("${not_here}") }.to raise_error /I do not know how to expand a variable reference to a NilClass/
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user