From 3dd3166c140c7748fbf174087339aca677dc0400 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Wed, 28 Nov 2012 11:14:47 -0500 Subject: [PATCH] Add pre- and post-build support to Visual Studio C# projects --- CHANGES.txt | 2 + src/actions/vstudio/vs2005_csproj.lua | 24 ++++- .../vstudio/cs2005/test_build_events.lua | 88 +++++++++++++++++++ tests/premake4.lua | 1 + 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 tests/actions/vstudio/cs2005/test_build_events.lua diff --git a/CHANGES.txt b/CHANGES.txt index 7c9e09cd..c171e5ba 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -21,6 +21,8 @@ * Added debugcommand for Visual Studio (xpol) * Bug 1674173: Allow source files to have the same name * Added forceinclude() to specify forced include files +* Visual Studio C# projects now support architectures +* Visual Studio C# projects now support pre- and post-build commands ------- diff --git a/src/actions/vstudio/vs2005_csproj.lua b/src/actions/vstudio/vs2005_csproj.lua index 7df94f8d..9502800e 100644 --- a/src/actions/vstudio/vs2005_csproj.lua +++ b/src/actions/vstudio/vs2005_csproj.lua @@ -27,7 +27,7 @@ cs2005.propertyGroup(cfg) cs2005.debugProps(cfg) cs2005.outputProps(cfg) - cs2005.compilerProps(cfg) + cs2005.compilerProps(cfg) _p(1,'') end @@ -48,6 +48,8 @@ _p(' ') _p(' -->') + cs2005.buildEvents(prj) + _p('') end @@ -165,6 +167,26 @@ end +-- +-- Write out pre- and post-build events, if provided. +-- + + function cs2005.buildEvents(prj) + local function output(name, steps) + if #steps > 0 then + _x(2,'<%sBuildEvent>%s', name, table.implode(steps, "", "", "\r\n"), name) + end + end + + if #prj.prebuildcommands > 0 or #prj.postbuildcommands > 0 then + _p(1,'') + output("Pre", prj.prebuildcommands) + output("Post", prj.postbuildcommands) + _p(1,'') + end + end + + -- -- Write the compiler flags for a particular configuration. -- diff --git a/tests/actions/vstudio/cs2005/test_build_events.lua b/tests/actions/vstudio/cs2005/test_build_events.lua new file mode 100644 index 00000000..50a0cf54 --- /dev/null +++ b/tests/actions/vstudio/cs2005/test_build_events.lua @@ -0,0 +1,88 @@ +-- +-- tests/actions/vstudio/cs2005/test_build_events.lua +-- Check generation of pre- and post-build commands for C# projects. +-- Copyright (c) 2012 Jason Perkins and the Premake project +-- + + T.vstudio_cs2005_build_events = {} + local suite = T.vstudio_cs2005_build_events + local cs2005 = premake.vstudio.cs2005 + + +-- +-- Setup +-- + + local sln, prj, cfg + + function suite.setup() + sln = test.createsolution() + end + + local function prepare(platform) + prj = premake.solution.getproject_ng(sln, 1) + cs2005.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 [[ + + command1 + + ]] + end + + function suite.onlyOne_onPostBuildOnly() + postbuildcommands { "command1" } + prepare() + test.capture [[ + + command1 + + ]] + end + + function suite.both_onBoth() + prebuildcommands { "command1" } + postbuildcommands { "command2" } + prepare() + test.capture [[ + + command1 + command2 + + ]] + end + + +-- +-- Multiple commands are separated with escaped EOL characters. +-- + + function suite.splits_onMultipleCommands() + postbuildcommands { "command1", "command2" } + prepare() + test.capture [[ + + command1 command2 + + ]] + end + diff --git a/tests/premake4.lua b/tests/premake4.lua index c61f1fff..4e513a76 100644 --- a/tests/premake4.lua +++ b/tests/premake4.lua @@ -88,6 +88,7 @@ -- Visual Studio 2005-2010 C# projects dofile("actions/vstudio/cs2005/test_assembly_refs.lua") + dofile("actions/vstudio/cs2005/test_build_events.lua") dofile("actions/vstudio/cs2005/test_compiler_props.lua") dofile("actions/vstudio/cs2005/test_debug_props.lua") dofile("actions/vstudio/cs2005/test_files.lua")