Config sets can now be hierarchical; pull target information from sets instead of old configs

This commit is contained in:
Jason Perkins 2012-11-01 16:34:06 -04:00
parent 6c19509737
commit 3d6e03e966
4 changed files with 38 additions and 14 deletions

View File

@ -103,6 +103,10 @@
function configset.fetchvalue(cfgset, fieldname, context)
local value = nil
if cfgset.parent then
value = configset.fetchvalue(cfgset.parent, fieldname, context)
end
for _, block in ipairs(cfgset.blocks) do
if criteria.matches(block.criteria, context) then
value = block[fieldname] or value

View File

@ -53,24 +53,20 @@
local basedir = project.getlocation(cfg.project)
local directory = cfg[field.."dir"] or cfg.targetdir or basedir
local basename = cfg[field.."name"] or cfg.targetname or cfg.project.name
local basename = cfg.context[field.."name"] or cfg.context.targetname or cfg.project.name
local prefix = cfg.context[field.."prefix"] or cfg.context.targetprefix or ""
local suffix = cfg.context[field.."suffix"] or cfg.context.targetsuffix or ""
local extension = cfg.context[field.."extension"] or ""
local bundlename = ""
local bundlepath = ""
local suffix = ""
local prefix = cfg.context[field.."prefix"] or ""
local extension = cfg.context[field.."extension"] or ""
-- Mac .app requires more logic than I can bundle up in a table right now
if cfg.system == premake.MACOSX and kind == premake.WINDOWEDAPP then
bundlename = basename .. ".app"
bundlepath = path.join(bundlename, "Contents/MacOS")
end
prefix = cfg[field.."prefix"] or cfg.targetprefix or prefix
suffix = cfg[field.."suffix"] or cfg.targetsuffix or suffix
extension = cfg[field.."extension"] or extension
local info = {}
info.directory = directory
info.basename = basename .. suffix

View File

@ -116,8 +116,8 @@
-- Temporary: Create a context for this configuration. Eventually, the context
-- will become the configuration object and much of this baking code will go
-- away. For right now, it provides a way to access the global settings that
-- match this configuration's setup.
-- away. Right now, I am gradually filling in the gaps in the config sets and
-- contexts, and passing through accessors as they are ready
filter = { cfg.buildcfg, cfg.platform, _ACTION, cfg.system, cfg.architecture, cfg.kind, prj.language }
local terms = {}
@ -126,7 +126,8 @@
table.insert(terms, v)
end
end
cfg.context = context.new(premake.configset.root, terms)
cfg.context = context.new(cfg.configset, terms)
-- fill in any calculated values
premake5.config.bake(cfg)

View File

@ -14,10 +14,11 @@
-- Setup and teardown
--
local cfgset
local cfgset, parentset
function suite.setup()
cfgset = configset.new()
parentset = configset.new()
cfgset = configset.new(parentset)
end
@ -73,3 +74,25 @@
configset.addvalue(cfgset, "targetextension", ".dll")
test.isequal(".so", configset.fetchvalue(cfgset, "targetextension", { "linux" }))
end
--
-- Values stored in a parent configuration set should propagate into child.
--
function suite.canRoundtrip_fromParentToChild()
configset.addvalue(parentset, "targetextension", ".so")
test.isequal(".so", configset.fetchvalue(cfgset, "targetextension", {}))
end
--
-- Child should be able to override parent values.
--
function suite.child_canOverrideStringValueFromParent()
configset.addvalue(parentset, "targetextension", ".so")
configset.addvalue(cfgset, "targetextension", ".dll")
test.isequal(".dll", configset.fetchvalue(cfgset, "targetextension", {}))
end