Add onsolution() and onproject() callbacks to actions

This commit is contained in:
starkos 2009-08-11 00:49:11 +00:00
parent d22b58dca2
commit 1fc95ca780
2 changed files with 30 additions and 8 deletions

View File

@ -77,7 +77,7 @@
function premake.action.call(name)
local a = premake.action.list[name]
-- walk the session objects and generate files from the templates
-- walk the session objects and pass to the action for handling
local function generatefiles(this, templates)
if (not templates) then return end
for _,tmpl in ipairs(templates) do
@ -103,13 +103,19 @@
end
for _,sln in ipairs(_SOLUTIONS) do
if type(a.onsolution) == "function" then
a.onsolution(sln)
end
generatefiles(sln, a.solutiontemplates)
for prj in premake.eachproject(sln) do
if type(a.onproject) == "function" then
a.onproject(prj)
end
generatefiles(prj, a.projecttemplates)
end
end
-- if the action has an execute() function, call it
-- call execute() to perform general processing
if type(a.execute) == "function" then
a.execute()
end

View File

@ -18,6 +18,10 @@
function T.action.setup()
premake.action.list["fake"] = fake
solution "MySolution"
configurations "Debug"
project "MyProject"
premake.buildconfigs()
end
function T.action.teardown()
@ -27,18 +31,30 @@
--
-- Tests
-- Tests for call()
--
function T.action.ExecuteIsCalledIfPresent()
function T.action.CallCallsExecuteIfPresent()
local called = false
fake.execute = function () called = true end
premake.action.call("fake")
test.istrue(called)
end
function T.action.ExecuteIsSkippedIfNotPresent()
test.success(premake.action.call, "fake")
function T.action.CallCallsOnSolutionIfPresent()
local called = false
fake.onsolution = function () called = true end
premake.action.call("fake")
test.istrue(called)
end
function T.action.CallCallsOnProjectIfPresent()
local called = false
fake.onproject = function () called = true end
premake.action.call("fake")
test.istrue(called)
end
function T.action.CallSkipsCallbacksIfNotPresent()
test.success(premake.action.call, "fake")
end