VarSet#expand_varref(): fix recursive expansion

This commit is contained in:
Josh Holtrop 2013-11-05 17:06:09 -05:00
parent 66f53a23f6
commit 2e0c2688aa
2 changed files with 10 additions and 2 deletions

View File

@ -68,9 +68,9 @@ module Rscons
prefix, varname, suffix = $1, $2, $3
varval = expand_varref(@vars[varname])
if varval.is_a?(String)
"#{prefix}#{varval}#{suffix}"
expand_varref("#{prefix}#{varval}#{suffix}")
elsif varval.is_a?(Array)
varval.map {|vv| "#{prefix}#{vv}#{suffix}"}
varval.map {|vv| expand_varref("#{prefix}#{vv}#{suffix}")}.flatten
else
raise "I do not know how to expand a variable reference to a #{varval.class.name}"
end

View File

@ -103,6 +103,14 @@ module Rscons
v.expand_varref("${compiler}").should == "gcc"
v.expand_varref("${cmd}").should == ["gcc", "-c", "-Wall", "-O2", "-Idir1", "-Idir2"]
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
expect { v.expand_varref("${not_here}") }.to raise_error /I do not know how to expand a variable reference to a NilClass/
end