From 81ea63c877a276c94b1d6d8f8bc8e2f9208d3b61 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Wed, 28 Dec 2011 16:44:09 -0500 Subject: [PATCH] Implement project.eachconfig(), to iterate through the new build configuration/platform pairs --- src/project/oven.lua | 23 ++++++++++++++++----- src/project/project.lua | 26 +++++++++++++++++++++-- tests/project/test_baking.lua | 16 ++++++++++++--- tests/project/test_eachconfig.lua | 34 +++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 10 deletions(-) diff --git a/src/project/oven.lua b/src/project/oven.lua index ddbb280b..5fc919fe 100755 --- a/src/project/oven.lua +++ b/src/project/oven.lua @@ -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 diff --git a/src/project/project.lua b/src/project/project.lua index 0ee68198..f872b29f 100755 --- a/src/project/project.lua +++ b/src/project/project.lua @@ -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 diff --git a/tests/project/test_baking.lua b/tests/project/test_baking.lua index ef6a136d..81a4e2c5 100755 --- a/tests/project/test_baking.lua +++ b/tests/project/test_baking.lua @@ -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 diff --git a/tests/project/test_eachconfig.lua b/tests/project/test_eachconfig.lua index 3d29967e..76d2da48 100755 --- a/tests/project/test_eachconfig.lua +++ b/tests/project/test_eachconfig.lua @@ -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