Initial connection of config sets to the public configuration API

This commit is contained in:
Jason Perkins 2012-10-31 15:46:28 -04:00
parent 211b538248
commit fb5aaf860c
11 changed files with 145 additions and 132 deletions

View File

@ -30,9 +30,9 @@
"base/premake.lua",
-- configuration APIs
"base/api.lua",
"base/configset.lua",
"base/context.lua",
"base/api.lua",
-- runtime environment setup
"_premake_init.lua",

View File

@ -15,8 +15,8 @@
-- and on down the line.
--
premake.root = configset.new()
local root = premake.root
configset.root = configset.new()
local root = configset.root
--
@ -36,86 +36,71 @@
-- Use Posix-style target naming by default, since it is the most common.
--
configset.addblock(root, { "SharedLib" })
configset.addvalue(root, "targetprefix", "lib")
configset.addvalue(root, "targetextension", ".so")
configuration { "SharedLib" }
targetprefix "lib"
targetextension ".so"
configset.addblock(root, { "StaticLib" })
configset.addvalue(root, "targetprefix", "lib")
configset.addvalue(root, "targetextension", ".a")
configuration { "StaticLib" }
targetprefix "lib"
targetextension ".a"
--
-- Add variations for other Posix-like systems.
--
configset.addblock(root, { "MacOSX", "SharedLib" })
configset.addvalue(root, "targetextension", ".dylib")
configuration { "MacOSX", "SharedLib" }
targetextension ".dylib"
configset.addblock(root, { "PS3", "ConsoleApp" })
configset.addvalue(root, "targetextension", ".elf")
configuration { "PS3", "ConsoleApp" }
targetextension ".elf"
--
-- Windows and friends.
--
configset.addblock(root, { "Windows", "ConsoleApp" })
configset.addvalue(root, "targetextension", ".exe")
configuration { "Windows", "ConsoleApp" }
targetextension ".exe"
configset.addblock(root, { "Windows", "WindowedApp" })
configset.addvalue(root, "targetextension", ".exe")
configuration { "Windows", "WindowedApp" }
targetextension ".exe"
configset.addblock(root, { "Windows", "SharedLib" })
configset.addvalue(root, "targetprefix", "")
configset.addvalue(root, "targetextension", ".dll")
configset.addvalue(root, "implibextension", ".lib")
configuration { "Windows", "SharedLib" }
targetprefix ""
targetextension ".dll"
implibextension ".lib"
configset.addblock(root, { "Windows", "StaticLib" })
configuration { "Windows", "StaticLib" }
targetprefix ""
targetextension ".lib"
configset.addvalue(root, "targetprefix", "")
configset.addvalue(root, "targetextension", ".lib")
configuration { "Xbox360", "ConsoleApp" }
targetextension ".exe"
configuration { "Xbox360", "WindowedApp" }
targetextension ".exe"
configset.addblock(root, { "Xbox360", "ConsoleApp" })
configset.addvalue(root, "targetextension", ".exe")
configuration { "Xbox360", "SharedLib" }
targetprefix ""
targetextension ".dll"
implibextension ".lib"
configset.addblock(root, { "Xbox360", "WindowedApp" })
configset.addvalue(root, "targetextension", ".exe")
configset.addblock(root, { "Xbox360", "SharedLib" })
configset.addvalue(root, "targetprefix", "")
configset.addvalue(root, "targetextension", ".dll")
configset.addvalue(root, "implibextension", ".lib")
configset.addblock(root, { "Xbox360", "StaticLib" })
configset.addvalue(root, "targetprefix", "")
configset.addvalue(root, "targetextension", ".lib")
configuration { "Xbox360", "StaticLib" }
targetprefix ""
targetextension ".lib"
--
-- .NET languages always use Windows-style naming.
--
configset.addblock(root, { "C#", "ConsoleApp" })
configset.addvalue(root, "targetextension", ".exe")
configuration { "C#", "ConsoleApp" }
targetextension ".exe"
configset.addblock(root, { "C#", "WindowedApp" })
configset.addvalue(root, "targetextension", ".exe")
configuration { "C#", "WindowedApp" }
targetextension ".exe"
configset.addblock(root, { "C#", "SharedLib" })
configset.addvalue(root, "targetprefix", "")
configset.addvalue(root, "targetextension", ".dll")
configuration { "C#", "SharedLib" }
targetprefix ""
targetextension ".dll"

View File

@ -6,6 +6,7 @@
premake.api = {}
local api = premake.api
local configset = premake.configset
--
@ -84,10 +85,18 @@
else
target = api.scope.configuration
end
if not target then
error({ msg="no " .. scope .. " in scope" })
end
-- WORK IN PROGRESS: I am moving everything toward the new config
-- set objects, which means that it will no longer be possible to
-- ever be completely out of scope.
--
-- TODO: Get rid of this function and use the active config set
-- in api.scope instead.
--
-- In the meantime, return a dummy container for the accessor while
-- I get things ported.
target = target or {}
return target
end
@ -382,6 +391,14 @@
local value, err = api.checkvalue(value, field.allowed, field.aliases)
if err then error({ msg=err }) end
-- NEW APPROACH:
-- TODO: receive config set directly instead of going through target
local cset = target.configset or configset.root
configset.addvalue(cset, name, value)
-- OLD APPROACH:
-- TODO: phase this out ASAP
target[name] = value
end
@ -1189,15 +1206,25 @@
if not terms then
return premake.CurrentConfiguration
end
-- NEW APPROACH: Create a new block in the current config set
-- TODO: Fetch the current config set from api.scope instead
local container = api.scope.project or api.scope.solution or {}
local cset = container.configset or configset.root
configset.addblock(cset, terms)
-- OLD APPROACH:
-- TODO: Phase this out ASAP
local container, err = premake.getobject("container")
if (not container) then
error(err, 2)
-- error(err, 2)
return
end
local cfg = { }
cfg.terms = table.flatten({terms})
cfg.basedir = os.getcwd()
cfg.configset = container.configset
table.insert(container.blocks, cfg)
premake.CurrentConfiguration = cfg
@ -1219,17 +1246,12 @@
-- this is the new place for storing scoped objects
api.scope.configuration = cfg
return cfg
end
local function createproject(name, sln, isUsage)
local prj = {}
-- attach a type
setmetatable(prj, {
__type = "project",
})
local prj = premake5.project.new(sln, name)
-- add to master list keyed by both name and index
table.insert(sln.projects, prj)
@ -1253,14 +1275,8 @@
sln.projects[name] = prj
end
prj.solution = sln
prj.name = name
prj.filename = name
prj.basedir = os.getcwd()
prj.script = _SCRIPT
prj.uuid = os.uuid()
prj.blocks = { }
prj.usage = isUsage;
prj.script = _SCRIPT
prj.usage = isUsage;
return prj;
end
@ -1326,7 +1342,7 @@
end
-- add an empty, global configuration to the project
configuration { }
configuration {}
-- this is the new place for storing scoped objects
api.scope.project = premake.CurrentContainer
@ -1347,7 +1363,6 @@
premake.CurrentContainer = premake.solution.get(name)
if (not premake.CurrentContainer) then
local sln = premake.solution.new(name)
sln.filename = name
premake.CurrentContainer = sln
end

View File

@ -23,10 +23,17 @@
--
-- Create a new configuration set.
--
-- @param parent
-- An optional parent configuration set. If provided, the parent provides
-- a base configuration, which this set will extend.
-- @return
-- A new, empty configuration set.
--
function configset.new()
function configset.new(parent)
local cfgset = {}
cfgset.parent = parent
cfgset.blocks = {}
configset.addblock(cfgset, {})
return cfgset
@ -50,7 +57,7 @@
local block = {}
-- convert terms to a simple, all-lower-case array
terms = table.flatten(terms)
terms = table.flatten({ terms })
for i, term in ipairs(terms) do
terms[i] = term:lower()
end
@ -98,7 +105,7 @@
--
function configset.fetchvalue(cfgset, fieldname, context)
local value = ""
local value = nil
for _, block in ipairs(cfgset.blocks) do
if criteria.matches(block.terms, context) then

View File

@ -41,11 +41,15 @@
end
ctx.terms = terms
-- attach field lookup metatable
-- when a missing field is requested, fetch it from my config
-- set, and then cache the value for future lookups
setmetatable(ctx, {
__index = function(ctx, key)
ctx[key] = configset.fetchvalue(cfgset, key, terms)
return ctx[key]
local value = configset.fetchvalue(cfgset, key, terms)
if value then
ctx[key] = value
end
return value
end
})

View File

@ -8,6 +8,7 @@
local solution = premake.solution
local oven = premake5.oven
local project = premake5.project
local configset = premake.configset
-- The list of defined solutions (which contain projects, etc.)
@ -20,10 +21,12 @@
--
-- @param name
-- The new solution's name.
-- @return
-- A new solution object.
--
function solution.new(name)
local sln = { }
local sln = {}
-- add to master list keyed by both name and index
table.insert(premake.solution.list, sln)
@ -32,16 +35,20 @@
-- attach a type descriptor
setmetatable(sln, { __type="solution" })
sln.name = name
sln.basedir = os.getcwd()
sln.projects = { }
sln.blocks = { }
sln.configurations = { }
sln.name = name
sln.basedir = os.getcwd()
sln.configset = configset.new(configset.root)
sln.filename = name
sln.projects = {}
sln.blocks = {}
sln.configurations = {}
return sln
end
--
-- Creates a new project, which the given
--
-- Iterates through all of the current solutions, bakes down their contents,
-- and then replaces the original solution object with this baked result.

View File

@ -58,8 +58,8 @@
local bundlename = ""
local bundlepath = ""
local suffix = ""
local prefix = cfg.context[field.."prefix"]
local extension = cfg.context[field.."extension"]
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

View File

@ -8,6 +8,36 @@
local project = premake5.project
local context = premake.context
local oven = premake5.oven
local configset = premake.configset
--
-- Create a new project object.
--
-- @param sln
-- The solution object to contain the new project.
-- @param name
-- The new project's name.
-- @return
-- A new project object, contained by the specified solution.
--
function project.new(sln, name)
local prj = {}
-- attach a type descriptor
setmetatable(prj, { __type="project" })
prj.name = name
prj.basedir = os.getcwd()
prj.solution = sln
prj.configset = configset.new(sln.configset)
prj.filename = name
prj.uuid = os.uuid()
prj.blocks = {}
return prj
end
--
@ -96,7 +126,7 @@
table.insert(terms, v)
end
end
cfg.context = context.new(premake.root, terms)
cfg.context = context.new(premake.configset.root, terms)
-- fill in any calculated values
premake5.config.bake(cfg)

View File

@ -83,34 +83,6 @@
end
--
-- If the field scope is "project", and there is no active solution
-- or project, an error should be raised.
--
function suite.errorRaised_onProjectScopeWithNoProject()
api.register { name = "testapi", kind = "test", scope = "project" }
ok, err = pcall(function ()
testapi "test"
end)
test.isfalse(ok)
end
--
-- If the field scope is "configuration" and there is no active configuration,
-- an error should be raised.
--
function suite.errorRaised_onConfigScopeWithNoConfig()
api.register { name = "testapi", kind = "test", scope = "configuration" }
ok, err = pcall(function ()
testapi "test"
end)
test.isfalse(ok)
end
--
-- If the field scope is "project" and there is an active solution, but not an
-- active project, the solution should be the target.

View File

@ -240,13 +240,6 @@
--
-- configuration() tests
--
function suite.configuration_RaisesError_OnNoContainer()
premake.CurrentContainer = nil
local fn = function() configuration{"Debug"} end
ok, err = pcall(fn)
test.isfalse(ok)
end
function suite.configuration_SetsCurrentConfiguration_OnKeywords()
local cfg = configuration {"Debug"}

View File

@ -35,7 +35,7 @@
--
function suite.defaultValue_onString()
test.isequal("", configset.fetchvalue(cfgset, "targetextension", {}))
test.isnil(configset.fetchvalue(cfgset, "targetextension", {}))
end