Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build steps to Visual Studio #1403

Merged
merged 2 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/vstudio/tests/_tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
92 changes: 92 additions & 0 deletions modules/vstudio/tests/vc2010/test_build_steps.lua
Original file line number Diff line number Diff line change
@@ -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 [[
<CustomBuildStep>
<Command>Example.exe</Command>
</CustomBuildStep>
]]
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 [[
<CustomBuildStep>
<Command>Example.exe</Command>
<Message>Hello World</Message>
<Outputs>Example.out</Outputs>
<Inputs>Example.in</Inputs>
</CustomBuildStep>
]]
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 [[
<CustomBuildStep>
<Command>Example.exe</Command>
<Message>Hello World</Message>
<Outputs>Example.out;Example2.out</Outputs>
<Inputs>Example.in;Example2.in</Inputs>
</CustomBuildStep>
]]
end
45 changes: 40 additions & 5 deletions modules/vstudio/vs2010_vcxproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@
else
return {
m.clCompile,
m.buildStep,
m.fxCompile,
m.resourceCompile,
m.linker,
Expand Down Expand Up @@ -395,6 +396,31 @@
p.pop('</ClCompile>')
end

--
-- Write the the <CustomBuildStep> 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('<CustomBuildStep>')
p.callArray(m.elements.buildStep, cfg)
p.pop('</CustomBuildStep>')

end
end


--
-- Write the <FxCompile> settings block.
Expand Down Expand Up @@ -1512,6 +1538,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
Expand All @@ -1522,9 +1554,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


Expand All @@ -1545,8 +1578,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


Expand Down