Commits

Jason Perkins committed e4689dc

Write ActiveCfg entries for excluded configurations in VS solutions, to avoid rewriting on save

Comments (0)

Files changed (2)

src/actions/vstudio/vs2005_solution.lua

 			slncfg[cfg] = string.format("%s|%s", cfg.buildcfg, platform)
 		end
 
-		-- Make a working list of each solution configuration, and sort it into
-		-- Visual Studio's desired ordering. If I don't this, Visual Studio will
-		-- reshuffle everything on the first save.
+		-- Make a working list of all solution configurations, and sort it into
+		-- Visual Studio's desired ordering. If I don't do this, Visual Studio
+		-- will reshuffle everything on the first save.
 
 		local sorted = {}
 		for cfg in solution.eachconfig(sln) do
 			return slncfg[a]:lower() < slncfg[b]:lower()
 		end)
 
-		-- Now use the sorted list to output the configuration maps.
+		-- Output the list of solution level configurations
 
 		_p(1,'GlobalSection(SolutionConfigurationPlatforms) = preSolution')
 		table.foreachi(sorted, function (cfg)
 		end)
 		_p(1,"EndGlobalSection")
 
+		-- Map each of the solution level configurations to the corresponding
+		-- project level configurations.
+
 		_p(1,"GlobalSection(ProjectConfigurationPlatforms) = postSolution")
 		local tr = solution.grouptree(sln)
 		tree.traverse(tr, {
 			onleaf = function(n)
 				local prj = n.project
 
+				-- Take an initial pass to map the solution configurations into the
+				-- project. Make a note of the first valid mapping I encounter; I'll
+				-- use this to represent excluded configurations in the project (if
+				-- I don't, Visual Studio will modify the solution later to add it).
+
+				local prjCfgs = {}
+				local firstPrjCfg
+
 				table.foreachi(sorted, function (cfg)
-					local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform)
-					if prjcfg then
-						local prjplatform = vstudio.projectPlatform(prjcfg)
-						local architecture = vstudio.archFromConfig(prjcfg, true)
+					local prjCfg = project.getconfig(prj, cfg.buildcfg, cfg.platform)
+					firstPrjCfg = firstPrjCfg or prjCfg
+					prjCfgs[cfg] = prjCfg
+				end)
 
-						_p(2,'{%s}.%s.ActiveCfg = %s|%s', prj.uuid, slncfg[cfg], prjplatform, architecture)
-						if prjcfg.kind ~= premake.NONE then
-							_p(2,'{%s}.%s.Build.0 = %s|%s', prj.uuid, slncfg[cfg], prjplatform, architecture)
-						end
+				-- With that out of the way, I can now output the map
+
+				table.foreachi(sorted, function (cfg)
+					local prjcfg = prjCfgs[cfg] or firstPrjCfg
+
+					local prjplatform = vstudio.projectPlatform(prjcfg)
+					local architecture = vstudio.archFromConfig(prjcfg, true)
+
+					_p(2,'{%s}.%s.ActiveCfg = %s|%s', prj.uuid, slncfg[cfg], prjplatform, architecture)
+					if prjcfg.kind ~= premake.NONE and prjCfgs[cfg] then
+						_p(2,'{%s}.%s.Build.0 = %s|%s', prj.uuid, slncfg[cfg], prjplatform, architecture)
 					end
+
 				end)
 			end
 		})

tests/actions/vstudio/sln2005/test_platforms.lua

 	EndGlobalSection
 		]]
 	end
+
+
+---
+-- Excluded configurations should write an ActiveCfg entry, pointing to some
+-- arbitrary project configuration, and skip the Build.0 entry.
+---
+
+	function suite.onExcludedConfiguration()
+		platforms { "DLL", "Static" }
+		project "MyProject"
+		removeplatforms { "Static" }
+		prepare()
+		test.capture [[
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|DLL = Debug|DLL
+		Debug|Static = Debug|Static
+		Release|DLL = Release|DLL
+		Release|Static = Release|Static
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|DLL.ActiveCfg = Debug DLL|Win32
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|DLL.Build.0 = Debug DLL|Win32
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Static.ActiveCfg = Debug DLL|Win32
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|DLL.ActiveCfg = Release DLL|Win32
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|DLL.Build.0 = Release DLL|Win32
+		{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Static.ActiveCfg = Debug DLL|Win32
+	EndGlobalSection
+		]]
+	end