Implement project.eachconfig(), to iterate through the new build configuration/platform pairs

This commit is contained in:
Jason Perkins 2011-12-28 16:44:09 -05:00
parent 12b033afc0
commit 81ea63c877
4 changed files with 89 additions and 10 deletions

View File

@ -8,6 +8,17 @@
local oven = premake5.oven
--
-- These configuration fields are used to support the baking process, and
-- should not be included in any generated configuration objects.
--
local nomerge =
{
keywords = true
}
--
-- The main entry point: walks through all of the configuration data
-- present in the project and "bakes" it into a single object, filtered
@ -43,7 +54,7 @@
cfg[type(container)] = container
-- Walk the blocks available in this container, and merge their values
-- into my configuration-in-progress
-- into my configuration-in-progress, if they pass the keyword filter
for _, block in ipairs(container.blocks) do
if oven.filter(block, filterTerms) then
oven.merge(cfg, block)
@ -126,10 +137,12 @@
function oven.merge(cfg, block)
for key, value in pairs(block) do
if type(value) == "table" then
cfg[key] = oven.mergetables(cfg[key] or {}, value)
else
cfg[key] = value
if not nomerge[key] then
if type(value) == "table" then
cfg[key] = oven.mergetables(cfg[key] or {}, value)
else
cfg[key] = value
end
end
end
end

View File

@ -5,7 +5,9 @@
--
premake5.project = { }
local project = premake5.project
local premake = premake5
local project = premake.project
--
-- Returns an iterator function for the configuration objects contained by
@ -14,11 +16,31 @@
--
-- @param prj
-- The project object to query.
-- @returns
-- @return
-- An iterator function returning configuration objects.
--
function project.eachconfig(prj)
local buildconfigs = prj.solution.configurations or {}
local platforms = prj.solution.platforms or {}
local i = 0
local j = #platforms
return function ()
j = j + 1
if j > #platforms then
i = i + 1
j = 1
end
if i > #buildconfigs then
return nil
end
local cfg = premake.oven.bake(prj, { buildconfigs[i], platforms[j] })
cfg.buildcfg = buildconfigs[i]
cfg.platform = platforms[j]
return cfg
end
end

View File

@ -19,9 +19,6 @@
sln = solution("MySolution")
end
local function prepare()
end
--
-- When a solution is baked, a reference to that solution should be
@ -164,3 +161,16 @@
cfg = oven.bake(prj , {"Debug"})
test.isequal("SOLUTION|SLN_DEBUG|PROJECT|PRJ_DEBUG", table.concat(cfg.defines, "|"))
end
--
-- The keywords field should NOT be included in the configuration objects
-- returned by the backing process.
--
function suite.noKeywordsInBakingResults()
configuration("Debug")
defines("DEBUG")
cfg = oven.bake(sln)
test.isnil(cfg.keywords)
end

View File

@ -23,6 +23,15 @@
prj = project("MyProject")
end
local function collect(fn)
prepare()
local result = { }
for cfg in premake.project.eachconfig(prj) do
table.insert(result, fn(cfg))
end
return result
end
--
-- The return value should be a function.
@ -58,3 +67,28 @@
local it = premake.project.eachconfig(prj)
test.isnil(it())
end
--
-- Configurations should be iterated in the order in which they
-- appear in the script.
--
function suite.iteratesConfigsInOrder()
configurations { "Debug", "Profile", "Release", "Deploy" }
local r = collect(function(cfg) return cfg.buildcfg end)
test.isequal("Debug|Profile|Release|Deploy", table.concat(r, "|"))
end
--
-- If platforms are supplied, they should be paired with build
-- configurations, with the order of both maintained.
--
function suite.pairsConfigsAndPlatformsInOrder()
configurations { "Debug", "Release" }
platforms { "x32", "x64" }
local r = collect(function(cfg) return (cfg.buildcfg .. "+" .. cfg.platform) end)
test.isequal("Debug+x32|Debug+x64|Release+x32|Release+x64", table.concat(r, "|"))
end