Configurations are now cached before action is called; performance

This commit is contained in:
Jason Perkins 2012-02-03 16:03:46 -05:00
parent 10f0798789
commit c9786f2242
7 changed files with 62 additions and 14 deletions

View File

@ -146,6 +146,10 @@
ok, err = premake.checkprojects()
if (not ok) then error("Error: " .. err, 0) end
else
for sln in premake.solution.each() do
premake.solution.bakeprojects(sln)
end
end

View File

@ -7,6 +7,7 @@
premake.vstudio.sln2005 = { }
local vstudio = premake.vstudio
local sln2005 = premake.vstudio.sln2005
local solution = premake.solution
local project = premake5.project
@ -87,7 +88,7 @@
function sln2005.solutionConfigurationPlatforms(sln)
-- eachconfig() requires a project object; any one will do
local prj = sln.projects[1]
local prj = solution.getproject_ng(sln, 1)
_p(1,'GlobalSection(SolutionConfigurationPlatforms) = preSolution')
for cfg in project.eachconfig(prj) do
@ -105,7 +106,7 @@
function sln2005.projectConfigurationPlatforms(sln)
_p(1,'GlobalSection(ProjectConfigurationPlatforms) = postSolution')
for _, prj in ipairs(sln.projects) do
for prj in solution.eachproject_ng(sln) do
for cfg in project.eachconfig(prj) do
local slnplatform = vstudio.platform(cfg)
local prjplatform = vstudio.projectplatform(cfg)

View File

@ -740,7 +740,7 @@
end
depth = depth + 1
for cfg in project.eachconfig(prj, nil, node.cfg.fullpath) do
for cfg in project.eachconfig(prj) do
local hasconfig
local out = function(depth, msg, ...)

View File

@ -398,7 +398,7 @@
_p(1,'<ItemGroup>')
for _, file in ipairs(files) do
_x(2,'<ClCompile Include=\"%s\">', path.translate(file.fullpath))
for cfg in project.eachconfig(prj, nil, file.fullpath) do
for cfg in project.eachconfig(prj) do
if pchsource == file.fullpath and not cfg.flags.NoPCH then
_p(3,'<PrecompiledHeader %s>Create</PrecompiledHeader>', vc2010.condition(cfg))
end

View File

@ -41,6 +41,21 @@
end
--
-- Flattens the configurations of each of the projects in the solution
-- and stores the results, which are then returned from subsequent
-- calls to getproject().
--
function solution.bakeprojects(sln)
for i = 1, #sln.projects do
local prj = solution.getproject_ng(sln, i)
sln.projects[i].rootcfg = prj
project.bakeconfigs(prj)
end
end
--
-- Iterate over the collection of solutions in a session.
--
@ -72,7 +87,7 @@
local i = 0
return function ()
i = i + 1
if (i <= #sln.projects) then
if i <= #sln.projects then
return premake.solution.getproject(sln, i)
end
end
@ -92,7 +107,7 @@
local i = 0
return function ()
i = i + 1
if (i <= #sln.projects) then
if i <= #sln.projects then
return premake.solution.getproject_ng(sln, i)
end
end
@ -185,9 +200,14 @@
function solution.getproject_ng(sln, idx)
local prj = sln.projects[idx]
if prj.rootcfg then
-- cached version build by solution.bakeprojects()
return prj.rootcfg
else
-- "raw" version, accessible during scripting
local cfg = oven.merge({}, sln)
cfg = oven.merge(cfg, prj)
cfg = oven.merge(cfg, project.getconfig(prj))
return cfg
end
end

View File

@ -333,7 +333,7 @@
-- times each obj dir gets used
local counts = {}
for sln in premake.solution.each() do
for _, prj in ipairs(sln.projects) do
for prj in premake.solution.eachproject_ng(sln) do
for testcfg in project.eachconfig(prj, "objdir") do
local dirs = getobjdirs(testcfg)
for _, dir in ipairs(dirs) do

View File

@ -8,6 +8,23 @@
local project = premake5.project
--
-- Flattens the configurations of each of the configurations in the project
-- and stores the results, which are then returned from subsequent calls
-- to getconfig().
--
function project.bakeconfigs(prj)
local configs = {}
configs["*"] = project.getconfig(prj)
for cfg in project.eachconfig(prj) do
local key = cfg.buildcfg .. (cfg.platform or "")
configs[key] = cfg
end
prj.configs = configs
end
--
-- Returns an iterator function for the configuration objects contained by
-- the project. Each configuration corresponds to a build configuration/
@ -64,7 +81,7 @@
--
function project.eachfile(prj)
cfg = project.getconfig(prj, nil, nil, "files")
local cfg = project.getconfig(prj, nil, nil, "files")
local files = cfg.files
local i = 0
return function()
@ -127,6 +144,12 @@
--
function project.getconfig(prj, buildcfg, platform, field, filename)
-- check for a cached version, build by bakeconfigs()
if not filename and prj.configs then
local key = (buildcfg or "*") .. (platform or "")
return prj.configs[key]
end
local system
local architecture