Visual Studio solutions now use the same project ordering in all sections; avoids unnecessary changes if the solution is later changed within Visual Studio

This commit is contained in:
Jason Perkins 2013-01-08 13:19:56 -05:00
parent a69b7501e7
commit 89d413d9d5
3 changed files with 51 additions and 47 deletions

View File

@ -18,7 +18,7 @@
function sln2005.generate_ng(sln) function sln2005.generate_ng(sln)
io.eol = '\r\n' io.eol = '\r\n'
-- Mark the file as Unicode -- Mark the file as Unicode
_p('\239\187\191') _p('\239\187\191')
@ -38,10 +38,10 @@
-- --
function sln2005.header(sln) function sln2005.header(sln)
local version = { local version = {
vs2005 = 9, vs2005 = 9,
vs2008 = 10, vs2008 = 10,
vs2010 = 11, vs2010 = 11,
vs2012 = 12, vs2012 = 12,
} }
_p('Microsoft Visual Studio Solution File, Format Version %d.00', version[_ACTION]) _p('Microsoft Visual Studio Solution File, Format Version %d.00', version[_ACTION])
@ -63,18 +63,18 @@
local slnpath = premake.solution.getlocation(prj.solution) local slnpath = premake.solution.getlocation(prj.solution)
local prjpath = vstudio.projectfile(prj) local prjpath = vstudio.projectfile(prj)
prjpath = path.translate(path.getrelative(slnpath, prjpath)) prjpath = path.translate(path.getrelative(slnpath, prjpath))
_x('Project("{%s}") = "%s", "%s", "{%s}"', vstudio.tool(prj), prj.name, prjpath, prj.uuid) _x('Project("{%s}") = "%s", "%s", "{%s}"', vstudio.tool(prj), prj.name, prjpath, prj.uuid)
if _ACTION < "vs2012" then if _ACTION < "vs2012" then
sln2005.projectdependencies_ng(prj) sln2005.projectdependencies_ng(prj)
end end
_p('EndProject') _p('EndProject')
end, end,
onbranch = function(n) onbranch = function(n)
_x('Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "%s", "%s", "{%s}"', n.name, n.name, n.uuid) _x('Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "%s", "%s", "{%s}"', n.name, n.name, n.uuid)
_p('EndProject') _p('EndProject')
end, end,
}) })
end end
@ -106,7 +106,7 @@
local platform = vstudio.solutionPlatform(cfg) local platform = vstudio.solutionPlatform(cfg)
slncfg[cfg] = string.format("%s|%s", cfg.buildcfg, platform) slncfg[cfg] = string.format("%s|%s", cfg.buildcfg, platform)
end end
_p(1,'GlobalSection(SolutionConfigurationPlatforms) = preSolution') _p(1,'GlobalSection(SolutionConfigurationPlatforms) = preSolution')
for cfg in solution.eachconfig(sln) do for cfg in solution.eachconfig(sln) do
_p(2,'%s = %s', slncfg[cfg], slncfg[cfg]) _p(2,'%s = %s', slncfg[cfg], slncfg[cfg])
@ -114,19 +114,24 @@
_p(1,'EndGlobalSection') _p(1,'EndGlobalSection')
_p(1,'GlobalSection(ProjectConfigurationPlatforms) = postSolution') _p(1,'GlobalSection(ProjectConfigurationPlatforms) = postSolution')
for prj in solution.eachproject_ng(sln) do local tr = solution.grouptree(sln)
for cfg in solution.eachconfig(sln) do tree.traverse(tr, {
local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform) onleaf = function(n)
if prjcfg then local prj = n.project
local prjplatform = vstudio.projectPlatform(prjcfg)
local architecture = vstudio.archFromConfig(prjcfg, true) for cfg in solution.eachconfig(sln) do
local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform)
_p(2,'{%s}.%s.ActiveCfg = %s|%s', prj.uuid, slncfg[cfg], prjplatform, architecture) if prjcfg then
_p(2,'{%s}.%s.Build.0 = %s|%s', prj.uuid, slncfg[cfg], prjplatform, architecture) local prjplatform = vstudio.projectPlatform(prjcfg)
local architecture = vstudio.archFromConfig(prjcfg, true)
_p(2,'{%s}.%s.ActiveCfg = %s|%s', prj.uuid, slncfg[cfg], prjplatform, architecture)
_p(2,'{%s}.%s.Build.0 = %s|%s', prj.uuid, slncfg[cfg], prjplatform, architecture)
end
end end
end end
end })
_p(1,'EndGlobalSection') _p(1,'EndGlobalSection')
end end
@ -134,7 +139,7 @@
-- Write out contents of the SolutionProperties section; currently unused. -- Write out contents of the SolutionProperties section; currently unused.
-- --
function sln2005.properties(sln) function sln2005.properties(sln)
_p('\tGlobalSection(SolutionProperties) = preSolution') _p('\tGlobalSection(SolutionProperties) = preSolution')
_p('\t\tHideSolutionNode = FALSE') _p('\t\tHideSolutionNode = FALSE')
_p('\tEndGlobalSection') _p('\tEndGlobalSection')

View File

@ -97,14 +97,14 @@
context.compile(ctx) context.compile(ctx)
-- TODO: OLD, REMOVE: build an old-style configuration to wrap context, for now -- TODO: OLD, REMOVE: build an old-style configuration to wrap context, for now
local result = oven.merge({}, sln) local result = oven.merge({}, sln)
result.baked = true result.baked = true
result.blocks = sln.blocks result.blocks = sln.blocks
-- TODO: HACK, TRANSITIONAL, REMOVE: pass requests for missing values -- TODO: HACK, TRANSITIONAL, REMOVE: pass requests for missing values
-- through to the config context. Eventually all values will be in the -- through to the config context. Eventually all values will be in the
-- context and the cfg wrapper can be done away with -- context and the cfg wrapper can be done away with
result.context = ctx result.context = ctx
sln.context = ctx sln.context = ctx
@ -115,8 +115,8 @@
end, end,
}) })
setmetatable(sln, getmetatable(result)) setmetatable(sln, getmetatable(result))
-- bake all of the projects in the list, and store that result -- bake all of the projects in the list, and store that result
local projects = {} local projects = {}
for i, prj in ipairs(sln.projects) do for i, prj in ipairs(sln.projects) do
@ -124,10 +124,10 @@
projects[prj.name] = projects[i] projects[prj.name] = projects[i]
end end
result.projects = projects result.projects = projects
-- assign unique object directories to every project configurations -- assign unique object directories to every project configurations
solution.bakeobjdirs(result) solution.bakeobjdirs(result)
-- expand all tokens contained by the solution -- expand all tokens contained by the solution
for prj in solution.eachproject_ng(result) do for prj in solution.eachproject_ng(result) do
oven.expandtokens(prj, "project") oven.expandtokens(prj, "project")
@ -151,7 +151,7 @@
function solution.bakeconfigs(sln) function solution.bakeconfigs(sln)
local buildcfgs = sln.configurations or {} local buildcfgs = sln.configurations or {}
local platforms = sln.platforms or {} local platforms = sln.platforms or {}
local configs = {} local configs = {}
for _, buildcfg in ipairs(buildcfgs) do for _, buildcfg in ipairs(buildcfgs) do
if #platforms > 0 then if #platforms > 0 then
@ -168,7 +168,7 @@
cfg.solution = sln cfg.solution = sln
premake5.config.bake(cfg) premake5.config.bake(cfg)
end end
return configs return configs
end end
@ -176,7 +176,7 @@
-- --
-- Assigns a unique objects directory to every configuration of every project -- Assigns a unique objects directory to every configuration of every project
-- in the solution, taking any objdir settings into account, to ensure builds -- in the solution, taking any objdir settings into account, to ensure builds
-- from different configurations won't step on each others' object files. -- from different configurations won't step on each others' object files.
-- The path is built from these choices, in order: -- The path is built from these choices, in order:
-- --
-- [1] -> the objects directory as set in the config -- [1] -> the objects directory as set in the config
@ -189,21 +189,21 @@
-- function to compute the four options for a specific configuration -- function to compute the four options for a specific configuration
local function getobjdirs(cfg) local function getobjdirs(cfg)
local dirs = {} local dirs = {}
local dir = path.getabsolute(path.join(project.getlocation(cfg.project), cfg.objdir or "obj")) local dir = path.getabsolute(path.join(project.getlocation(cfg.project), cfg.objdir or "obj"))
table.insert(dirs, dir) table.insert(dirs, dir)
if cfg.platform then if cfg.platform then
dir = path.join(dir, cfg.platform) dir = path.join(dir, cfg.platform)
table.insert(dirs, dir) table.insert(dirs, dir)
end end
dir = path.join(dir, cfg.buildcfg) dir = path.join(dir, cfg.buildcfg)
table.insert(dirs, dir) table.insert(dirs, dir)
dir = path.join(dir, cfg.project.name) dir = path.join(dir, cfg.project.name)
table.insert(dirs, dir) table.insert(dirs, dir)
return dirs return dirs
end end
@ -211,16 +211,16 @@
-- times each obj dir gets used -- times each obj dir gets used
local counts = {} local counts = {}
local configs = {} local configs = {}
for prj in premake.solution.eachproject_ng(sln) do for prj in premake.solution.eachproject_ng(sln) do
for cfg in project.eachconfig(prj) do for cfg in project.eachconfig(prj) do
-- expand any tokens contained in the field -- expand any tokens contained in the field
oven.expandtokens(cfg, "config", nil, "objdir") oven.expandtokens(cfg, "config", nil, "objdir")
-- get the dirs for this config, and remember the association -- get the dirs for this config, and remember the association
local dirs = getobjdirs(cfg) local dirs = getobjdirs(cfg)
configs[cfg] = dirs configs[cfg] = dirs
for _, dir in ipairs(dirs) do for _, dir in ipairs(dirs) do
counts[dir] = (counts[dir] or 0) + 1 counts[dir] = (counts[dir] or 0) + 1
end end
@ -231,7 +231,7 @@
for cfg, dirs in pairs(configs) do for cfg, dirs in pairs(configs) do
for _, dir in ipairs(dirs) do for _, dir in ipairs(dirs) do
if counts[dir] == 1 then if counts[dir] == 1 then
cfg.objdir = dir cfg.objdir = dir
break break
end end
end end
@ -390,7 +390,7 @@
if sln.grouptree then if sln.grouptree then
return sln.grouptree return sln.grouptree
end end
local tr = tree.new() local tr = tree.new()
sln.grouptree = tr sln.grouptree = tr
@ -400,7 +400,6 @@
node.project = prj node.project = prj
end end
tree.sort(tr)
return tr return tr
end end
@ -436,7 +435,7 @@
-- the global (not configuration specific) settings collapsed -- the global (not configuration specific) settings collapsed
local prj = sln.projects[idx] local prj = sln.projects[idx]
local cfg = premake.getconfig(prj) local cfg = premake.getconfig(prj)
-- root configuration doesn't have a name; use the project's -- root configuration doesn't have a name; use the project's
cfg.name = prj.name cfg.name = prj.name
return cfg return cfg
@ -491,7 +490,7 @@
-- @param sln -- @param sln
-- The solution to query. -- The solution to query.
-- @return -- @return
-- True if at least one project in the solution uses a -- True if at least one project in the solution uses a
-- .NET language -- .NET language
-- --

View File

@ -10,17 +10,17 @@
-- --
-- Setup -- Setup
-- --
local sln local sln
function suite.setup() function suite.setup()
_ACTION = "vs2008" _ACTION = "vs2008"
sln = solution "MySolution" sln = solution "MySolution"
configurations { "Debug", "Release" } configurations { "Debug", "Release" }
end end
local function prepare() local function prepare()
sln2005.projects(sln) sln2005.projects(sln)
end end