Merge project objects with their underlying configuration sets

This commit is contained in:
Jason Perkins 2014-03-13 17:08:04 -04:00
parent 49ceccd53f
commit 5ef13aa5b6
7 changed files with 35 additions and 88 deletions

View File

@ -9,14 +9,6 @@
local configset = premake.configset
--
-- A place to store the current active objects in each configuration scope
-- (e.g. solutions, projects, groups, and configurations).
--
api.scope = {}
--
-- Create a "root" configuration set, to hold the global configuration. Values
-- that are added to this set become available for all add-ons, solution, projects,
@ -27,6 +19,14 @@
local root = configset.root
--
-- A place to store the current active objects in each configuration scope
-- (e.g. solutions, projects, groups, and configurations).
--
api.scope = { root = configset.root }
---
-- Register a new API function. See the built-in API definitions in
-- _premake_init.lua for lots of usage examples.
@ -242,14 +242,7 @@
--
function api.gettarget(scope)
local target
if scope == "project" then
target = api.scope.project or api.scope.solution or api.scope.root
else
target = api.scope.configuration or api.scope.root
end
return target
return api.scope.project or api.scope.solution or api.scope.root
end
@ -268,12 +261,11 @@
end
local target = api.gettarget(field.scope)
if not value then
return configset.fetch(target.configset, field)
return configset.fetch(target, field)
end
local status, err = configset.store(target.configset, field, value)
local status, err = configset.store(target, field, value)
if err then
error(result, 3)
end
@ -321,7 +313,7 @@
table.foreachi(value, recurse)
elseif hasDeprecatedValues and value:contains("*") then
local current = configset.fetch(target.configset, field)
local current = configset.fetch(target, field)
local mask = path.wildcards(value)
for _, item in ipairs(current) do
if item:match(mask) == item then
@ -348,7 +340,7 @@
end
recurse(value)
configset.remove(target.configset, field, removes)
configset.remove(target, field, removes)
end
@ -423,22 +415,6 @@
--
-- Clears all active API objects; resets to root configuration block.
--
function api.reset()
api.scope = {
root = {
configset = configset.root,
blocks = {} -- TODO: remove this when switch-over to new APIs is done
}
}
end
api.reset()
--
-- Directory data kind; performs wildcard directory searches, converts
-- results to absolute paths.
@ -719,20 +695,13 @@
--
function configuration(terms)
if not terms then
return api.scope.configuration
local target = api.gettarget()
if terms then
if terms == "*" then terms = nil end
configset.addblock(target, {terms}, os.getcwd())
end
if terms == "*" then terms = nil end
local container = api.scope.project or api.scope.solution or api.scope.root
configset.addblock(container.configset, {terms}, os.getcwd())
local cfg = {}
cfg.configset = container.configset
api.scope.configuration = cfg
return cfg
return target
end

View File

@ -1,7 +1,7 @@
--
-- fileconfig.lua
-- The set of configuration information for a specific file.
-- Copyright (c) 2011-2013 Jason Perkins and the Premake project
-- Copyright (c) 2011-2014 Jason Perkins and the Premake project
--
premake.fileconfig = {}
@ -76,13 +76,14 @@
--
function fileconfig.addconfig(fcfg, cfg)
local prj = cfg.project
-- Create a new context object for this configuration-file pairing.
-- The context has the ability to pull out configuration settings
-- specific to the file.
local environ = {}
local fsub = context.new(cfg.project.configset, environ, fcfg.abspath)
local fsub = context.new(prj, environ, fcfg.abspath)
context.copyterms(fsub, cfg)
fcfg.configs[cfg] = fsub
@ -105,14 +106,14 @@
fsub.abspath = fcfg.abspath
fsub.vpath = fcfg.vpath
fsub.config = cfg
fsub.project = cfg.project
fsub.project = prj
-- Set the context's base directory to the project's file system
-- location. Any path tokens which are expanded in non-path fields
-- (such as the custom build commands) will be made relative to
-- this path, ensuring a portable generated project.
context.basedir(fsub, cfg.project.location)
context.basedir(fsub, prj.location)
setmetatable(fsub, fileconfig.fsub_mt)

View File

@ -6,7 +6,7 @@
-- and actions. Fills in computed values (e.g. object directories) and
-- optimizes the layout of the data for faster fetches.
--
-- Copyright (c) 2002-2013 Jason Perkins and the Premake project
-- Copyright (c) 2002-2014 Jason Perkins and the Premake project
--
premake.oven = {}
@ -58,8 +58,7 @@
sln = sln,
}
local ctx = context.new(sln.configset, environ)
local ctx = context.new(sln, environ)
ctx.name = sln.name
ctx.baked = true
@ -139,7 +138,7 @@
-- Use an empty token expansion environment for the moment.
local environ = {}
local ctx = context.new(prj.configset, environ)
local ctx = context.new(prj, environ)
-- Add filtering terms to the context to make it as specific as I can.
-- Start with the same filtering that was applied at the solution level.
@ -191,7 +190,7 @@
-- This works, but it could probably be simplified.
local cfgs = table.fold(ctx.configurations or {}, ctx.platforms or {})
oven.bakeConfigMap(ctx, prj.configset, cfgs)
oven.bakeConfigMap(ctx, prj, cfgs)
ctx._cfglist = oven.bakeConfigList(ctx, cfgs)
-- Don't allow a project-level system setting to influence the configurations
@ -443,7 +442,7 @@
prj = prj,
}
local ctx = context.new(prj.configset, environ)
local ctx = context.new(prj, environ)
ctx.project = prj
ctx.solution = prj.solution

View File

@ -1,7 +1,7 @@
--
-- project.lua
-- Premake project object API
-- Copyright (c) 2011-2013 Jason Perkins and the Premake project
-- Copyright (c) 2011-2014 Jason Perkins and the Premake project
--
premake.project = {}
@ -23,22 +23,12 @@
--
function project.new(sln, name)
local prj = {}
local prj = configset.new(sln)
setmetatable(prj, configset.metatable(prj))
prj.name = name
prj.solution = sln
prj.script = _SCRIPT
-- Start a new configuration set to hold this project's info. For
-- convenience and backward compatibility with the old Premake 3.x
-- way of doing things, allow the project to be treated like a
-- regular table.
local cset = configset.new(sln.configset)
prj.configset = cset
setmetatable(prj, configset.metatable(cset))
-- And set defaults for some of the fields
prj.basedir = os.getcwd()
prj.filename = name
prj.uuid = os.uuid(name)

View File

@ -27,21 +27,11 @@
--
function solution.new(name)
local sln = {}
sln = configset.new(configset.root)
setmetatable(sln, configset.metatable(sln))
sln.name = name
sln.projects = {}
-- Start a new configuration set to hold this project's info. For
-- convenience and backward compatibility with the old Premake 3.x
-- way of doing things, allow the solution to be treated like a
-- regular table.
local cset = configset.new(configset.root)
sln.configset = cset
setmetatable(sln, configset.metatable(cset))
-- Set defaults for some of the fields
sln.basedir = os.getcwd()
sln.filename = name

View File

@ -1,11 +1,10 @@
--
-- tests/base/test_configset.lua
-- Test suite for the configset API.
-- Copyright (c) 2012 Jason Perkins and the Premake project
-- Copyright (c) 2012-2014 Jason Perkins and the Premake project
--
T.configset = {}
local suite = T.configset
local suite = test.declare("configset")
local configset = premake.configset
local field = premake.field

View File

@ -284,7 +284,6 @@
stderr_capture = nil
premake.solution.list = { }
premake.api.reset()
premake.clearWarnings()
premake.eol("\n")
premake.escaper(nil)