1. Jason McKesson
  2. premake for usage

Commits

Jason Perkins  committed bab8003

Removed deprecated file configuration object; now uses context object directly

  • Participants
  • Parent commits 2fc425d
  • Branches default

Comments (0)

Files changed (6)

File src/actions/vstudio/vs200x_vcproj.lua

View file
 	local vstudio = premake.vstudio
 	local vc200x = premake.vstudio.vc200x
 	local config = premake5.config
+	local context = premake.context
 	local project = premake5.project
 	local tree = premake.tree
 
 			
 			-- if there is a file configuration, see if it contains any values
 			-- (will be empty if it matches the project config)
-			local hasSettings = (filecfg ~= nil and filecfg.terms ~= nil)
+			local hasSettings = (filecfg ~= nil and not context.empty(filecfg))
 			
 			-- check to see if this is the PCH source file
 			local isPchSource = (cfg.pchsource == node.abspath and not cfg.flags.NoPCH)

File src/base/configset.lua

View file
 
 	function configset.new(parent)
 		local cset = {}
-		cset._parent = parent or cset
+		cset._parent = parent or false
 		cset._blocks = {}
-		
-		-- set always starts with a single, global block
-		configset.addblock(cset, {})
+		cset._current = false
+		cset.compiled = false
 
 		-- enable config sets to be treat like plain old tables; storing
 		-- a value will place it into the current block
 		configset._fields[name] = behavior
 	end
 
-
+	
 --
 -- Create a new block of configuration field-value pairs, with the provided
 -- set of context terms to control their application.
 --
 
 	function configset.addvalue(cset, fieldname, value)
+		-- make sure there is an active block
+		if not cset._current then
+			configset.addblock(cset, {})
+		end
+
 		local current = cset._current
 		local field = configset._fields[fieldname]
 		if field and (field.keyed or field.merge) then
 
 
 --
+-- Check to see if a configuration set is empty; that is, it does
+-- not contain any configuration blocks.
+--
+-- @param cset
+--    The configuration set to query.
+-- @return
+--    True if the set does not contain any blocks.
+--
+
+	function configset.empty(cset)
+		return (#cset._blocks == 0)
+	end
+
+
+--
 -- Check to see if an individual configuration block applies to the
 -- given context and filename.
 --
 
 
 --
+-- Compiles a new configuration set containing only the blocks which match
+-- the specified criteria. Fetches against this compiled configuration set
+-- may omit the context argument, resulting in faster fetches against a
+-- smaller set of configuration blocks.
+--
+-- @param cset
+--    The configuration set to query.
+-- @param context
+--    A list of lowercase context terms to use during the fetch. Only those 
+--    blocks with terms fully contained by this list will be considered in 
+--    determining the returned value. Terms should be lower case to make
+--    the context filtering case-insensitive.
+-- @param filename
+--    An optional filename; if provided, only blocks with pattern that
+--    matches the name will be considered.
+-- @return
+--    A new configuration set containing only the selected blocks, and the
+--    "compiled" field set to true.
+--
+
+	function configset.compile(cset, context, filename)
+		-- always start with the parent
+		local result
+		if cset._parent then
+			result = configset.compile(cset._parent, context, filename)
+		else
+			result = configset.new()
+		end
+
+		-- add in my own blocks
+		for _, block in ipairs(cset._blocks) do
+			if testblock(block, context, filename) then
+				table.insert(result._blocks, block)
+			end
+		end
+		
+		result.compiled = true
+		return result
+	end
+
+
+--
 -- Merges two lists of values together. The merged list is both indexed
 -- and keyed for faster lookups. If duplicate values are encountered,
 -- the earlier value is removed.
 		local n = #cset._blocks
 		for i = n, 1, -1 do
 			local block = cset._blocks[i]
-			if block[fieldname] and testblock(block, context, filename) then
+			if block[fieldname] and (cset.compiled or testblock(block, context, filename)) then
 				return block[fieldname]
 			end
 		end
 		
-		if cset._parent ~= cset then
+		if cset._parent then
 			return fetchassign(cset._parent, fieldname, context, filename)
 		end
 	end
 		local result = {}
 
 		-- grab values from the parent set first
-		if cset._parent ~= cset then
+		if cset._parent then
 			result = fetchkeyed(cset._parent, fieldname, context, filename, merge)
 		end
 		
 		end
 
 		for _, block in ipairs(cset._blocks) do
-			if testblock(block, context, filename) then
+			if cset.compiled or testblock(block, context, filename) then
 				local value = block[fieldname]
 				if value then
 					process(value)
 		local result = {}
 
 		-- grab values from the parent set first
-		if cset._parent ~= cset then
+		if cset._parent then
 			result = fetchmerge(cset._parent, fieldname, context, filename)
 		end
 
 		end
 
 		for _, block in ipairs(cset._blocks) do
-			if testblock(block, context, filename) then
+			if cset.compiled or testblock(block, context, filename) then
 				if block._removes and block._removes[fieldname] then
 					remove(block._removes[fieldname])
 				end

File src/base/context.lua

View file
 
 
 --
+-- Compiles the context for better performance. The list of context terms
+-- becomes locked down; any subsequent changes are ignored.
+--
+-- @param ctx
+--    The context to compile.
+--
+
+	function context.compile(ctx)
+		ctx._cfgset = configset.compile(ctx._cfgset, ctx._terms, ctx._filename[1])
+	end
+
+
+--
+-- Check to see if a context's underlying configuration set is empty; that 
+-- is, it does not contain any configuration blocks.
+--
+-- @param ctx
+--    The context to query.
+-- @return
+--    True if the set does not contain any blocks.
+--
+
+	function context.empty(ctx)
+		return configset.empty(ctx._cfgset)
+	end
+
+
+--
 -- Fetch a value from underlying configuration set.
 --
 -- @param ctx

File src/base/solution.lua

View file
 		-- of the filter terms may be nil, so not safe to use a list
 		local ctx = context.new(sln.configset, environ)
 		context.addterms(ctx, _ACTION)
+		context.compile(ctx)
 
 
 		-- TODO: OLD, REMOVE: build an old-style configuration to wrap context, for now 

File src/project/config.lua

View file
 		-- initially this value will be a string (the file name); if so, build
 		-- and replace it with a full file configuration object
 		if type(filecfg) ~= "table" then
-			-- TODO, OLD, REMOVE: This is being replaced by configuration
-			-- contexts; will be removed soon
-			filecfg = oven.bakefile(cfg, filename)
-			
+			-- create context to represent the file's configuration, based on
+			-- the specified project configuration
+			local environ = {}
+			filecfg = context.new(cfg.project.configset, environ, filename)
+			context.copyterms(filecfg, cfg.context)
+
+			-- set up an environment for expanding tokens contained by this file
+			-- configuration; based on the configuration's environment so that
+			-- any magic set up there gets maintained
+			for envkey, envval in pairs(cfg.context.environ) do
+				environ[envkey] = envval
+			end
+			environ.file = filecfg
+
 			-- merge in the file path information (virtual paths, etc.) that are
 			-- computed at the project level, for token expansions to use
 			local prjcfg = project.getfileconfig(cfg.project, filename)
 			for key, value in pairs(prjcfg) do
 				filecfg[key] = value
 			end
-			
-			-- expand inline tokens
-			oven.expandtokens(cfg, "config", filecfg)
+
+			-- finish the setup
+			context.compile(filecfg)
 			
 			-- and cache the result
 			cfg.files[filename] = filecfg
-
-			-- set up an environment for expanding tokens contained by this file
-			-- configuration; based on the configuration's environment so that
-			-- any magic set up there gets maintained
-			local environ = {
-				file = filecfg
-			}
-			for envkey, envval in pairs(cfg.context.environ) do
-				environ[envkey] = envval
-			end
-			
-			-- create a context to provide access to this file's information
-			local ctx = context.new(cfg.project.configset, environ, filename)
-			context.copyterms(ctx, cfg.context)
-			
-			-- TODO: HACK, TRANSITIONAL, REMOVE: pass requests for missing values 
-			-- through to the config context. Eventually all values will be in the 
-			-- context and the cfg wrapper can be done away with
-			filecfg.context = ctx
-			setmetatable(filecfg, {
-				__index = function(filecfg, key)
-					return filecfg.context[key]
-				end,
-			})
-		
 		end
 		
 		return filecfg

File src/project/project.lua

View file
 
 		-- if a kind is specified at the project level, use that too
 		context.addterms(ctx, ctx.kind)
-	
+		context.compile(ctx)
+
 		-- attach a bit more local state
 		ctx.solution = sln
 		
 
 		-- allow configuration to override the project kind
 		context.addterms(ctx, ctx.kind)
+		context.compile(ctx)
 
 		-- attach a bit more local state
 		ctx.project = prj