Merged in noresources/premake-dev-ns/makefile-groups (pull request #112)

Transform solution groups into target aggregates in Makefiles (bis)
This commit is contained in:
Jason Perkins 2014-09-20 18:50:56 -04:00
commit 65a89ab098
3 changed files with 116 additions and 4 deletions

View File

@ -6,6 +6,7 @@
local make = premake.make
local solution = premake.solution
local tree = premake.tree
local project = premake.project
@ -21,10 +22,8 @@
make.configmap(sln)
make.projects(sln)
_p('.PHONY: all clean help $(PROJECTS)')
_p('')
_p('all: $(PROJECTS)')
_p('')
make.solutionPhonyRule(sln)
make.groupRules(sln)
make.projectrules(sln)
make.cleanrules(sln)
@ -106,6 +105,59 @@
_p('')
end
--
-- Write out the solution PHONY rule
--
function make.solutionPhonyRule(sln)
local groups = {}
local tr = solution.grouptree(sln)
tree.traverse(tr, {
onbranch = function(n)
table.insert(groups, n.path)
end
})
_p('.PHONY: all clean help $(PROJECTS) ' .. table.implode(groups, '', '', ' '))
_p('')
_p('all: $(PROJECTS)')
_p('')
end
--
-- Write out the phony rules representing project groups
--
function make.groupRules(sln)
-- Transform solution groups into target aggregate
local tr = solution.grouptree(sln)
tree.traverse(tr, {
onbranch = function(n)
local rule = n.path .. ":"
local projectTargets = {}
local groupTargets = {}
for i, c in pairs(n.children)
do
if type(i) == "string"
then
if c.project
then
table.insert(projectTargets, c.name)
else
table.insert(groupTargets, c.path)
end
end
end
if #groupTargets > 0 then
rule = rule .. " " .. table.concat(groupTargets, " ")
end
if #projectTargets > 0 then
rule = rule .. " " .. table.concat(projectTargets, " ")
end
_p(rule)
_p('')
end
})
end
--
-- Write out the rules to build each of the solution's projects.

View File

@ -138,6 +138,7 @@ return {
-- Makefile solutions
"actions/make/solution/test_config_maps.lua",
"actions/make/solution/test_default_config.lua",
"actions/make/solution/test_group_rule.lua",
"actions/make/solution/test_help_rule.lua",
"actions/make/solution/test_project_rule.lua",

View File

@ -0,0 +1,59 @@
--
-- tests/actions/make/solution/test_group_rule.lua
-- Validate generation of group rules
-- Copyright (c) 2012-2014 Jason Perkins and the Premake project
--
T.make_group_rule = {}
local suite = T.make_group_rule
local make = premake.make
--
-- Setup/teardown
--
local sln
function suite.setup()
sln = test.createsolution()
group "MainGroup"
test.createproject(sln)
group "MainGroup/SubGroup1"
test.createproject(sln)
group "MainGroup/SubGroup2"
test.createproject(sln)
test.createproject(sln)
end
local function prepare()
sln = premake.oven.bakeSolution(sln)
end
--
-- Groups should be added to solution's PHONY
--
function suite.groupRule_groupAsPhony()
prepare()
make.solutionPhonyRule(sln)
test.capture [[
.PHONY: all clean help $(PROJECTS) MainGroup MainGroup/SubGroup1 MainGroup/SubGroup2
]]
end
--
-- Transform solution groups into target aggregate
--
function suite.groupRule_groupRules()
prepare()
make.groupRules(sln)
test.capture [[
MainGroup: MainGroup/SubGroup1 MainGroup/SubGroup2 MyProject2
MainGroup/SubGroup1: MyProject3
MainGroup/SubGroup2: MyProject4 MyProject5
]]
end