From 89d413d9d53c9f163d53a11e4f197b24bbba48c0 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Tue, 8 Jan 2013 13:19:56 -0500 Subject: [PATCH] Visual Studio solutions now use the same project ordering in all sections; avoids unnecessary changes if the solution is later changed within Visual Studio --- src/actions/vstudio/vs2005_solution.lua | 47 ++++++++++--------- src/base/solution.lua | 43 +++++++++-------- .../actions/vstudio/sln2005/test_projects.lua | 8 ++-- 3 files changed, 51 insertions(+), 47 deletions(-) diff --git a/src/actions/vstudio/vs2005_solution.lua b/src/actions/vstudio/vs2005_solution.lua index 3c83985c..b7bf9586 100644 --- a/src/actions/vstudio/vs2005_solution.lua +++ b/src/actions/vstudio/vs2005_solution.lua @@ -18,7 +18,7 @@ function sln2005.generate_ng(sln) io.eol = '\r\n' - + -- Mark the file as Unicode _p('\239\187\191') @@ -38,10 +38,10 @@ -- function sln2005.header(sln) - local version = { - vs2005 = 9, - vs2008 = 10, - vs2010 = 11, + local version = { + vs2005 = 9, + vs2008 = 10, + vs2010 = 11, vs2012 = 12, } _p('Microsoft Visual Studio Solution File, Format Version %d.00', version[_ACTION]) @@ -63,18 +63,18 @@ local slnpath = premake.solution.getlocation(prj.solution) local prjpath = vstudio.projectfile(prj) prjpath = path.translate(path.getrelative(slnpath, prjpath)) - + _x('Project("{%s}") = "%s", "%s", "{%s}"', vstudio.tool(prj), prj.name, prjpath, prj.uuid) if _ACTION < "vs2012" then sln2005.projectdependencies_ng(prj) end _p('EndProject') end, - + onbranch = function(n) _x('Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "%s", "%s", "{%s}"', n.name, n.name, n.uuid) _p('EndProject') - end, + end, }) end @@ -106,7 +106,7 @@ local platform = vstudio.solutionPlatform(cfg) slncfg[cfg] = string.format("%s|%s", cfg.buildcfg, platform) end - + _p(1,'GlobalSection(SolutionConfigurationPlatforms) = preSolution') for cfg in solution.eachconfig(sln) do _p(2,'%s = %s', slncfg[cfg], slncfg[cfg]) @@ -114,19 +114,24 @@ _p(1,'EndGlobalSection') _p(1,'GlobalSection(ProjectConfigurationPlatforms) = postSolution') - for prj in solution.eachproject_ng(sln) do - for cfg in solution.eachconfig(sln) do - local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform) - if prjcfg then - 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) + local tr = solution.grouptree(sln) + tree.traverse(tr, { + onleaf = function(n) + local prj = n.project + + for cfg in solution.eachconfig(sln) do + local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform) + if prjcfg then + 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 - _p(1,'EndGlobalSection') + }) + _p(1,'EndGlobalSection') end @@ -134,7 +139,7 @@ -- Write out contents of the SolutionProperties section; currently unused. -- - function sln2005.properties(sln) + function sln2005.properties(sln) _p('\tGlobalSection(SolutionProperties) = preSolution') _p('\t\tHideSolutionNode = FALSE') _p('\tEndGlobalSection') diff --git a/src/base/solution.lua b/src/base/solution.lua index ac0c246b..c0d5f0d2 100644 --- a/src/base/solution.lua +++ b/src/base/solution.lua @@ -97,14 +97,14 @@ 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) result.baked = true result.blocks = sln.blocks - -- TODO: HACK, TRANSITIONAL, REMOVE: pass requests for missing values - -- through to the config context. Eventually all values will be in the + -- 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 result.context = ctx sln.context = ctx @@ -115,8 +115,8 @@ end, }) setmetatable(sln, getmetatable(result)) - - + + -- bake all of the projects in the list, and store that result local projects = {} for i, prj in ipairs(sln.projects) do @@ -124,10 +124,10 @@ projects[prj.name] = projects[i] end result.projects = projects - + -- assign unique object directories to every project configurations solution.bakeobjdirs(result) - + -- expand all tokens contained by the solution for prj in solution.eachproject_ng(result) do oven.expandtokens(prj, "project") @@ -151,7 +151,7 @@ function solution.bakeconfigs(sln) local buildcfgs = sln.configurations or {} local platforms = sln.platforms or {} - + local configs = {} for _, buildcfg in ipairs(buildcfgs) do if #platforms > 0 then @@ -168,7 +168,7 @@ cfg.solution = sln premake5.config.bake(cfg) end - + return configs end @@ -176,7 +176,7 @@ -- -- Assigns a unique objects directory to every configuration of every project -- 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: -- -- [1] -> the objects directory as set in the config @@ -189,21 +189,21 @@ -- function to compute the four options for a specific configuration local function getobjdirs(cfg) local dirs = {} - + local dir = path.getabsolute(path.join(project.getlocation(cfg.project), cfg.objdir or "obj")) table.insert(dirs, dir) - + if cfg.platform then dir = path.join(dir, cfg.platform) table.insert(dirs, dir) end - + dir = path.join(dir, cfg.buildcfg) table.insert(dirs, dir) dir = path.join(dir, cfg.project.name) table.insert(dirs, dir) - + return dirs end @@ -211,16 +211,16 @@ -- times each obj dir gets used local counts = {} local configs = {} - + for prj in premake.solution.eachproject_ng(sln) do for cfg in project.eachconfig(prj) do -- expand any tokens contained in the field oven.expandtokens(cfg, "config", nil, "objdir") - + -- get the dirs for this config, and remember the association local dirs = getobjdirs(cfg) configs[cfg] = dirs - + for _, dir in ipairs(dirs) do counts[dir] = (counts[dir] or 0) + 1 end @@ -231,7 +231,7 @@ for cfg, dirs in pairs(configs) do for _, dir in ipairs(dirs) do if counts[dir] == 1 then - cfg.objdir = dir + cfg.objdir = dir break end end @@ -390,7 +390,7 @@ if sln.grouptree then return sln.grouptree end - + local tr = tree.new() sln.grouptree = tr @@ -400,7 +400,6 @@ node.project = prj end - tree.sort(tr) return tr end @@ -436,7 +435,7 @@ -- the global (not configuration specific) settings collapsed local prj = sln.projects[idx] local cfg = premake.getconfig(prj) - + -- root configuration doesn't have a name; use the project's cfg.name = prj.name return cfg @@ -491,7 +490,7 @@ -- @param sln -- The solution to query. -- @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 -- diff --git a/tests/actions/vstudio/sln2005/test_projects.lua b/tests/actions/vstudio/sln2005/test_projects.lua index 63cf5a7b..78954991 100755 --- a/tests/actions/vstudio/sln2005/test_projects.lua +++ b/tests/actions/vstudio/sln2005/test_projects.lua @@ -10,17 +10,17 @@ -- --- Setup +-- Setup -- local sln - + function suite.setup() _ACTION = "vs2008" sln = solution "MySolution" - configurations { "Debug", "Release" } + configurations { "Debug", "Release" } end - + local function prepare() sln2005.projects(sln) end