diff --git a/lib/rscons/varset.rb b/lib/rscons/varset.rb index 4144e69..f296412 100644 --- a/lib/rscons/varset.rb +++ b/lib/rscons/varset.rb @@ -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 diff --git a/spec/rscons/varset_spec.rb b/spec/rscons/varset_spec.rb index d117a92..e52b7d9 100644 --- a/spec/rscons/varset_spec.rb +++ b/spec/rscons/varset_spec.rb @@ -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