Fixed VC 2010 escaping of custom build steps

This commit is contained in:
Jason Perkins 2014-01-10 10:40:45 -05:00
parent 48bbde5334
commit 2efe9d780d
7 changed files with 117 additions and 32 deletions

View File

@ -17,18 +17,6 @@
cs2005.elements = {}
--
-- XML escaping for C# projects is a little different than for C++.
--
function cs2005.esc(value)
value = value:gsub('&', "&")
value = value:gsub('<', "&lt;")
value = value:gsub('>', "&gt;")
return value
end
--
-- Generate a Visual Studio 200x C# project, with support for the new platforms API.
--
@ -45,7 +33,6 @@
function cs2005.generate(prj)
io.indent = " "
io.eol = "\r\n"
io.esc = cs2005.esc
io.utf8()
premake.callarray(cs2005, cs2005.elements.project, prj)

View File

@ -36,6 +36,19 @@
--
-- The VS 2010 standard for XML escaping in generated project files.
--
function vs2010.esc(value)
value = value:gsub('&', "&amp;")
value = value:gsub('<', "&lt;")
value = value:gsub('>', "&gt;")
return value
end
---
-- Define the Visual Studio 2010 export action.
---

View File

@ -27,7 +27,6 @@
function vc2010.generate(prj)
io.indent = " "
io.esc = vc2010.esc
io.utf8()
vc2010.xmlDeclaration()
@ -71,22 +70,6 @@
---
-- Apply XML escaping on a value to be included in an
-- exported project file.
---
function vc2010.esc(value)
value = string.gsub(value, '&', "&amp;")
value = value:gsub('<', "&lt;")
value = value:gsub('>', "&gt;")
value = value:gsub('\r', "&#x0D;")
value = value:gsub('\n', "&#x0A;")
return value
end
--
-- Output the XML declaration and opening <Project> tag.
--

View File

@ -15,7 +15,7 @@
local sln, prj, cfg
function suite.setup()
io.esc = cs2005.esc
io.esc = premake.vstudio.vs2010.esc
sln = test.createsolution()
end

View File

@ -0,0 +1,101 @@
--
-- tests/actions/vstudio/vc2010/test_build_events.lua
-- Check generation of pre- and post-build commands for C++ projects.
-- Copyright (c) 2012-2013 Jason Perkins and the Premake project
--
local suite = test.declare("vstudio_vc2010_build_events")
local vc2010 = premake.vstudio.vc2010
--
-- Setup
--
local sln, prj, cfg
function suite.setup()
io.esc = premake.vstudio.vs2010.esc
sln = test.createsolution()
end
local function prepare(platform)
prj = premake.solution.getproject(sln, 1)
vc2010.buildEvents(prj)
end
--
-- If no build steps are specified, nothing should be written.
--
function suite.noOutput_onNoEvents()
prepare()
test.isemptycapture()
end
--
-- If one command set is used and not the other, only the one should be written.
--
function suite.onlyOne_onPreBuildOnly()
prebuildcommands { "command1" }
prepare()
test.capture [[
<PreBuildEvent>
<Command>command1</Command>
</PreBuildEvent>
]]
end
function suite.onlyOne_onPostBuildOnly()
postbuildcommands { "command1" }
prepare()
test.capture [[
<PostBuildEvent>
<Command>command1</Command>
</PostBuildEvent>
]]
end
function suite.both_onBoth()
prebuildcommands { "command1" }
postbuildcommands { "command2" }
prepare()
test.capture [[
<PreBuildEvent>
<Command>command1</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>command2</Command>
</PostBuildEvent>
]]
end
--
-- Multiple commands should be separated with un-escaped EOLs.
--
function suite.splits_onMultipleCommands()
postbuildcommands { "command1", "command2" }
prepare()
test.capture ("\t\t<PostBuildEvent>\n\t\t\t<Command>command1\r\ncommand2</Command>\n\t\t</PostBuildEvent>\n")
end
--
-- Quotes should not be escaped, other special characters should.
--
function suite.onSpecialChars()
postbuildcommands { '\' " < > &' }
prepare()
test.capture [[
<PostBuildEvent>
<Command>' " &lt; &gt; &amp;</Command>
</PostBuildEvent>
]]
end

View File

@ -16,7 +16,7 @@
local sln, prj
function suite.setup()
io.esc = vc2010.esc
io.esc = premake.vstudio.vs2010.esc
sln, prj = test.createsolution()
end

View File

@ -142,6 +142,7 @@
-- Visual Studio 2010 C/C++ projects
dofile("actions/vstudio/vc2010/test_assembly_refs.lua")
dofile("actions/vstudio/vc2010/test_build_events.lua")
dofile("actions/vstudio/vc2010/test_compile_settings.lua")
dofile("actions/vstudio/vc2010/test_config_props.lua")
dofile("actions/vstudio/vc2010/test_debug_settings.lua")