From 66f53a23f6d2402b853a2a943d61b1522ba45c0b Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 5 Nov 2013 16:53:55 -0500 Subject: [PATCH] change construction variable reference format to ${var} this change is backwards-incompatible --- lib/rscons/builders/library.rb | 2 +- lib/rscons/builders/object.rb | 20 ++++++++++---------- lib/rscons/builders/program.rb | 2 +- lib/rscons/varset.rb | 18 +++++++----------- spec/rscons/environment_spec.rb | 4 ++-- spec/rscons/varset_spec.rb | 21 +++++++++------------ 6 files changed, 30 insertions(+), 37 deletions(-) diff --git a/lib/rscons/builders/library.rb b/lib/rscons/builders/library.rb index fd8bb3a..600a374 100644 --- a/lib/rscons/builders/library.rb +++ b/lib/rscons/builders/library.rb @@ -8,7 +8,7 @@ module Rscons 'AR' => 'ar', 'LIBSUFFIX' => '.a', 'ARFLAGS' => [], - 'ARCOM' => ['$AR', 'rcs', '$ARFLAGS', '$_TARGET', '$_SOURCES'] + 'ARCOM' => ['${AR}', 'rcs', '${ARFLAGS}', '${_TARGET}', '${_SOURCES}'] } end diff --git a/lib/rscons/builders/object.rb b/lib/rscons/builders/object.rb index ccc01e9..6c2ead4 100644 --- a/lib/rscons/builders/object.rb +++ b/lib/rscons/builders/object.rb @@ -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 diff --git a/lib/rscons/builders/program.rb b/lib/rscons/builders/program.rb index 089dd4a..3254a64 100644 --- a/lib/rscons/builders/program.rb +++ b/lib/rscons/builders/program.rb @@ -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 diff --git a/lib/rscons/varset.rb b/lib/rscons/varset.rb index 429fcd3..4144e69 100644 --- a/lib/rscons/varset.rb +++ b/lib/rscons/varset.rb @@ -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 diff --git a/spec/rscons/environment_spec.rb b/spec/rscons/environment_spec.rb index 2579d33..9635c27 100644 --- a/spec/rscons/environment_spec.rb +++ b/spec/rscons/environment_spec.rb @@ -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 diff --git a/spec/rscons/varset_spec.rb b/spec/rscons/varset_spec.rb index 48edaa7..d117a92 100644 --- a/spec/rscons/varset_spec.rb +++ b/spec/rscons/varset_spec.rb @@ -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