oven.bake() now takes explicit basis object, no longer tries to set parent objects automatically

This commit is contained in:
Jason Perkins 2012-04-24 16:36:52 -04:00
parent bfeb1e6906
commit 15662f30c9
7 changed files with 29 additions and 29 deletions

View File

@ -30,6 +30,9 @@
--
-- @param container
-- The solution or project to query.
-- @param basis
-- A "parent" object containing an initial configuration. For example,
-- if baking a project, this would be the containing solution.
-- @param filterterms
-- An optional list of filter terms. Only configuration blocks which
-- match all of the terms in the list will be included in the result.
@ -40,7 +43,8 @@
-- A configuration object.
--
function oven.bake(container, filterTerms, filterField)
function oven.bake(container, basis, filterTerms, filterField)
local cfg = {}
filterTerms = filterTerms or {}
-- keyword/term tests are case-insensitive; convert all terms to lowercase
@ -49,19 +53,13 @@
casedTerms[key] = value:lower()
end
-- If I'm baking a project, start with the values from the solution level
local cfg
if container.solution then
cfg = oven.bake(container.solution, casedTerms, filterField)
else
cfg = {}
end
-- If there is a basis object, start with that
if basis then
cfg = oven.bake(basis, nil, filterTerms, filterField)
end
-- Merge container level (solution, project) in the result
cfg = oven.merge(cfg, container)
-- Attach a reference to the source container, as "solution" or "project"
cfg[type(container)] = container
-- Walk the blocks available in this container, and merge their values
-- into my configuration-in-progress, if they pass the keyword filter

View File

@ -130,10 +130,12 @@
["action"] = _ACTION
}
local cfg = premake5.oven.bake(prj.project or prj, filter, "system")
local cfg = premake5.oven.bake(prj.project or prj, prj.solution, filter, "system")
filter.system = cfg.system or system or premake.action.current().os or os.get()
cfg = premake5.oven.bake(prj.project or prj, filter, field)
cfg = premake5.oven.bake(prj.project or prj, prj.solution, filter, field)
cfg.solution = prj.solution
cfg.project = prj.project or prj
cfg.architecture = cfg.architecture or architecture
return cfg
end

View File

@ -38,7 +38,7 @@
function suite.solutionSet_whenCalledOnSolution()
prj = project("MyProject")
local cfg = oven.bake(prj)
local cfg = oven.bake(prj, sln)
test.istrue(prj == cfg.project)
end
@ -51,7 +51,7 @@
function suite.callPullProjectLevelConfig()
prj = project("MyProject")
files { "hello.cpp" }
cfg = oven.bake(prj, {}, "files")
cfg = oven.bake(prj, sln, {}, "files")
test.isequal("hello.cpp", cfg.files[1]:sub(-9))
end
@ -76,7 +76,7 @@
function suite.fieldValueReturned_onFilterFieldPresent()
configuration("Debug")
kind "SharedLib"
cfg = oven.bake(sln, {"Debug"}, "kind")
cfg = oven.bake(sln, nil, {"Debug"}, "kind")
test.isequal("SharedLib", cfg.kind)
end
@ -84,6 +84,6 @@
configuration("Debug")
kind("SharedLib")
defines("DEBUG")
cfg = oven.bake(sln, {"Debug"}, "kind")
cfg = oven.bake(sln, nil, {"Debug"}, "kind")
test.isnil(cfg.defines)
end

View File

@ -40,6 +40,6 @@
configmap { ["sln"] = "slnvalue" }
prj = project("MyProject")
configmap { ["prj"] = "prjvalue" }
local cfg = oven.bake(prj)
local cfg = oven.bake(prj, sln)
test.istrue(cfg.configmap.sln ~= nil and cfg.configmap.prj ~= nil)
end

View File

@ -51,7 +51,7 @@
function suite.projectValuePreset_onProjectConfig()
prj = project "MyProject"
defines "PROJECT"
local cfg = oven.bake(prj)
local cfg = oven.bake(prj, sln)
test.isequal("PROJECT", table.concat(cfg.defines))
end
@ -64,7 +64,7 @@
function suite.solutionValuePresent_onProjectConfig()
defines("SOLUTION")
prj = project("MyProject")
local cfg = oven.bake(prj)
local cfg = oven.bake(prj, sln)
test.isequal("SOLUTION", table.concat(cfg.defines))
end
@ -79,7 +79,7 @@
defines("SOLUTION")
prj = project("MyProject")
defines("PROJECT")
local cfg = oven.bake(prj)
local cfg = oven.bake(prj, sln)
test.isequal("SOLUTION|PROJECT", table.concat(cfg.defines, "|"))
end
@ -91,14 +91,14 @@
function suite.valueFromGeneralConfigPreset_onMoreSpecificConfig()
defines("SOLUTION")
local cfg = oven.bake(sln, {"Debug"})
local cfg = oven.bake(sln, nil, {"Debug"})
test.isequal("SOLUTION", table.concat(cfg.defines))
end
function suite.valueFromGeneralConfigPreset_onMoreSpecificConfig()
configuration("Debug")
defines("DEBUG")
local cfg = oven.bake(sln, {"Debug","Windows"})
local cfg = oven.bake(sln, nil, {"Debug","Windows"})
test.isequal("DEBUG", table.concat(cfg.defines))
end
@ -118,7 +118,7 @@
function suite.configValuePresent_ifMatchingFilterTerm()
configuration("Debug")
kind "SharedLib"
cfg = oven.bake(sln, {"Debug"})
cfg = oven.bake(sln, nil, {"Debug"})
test.isequal("SharedLib", cfg.kind)
end
@ -136,7 +136,7 @@
defines("PROJECT")
configuration("Debug")
defines("PRJ_DEBUG")
cfg = oven.bake(prj , {"Debug"})
cfg = oven.bake(prj , sln, {"Debug"})
test.isequal("SOLUTION|SLN_DEBUG|PROJECT|PRJ_DEBUG", table.concat(cfg.defines, "|"))
end
@ -149,6 +149,6 @@
defines { "SOLUTION", "DUPLICATE" }
prj = project("MyProject")
defines { "PROJECT", "DUPLICATE" }
cfg = oven.bake(prj, {"Debug"})
cfg = oven.bake(prj, sln, {"Debug"})
test.isequal("SOLUTION|DUPLICATE|PROJECT", table.concat(cfg.defines, "|"))
end

View File

@ -34,6 +34,6 @@
buildrule { description="sln" }
prj = project("MyProject")
buildrule { description="prj" }
cfg = oven.bake(prj, {"Debug"})
cfg = oven.bake(prj, sln, {"Debug"})
test.isequal("prj", cfg.buildrule.description)
end

View File

@ -80,6 +80,6 @@
configurations { "Debug", "Release" }
local prj = project "MyProject"
removeconfigurations { "Debug" }
cfg = oven.bake(prj)
cfg = oven.bake(prj, sln)
test.isequal({ "Release" }, cfg.configurations)
end