From 4ca4a1d0a0a69cb74f015bf15a1ebe41f11c4987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Thu, 27 Feb 2020 19:45:56 +0000 Subject: [PATCH] Add build steps to Visual Studio --- modules/vstudio/tests/_tests.lua | 1 + .../vstudio/tests/vc2010/test_build_steps.lua | 92 +++++++++++++++++++ modules/vstudio/vs2010_vcxproj.lua | 45 ++++++++- 3 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 modules/vstudio/tests/vc2010/test_build_steps.lua diff --git a/modules/vstudio/tests/_tests.lua b/modules/vstudio/tests/_tests.lua index 2a742999..fd418b36 100644 --- a/modules/vstudio/tests/_tests.lua +++ b/modules/vstudio/tests/_tests.lua @@ -55,6 +55,7 @@ return { "vc2010/test_assembly_refs.lua", "vc2010/test_build_events.lua", "vc2010/test_build_log.lua", + "vc2010/test_build_steps.lua", "vc2010/test_character_set.lua", "vc2010/test_compile_settings.lua", "vc2010/test_config_props.lua", diff --git a/modules/vstudio/tests/vc2010/test_build_steps.lua b/modules/vstudio/tests/vc2010/test_build_steps.lua new file mode 100644 index 00000000..0a8026b0 --- /dev/null +++ b/modules/vstudio/tests/vc2010/test_build_steps.lua @@ -0,0 +1,92 @@ +-- +-- tests/actions/vstudio/vc2010/test_compile_settings.lua +-- Validate compiler settings in Visual Studio 2010 C/C++ projects. +-- Copyright (c) 2011-2020 Jason Perkins and the Premake project +-- + + local p = premake + local suite = test.declare("vstudio_vs2010_build_steps") + local vc2010 = p.vstudio.vc2010 + local project = p.project + + +-- +-- Setup +-- + + local wks, prj + + function suite.setup() + p.action.set("vs2010") + wks, prj = test.createWorkspace() + end + + local function prepare(platform) + local cfg = test.getconfig(prj, "Debug", platform) + vc2010.buildStep(cfg) + end + +-- +-- Check that we output nothing unless there is something to output +-- + + function suite.buildStepNone() + prepare() + test.capture [[ + ]] + end + +-- +-- Check the basic build step example +-- + + function suite.buildStepBasic() + buildcommands("Example.exe") + prepare() + test.capture [[ + + Example.exe + + ]] + end + +-- +-- Check a normal build step setup +-- + + function suite.buildStepCommon() + buildcommands("Example.exe") + buildoutputs("Example.out") + buildinputs("Example.in") + buildmessage("Hello World") + prepare() + test.capture [[ + + Example.exe + Hello World + Example.out + Example.in + + ]] + end + + +-- +-- Check a more complex build step setup +-- + + function suite.buildStepComplex() + buildcommands ( "Example.exe" ) + buildoutputs { "Example.out", "Example2.out" } + buildinputs { "Example.in", "Example2.in" } + buildmessage("Hello World") + prepare() + test.capture [[ + + Example.exe + Hello World + Example.out;Example2.out + Example.in;Example2.in + + ]] + end \ No newline at end of file diff --git a/modules/vstudio/vs2010_vcxproj.lua b/modules/vstudio/vs2010_vcxproj.lua index 112c9467..faa07c6f 100644 --- a/modules/vstudio/vs2010_vcxproj.lua +++ b/modules/vstudio/vs2010_vcxproj.lua @@ -307,6 +307,7 @@ else return { m.clCompile, + m.buildStep, m.fxCompile, m.resourceCompile, m.linker, @@ -395,6 +396,31 @@ p.pop('') end +-- +-- Write the the compiler settings block. +-- + + m.elements.buildStep = function(cfg) + local calls = { + m.buildCommands, + m.buildMessage, + m.buildOutputs, + m.buildInputs + } + + return calls + end + + function m.buildStep(cfg) + if #cfg.buildCommands > 0 or #cfg.buildOutputs > 0 or #cfg.buildInputs > 0 or cfg.buildMessage then + + p.push('') + p.callArray(m.elements.buildStep, cfg) + p.pop('') + + end + end + -- -- Write the settings block. @@ -1514,6 +1540,12 @@ end end + function m.buildInputs(cfg, condition) + if cfg.buildinputs and #cfg.buildinputs > 0 then + local inputs = project.getrelative(cfg.project, cfg.buildinputs) + m.element("Inputs", condition, '%s', table.concat(inputs, ";")) + end + end function m.buildAdditionalInputs(fcfg, condition) if fcfg.buildinputs and #fcfg.buildinputs > 0 then @@ -1524,9 +1556,10 @@ function m.buildCommands(fcfg, condition) - local commands = os.translateCommandsAndPaths(fcfg.buildcommands, fcfg.project.basedir, fcfg.project.location) - commands = table.concat(commands,'\r\n') - m.element("Command", condition, '%s', commands) + if #fcfg.buildcommands > 0 then + local commands = os.translateCommandsAndPaths(fcfg.buildcommands, fcfg.project.basedir, fcfg.project.location) + m.element("Command", condition, '%s', table.concat(commands,'\r\n')) + end end @@ -1547,8 +1580,10 @@ function m.buildOutputs(fcfg, condition) - local outputs = project.getrelative(fcfg.project, fcfg.buildoutputs) - m.element("Outputs", condition, '%s', table.concat(outputs, ";")) + if #fcfg.buildoutputs > 0 then + local outputs = project.getrelative(fcfg.project, fcfg.buildoutputs) + m.element("Outputs", condition, '%s', table.concat(outputs, ";")) + end end