change construction variable reference format to ${var}

this change is backwards-incompatible
This commit is contained in:
Josh Holtrop 2013-11-05 16:53:55 -05:00
parent 545b893ef4
commit 66f53a23f6
6 changed files with 30 additions and 37 deletions

View File

@ -8,7 +8,7 @@ module Rscons
'AR' => 'ar', 'AR' => 'ar',
'LIBSUFFIX' => '.a', 'LIBSUFFIX' => '.a',
'ARFLAGS' => [], 'ARFLAGS' => [],
'ARCOM' => ['$AR', 'rcs', '$ARFLAGS', '$_TARGET', '$_SOURCES'] 'ARCOM' => ['${AR}', 'rcs', '${ARFLAGS}', '${_TARGET}', '${_SOURCES}']
} }
end end

View File

@ -13,13 +13,13 @@ module Rscons
{ {
'OBJSUFFIX' => '.o', 'OBJSUFFIX' => '.o',
'AS' => '$CC', 'AS' => '${CC}',
'ASFLAGS' => [], 'ASFLAGS' => [],
'ASSUFFIX' => '.S', 'ASSUFFIX' => '.S',
'ASPPPATH' => '$CPPPATH', 'ASPPPATH' => '${CPPPATH}',
'ASPPFLAGS' => '$CPPFLAGS', 'ASPPFLAGS' => '${CPPFLAGS}',
'ASDEPGEN' => ['-MMD', '-MF', '$_DEPFILE'], 'ASDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
'ASCOM' => ['$AS', '-c', '-o', '$_TARGET', '$ASDEPGEN', '-I$[ASPPPATH]', '$ASPPFLAGS', '$ASFLAGS', '$_SOURCES'], 'ASCOM' => ['${AS}', '-c', '-o', '${_TARGET}', '${ASDEPGEN}', '-I${ASPPPATH}', '${ASPPFLAGS}', '${ASFLAGS}', '${_SOURCES}'],
'CPPFLAGS' => [], 'CPPFLAGS' => [],
'CPPPATH' => [], 'CPPPATH' => [],
@ -27,20 +27,20 @@ module Rscons
'CC' => 'gcc', 'CC' => 'gcc',
'CFLAGS' => [], 'CFLAGS' => [],
'CSUFFIX' => '.c', 'CSUFFIX' => '.c',
'CCDEPGEN' => ['-MMD', '-MF', '$_DEPFILE'], 'CCDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
'CCCOM' => ['$CC', '-c', '-o', '$_TARGET', '$CCDEPGEN', '-I$[CPPPATH]', '$CPPFLAGS', '$CFLAGS', '$_SOURCES'], 'CCCOM' => ['${CC}', '-c', '-o', '${_TARGET}', '${CCDEPGEN}', '-I${CPPPATH}', '${CPPFLAGS}', '${CFLAGS}', '${_SOURCES}'],
'CXX' => 'g++', 'CXX' => 'g++',
'CXXFLAGS' => [], 'CXXFLAGS' => [],
'CXXSUFFIX' => '.cc', 'CXXSUFFIX' => '.cc',
'CXXDEPGEN' => ['-MMD', '-MF', '$_DEPFILE'], 'CXXDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
'CXXCOM' =>['$CXX', '-c', '-o', '$_TARGET', '$CXXDEPGEN', '-I$[CPPPATH]', '$CPPFLAGS', '$CXXFLAGS', '$_SOURCES'], 'CXXCOM' =>['${CXX}', '-c', '-o', '${_TARGET}', '${CXXDEPGEN}', '-I${CPPPATH}', '${CPPFLAGS}', '${CXXFLAGS}', '${_SOURCES}'],
'DC' => 'gdc', 'DC' => 'gdc',
'DFLAGS' => [], 'DFLAGS' => [],
'DSUFFIX' => '.d', 'DSUFFIX' => '.d',
'D_IMPORT_PATH' => [], 'D_IMPORT_PATH' => [],
'DCCOM' => ['$DC', '-c', '-o', '$_TARGET', '-I$[D_IMPORT_PATH]', '$DFLAGS', '$_SOURCES'], 'DCCOM' => ['${DC}', '-c', '-o', '${_TARGET}', '-I${D_IMPORT_PATH}', '${DFLAGS}', '${_SOURCES}'],
} }
end end

View File

@ -10,7 +10,7 @@ module Rscons
'LDFLAGS' => [], 'LDFLAGS' => [],
'LIBPATH' => [], 'LIBPATH' => [],
'LIBS' => [], 'LIBS' => [],
'LDCOM' => ['$LD', '-o', '$_TARGET', '$LDFLAGS', '$_SOURCES', '-L$[LIBPATH]', '-l$[LIBS]'] 'LDCOM' => ['${LD}', '-o', '${_TARGET}', '${LDFLAGS}', '${_SOURCES}', '-L${LIBPATH}', '-l${LIBS}']
} }
end end

View File

@ -64,20 +64,16 @@ module Rscons
expand_varref(ent) expand_varref(ent)
end.flatten end.flatten
else else
if varref =~ /^(.*)\$\[(\w+)\](.*)$/ if varref =~ /^(.*)\$\{([^}]+)\}(.*)$/
# expand array with given prefix, suffix
prefix, varname, suffix = $1, $2, $3 prefix, varname, suffix = $1, $2, $3
varval = expand_varref(@vars[varname]) varval = expand_varref(@vars[varname])
unless varval.is_a?(Array) if varval.is_a?(String)
raise "Array expected for $#{varname}" "#{prefix}#{varval}#{suffix}"
elsif varval.is_a?(Array)
varval.map {|vv| "#{prefix}#{vv}#{suffix}"}
else
raise "I do not know how to expand a variable reference to a #{varval.class.name}"
end end
varval.map {|e| "#{prefix}#{e}#{suffix}"}
elsif varref =~ /^\$(.*)$/
# expand a single variable reference
varname = $1
varval = expand_varref(@vars[varname])
varval or raise "Could not find variable #{varname.inspect}"
expand_varref(varval)
else else
varref varref
end end

View File

@ -162,9 +162,9 @@ module Rscons
it "returns a command based on the variables in the Environment" do it "returns a command based on the variables in the Environment" do
env = Environment.new env = Environment.new
env["path"] = ["dir1", "dir2"] env["path"] = ["dir1", "dir2"]
env["flags"] = ["-x", "-y", "$specialflag"] env["flags"] = ["-x", "-y", "${specialflag}"]
env["specialflag"] = "-z" env["specialflag"] = "-z"
template = ["cmd", "-I$[path]", "$flags", "$_source", "$_dest"] template = ["cmd", "-I${path}", "${flags}", "${_source}", "${_dest}"]
cmd = env.build_command(template, "_source" => "infile", "_dest" => "outfile") cmd = env.build_command(template, "_source" => "infile", "_dest" => "outfile")
cmd.should == ["cmd", "-Idir1", "-Idir2", "-x", "-y", "-z", "infile", "outfile"] cmd.should == ["cmd", "-Idir1", "-Idir2", "-x", "-y", "-z", "infile", "outfile"]
end end

View File

@ -84,30 +84,27 @@ module Rscons
v = VarSet.new("CFLAGS" => ["-Wall", "-O2"], v = VarSet.new("CFLAGS" => ["-Wall", "-O2"],
"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}"])
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"
v.expand_varref("str").should == "str" v.expand_varref("str").should == "str"
end end
it "expands a single variable reference beginning with a '$'" do it "expands a single variable reference beginning with a '$'" do
v.expand_varref("$CC").should == "gcc" v.expand_varref("${CC}").should == "gcc"
v.expand_varref("$CPPPATH").should == ["dir1", "dir2"] v.expand_varref("${CPPPATH}").should == ["dir1", "dir2"]
end end
it "expands a single variable reference in $[arr] notation" do it "expands a single variable reference in ${arr} notation" do
v.expand_varref("prefix$[CFLAGS]suffix").should == ["prefix-Wallsuffix", "prefix-O2suffix"] v.expand_varref("prefix${CFLAGS}suffix").should == ["prefix-Wallsuffix", "prefix-O2suffix"]
v.expand_varref(v["cmd"]).should == ["gcc", "-c", "-Wall", "-O2", "-Idir1", "-Idir2"] v.expand_varref(v["cmd"]).should == ["gcc", "-c", "-Wall", "-O2", "-Idir1", "-Idir2"]
end end
it "expands a variable reference recursively" do it "expands a variable reference recursively" do
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
it "raises an error when array notation is applied to a non-array variable" do
expect { v.expand_varref("$[CC]") }.to raise_error /Array.expected/
end 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 /Could.not.find.variable..not_here/ expect { v.expand_varref("${not_here}") }.to raise_error /I do not know how to expand a variable reference to a NilClass/
end end
end end
end end