change construction variable reference format to ${var}
this change is backwards-incompatible
This commit is contained in:
parent
545b893ef4
commit
66f53a23f6
@ -8,7 +8,7 @@ module Rscons
|
||||
'AR' => 'ar',
|
||||
'LIBSUFFIX' => '.a',
|
||||
'ARFLAGS' => [],
|
||||
'ARCOM' => ['$AR', 'rcs', '$ARFLAGS', '$_TARGET', '$_SOURCES']
|
||||
'ARCOM' => ['${AR}', 'rcs', '${ARFLAGS}', '${_TARGET}', '${_SOURCES}']
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -13,13 +13,13 @@ module Rscons
|
||||
{
|
||||
'OBJSUFFIX' => '.o',
|
||||
|
||||
'AS' => '$CC',
|
||||
'AS' => '${CC}',
|
||||
'ASFLAGS' => [],
|
||||
'ASSUFFIX' => '.S',
|
||||
'ASPPPATH' => '$CPPPATH',
|
||||
'ASPPFLAGS' => '$CPPFLAGS',
|
||||
'ASDEPGEN' => ['-MMD', '-MF', '$_DEPFILE'],
|
||||
'ASCOM' => ['$AS', '-c', '-o', '$_TARGET', '$ASDEPGEN', '-I$[ASPPPATH]', '$ASPPFLAGS', '$ASFLAGS', '$_SOURCES'],
|
||||
'ASPPPATH' => '${CPPPATH}',
|
||||
'ASPPFLAGS' => '${CPPFLAGS}',
|
||||
'ASDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
|
||||
'ASCOM' => ['${AS}', '-c', '-o', '${_TARGET}', '${ASDEPGEN}', '-I${ASPPPATH}', '${ASPPFLAGS}', '${ASFLAGS}', '${_SOURCES}'],
|
||||
|
||||
'CPPFLAGS' => [],
|
||||
'CPPPATH' => [],
|
||||
@ -27,20 +27,20 @@ module Rscons
|
||||
'CC' => 'gcc',
|
||||
'CFLAGS' => [],
|
||||
'CSUFFIX' => '.c',
|
||||
'CCDEPGEN' => ['-MMD', '-MF', '$_DEPFILE'],
|
||||
'CCCOM' => ['$CC', '-c', '-o', '$_TARGET', '$CCDEPGEN', '-I$[CPPPATH]', '$CPPFLAGS', '$CFLAGS', '$_SOURCES'],
|
||||
'CCDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
|
||||
'CCCOM' => ['${CC}', '-c', '-o', '${_TARGET}', '${CCDEPGEN}', '-I${CPPPATH}', '${CPPFLAGS}', '${CFLAGS}', '${_SOURCES}'],
|
||||
|
||||
'CXX' => 'g++',
|
||||
'CXXFLAGS' => [],
|
||||
'CXXSUFFIX' => '.cc',
|
||||
'CXXDEPGEN' => ['-MMD', '-MF', '$_DEPFILE'],
|
||||
'CXXCOM' =>['$CXX', '-c', '-o', '$_TARGET', '$CXXDEPGEN', '-I$[CPPPATH]', '$CPPFLAGS', '$CXXFLAGS', '$_SOURCES'],
|
||||
'CXXDEPGEN' => ['-MMD', '-MF', '${_DEPFILE}'],
|
||||
'CXXCOM' =>['${CXX}', '-c', '-o', '${_TARGET}', '${CXXDEPGEN}', '-I${CPPPATH}', '${CPPFLAGS}', '${CXXFLAGS}', '${_SOURCES}'],
|
||||
|
||||
'DC' => 'gdc',
|
||||
'DFLAGS' => [],
|
||||
'DSUFFIX' => '.d',
|
||||
'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
|
||||
|
||||
|
@ -10,7 +10,7 @@ module Rscons
|
||||
'LDFLAGS' => [],
|
||||
'LIBPATH' => [],
|
||||
'LIBS' => [],
|
||||
'LDCOM' => ['$LD', '-o', '$_TARGET', '$LDFLAGS', '$_SOURCES', '-L$[LIBPATH]', '-l$[LIBS]']
|
||||
'LDCOM' => ['${LD}', '-o', '${_TARGET}', '${LDFLAGS}', '${_SOURCES}', '-L${LIBPATH}', '-l${LIBS}']
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -64,20 +64,16 @@ module Rscons
|
||||
expand_varref(ent)
|
||||
end.flatten
|
||||
else
|
||||
if varref =~ /^(.*)\$\[(\w+)\](.*)$/
|
||||
# expand array with given prefix, suffix
|
||||
if varref =~ /^(.*)\$\{([^}]+)\}(.*)$/
|
||||
prefix, varname, suffix = $1, $2, $3
|
||||
varval = expand_varref(@vars[varname])
|
||||
unless varval.is_a?(Array)
|
||||
raise "Array expected for $#{varname}"
|
||||
if varval.is_a?(String)
|
||||
"#{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
|
||||
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
|
||||
varref
|
||||
end
|
||||
|
@ -162,9 +162,9 @@ module Rscons
|
||||
it "returns a command based on the variables in the Environment" do
|
||||
env = Environment.new
|
||||
env["path"] = ["dir1", "dir2"]
|
||||
env["flags"] = ["-x", "-y", "$specialflag"]
|
||||
env["flags"] = ["-x", "-y", "${specialflag}"]
|
||||
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.should == ["cmd", "-Idir1", "-Idir2", "-x", "-y", "-z", "infile", "outfile"]
|
||||
end
|
||||
|
@ -84,30 +84,27 @@ module Rscons
|
||||
v = VarSet.new("CFLAGS" => ["-Wall", "-O2"],
|
||||
"CC" => "gcc",
|
||||
"CPPPATH" => ["dir1", "dir2"],
|
||||
"compiler" => "$CC",
|
||||
"cmd" => ["$CC", "-c", "$CFLAGS", "-I$[CPPPATH]"])
|
||||
"compiler" => "${CC}",
|
||||
"cmd" => ["${CC}", "-c", "${CFLAGS}", "-I${CPPPATH}"])
|
||||
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"
|
||||
v.expand_varref("str").should == "str"
|
||||
end
|
||||
it "expands a single variable reference beginning with a '$'" do
|
||||
v.expand_varref("$CC").should == "gcc"
|
||||
v.expand_varref("$CPPPATH").should == ["dir1", "dir2"]
|
||||
v.expand_varref("${CC}").should == "gcc"
|
||||
v.expand_varref("${CPPPATH}").should == ["dir1", "dir2"]
|
||||
end
|
||||
it "expands a single variable reference in $[arr] notation" do
|
||||
v.expand_varref("prefix$[CFLAGS]suffix").should == ["prefix-Wallsuffix", "prefix-O2suffix"]
|
||||
it "expands a single variable reference in ${arr} notation" do
|
||||
v.expand_varref("prefix${CFLAGS}suffix").should == ["prefix-Wallsuffix", "prefix-O2suffix"]
|
||||
v.expand_varref(v["cmd"]).should == ["gcc", "-c", "-Wall", "-O2", "-Idir1", "-Idir2"]
|
||||
end
|
||||
it "expands a variable reference recursively" do
|
||||
v.expand_varref("$compiler").should == "gcc"
|
||||
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/
|
||||
v.expand_varref("${compiler}").should == "gcc"
|
||||
v.expand_varref("${cmd}").should == ["gcc", "-c", "-Wall", "-O2", "-Idir1", "-Idir2"]
|
||||
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 /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
|
||||
|
Loading…
x
Reference in New Issue
Block a user