From e0e4b23a5d2c1b396bdeb7bcfb71a534828bab7b Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Tue, 21 May 2013 08:48:22 -0400 Subject: [PATCH] More reconciliation with Visual Studio project formats: - sort solution configurations by case-insensitive names - add trailing CR-LF to custom build steps - remove empty Filter attributes from folder filter elements --- src/actions/vstudio/vs2005_solution.lua | 37 ++++++++--- src/actions/vstudio/vs200x_vcproj.lua | 3 +- src/actions/vstudio/vs2010_vcxproj.lua | 2 +- src/project/config.lua | 2 +- .../vstudio/sln2005/test_platforms.lua | 63 ++++++++++++++----- .../vstudio/vc200x/test_build_steps.lua | 54 ++++++++++++++++ tests/actions/vstudio/vc200x/test_files.lua | 5 -- tests/premake4.lua | 1 + 8 files changed, 131 insertions(+), 36 deletions(-) create mode 100644 tests/actions/vstudio/vc200x/test_build_steps.lua diff --git a/src/actions/vstudio/vs2005_solution.lua b/src/actions/vstudio/vs2005_solution.lua index 06c53edb..f37948da 100644 --- a/src/actions/vstudio/vs2005_solution.lua +++ b/src/actions/vstudio/vs2005_solution.lua @@ -131,26 +131,43 @@ -- function sln2005.configurationPlatforms(sln) - -- build a VS cfg descriptor for each solution configuration + + -- Build a VS cfg descriptor for each solution configuration. + local slncfg = {} for cfg in solution.eachconfig(sln) do 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]) - end - _p(1,'EndGlobalSection') + -- 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. - _p(1,'GlobalSection(ProjectConfigurationPlatforms) = postSolution') + local sorted = {} + for cfg in solution.eachconfig(sln) do + table.insert(sorted, cfg) + end + + table.sort(sorted, function(a,b) + return slncfg[a]:lower() < slncfg[b]:lower() + end) + + -- Now use the sorted list to output the configuration maps. + + _p(1,'GlobalSection(SolutionConfigurationPlatforms) = preSolution') + table.foreachi(sorted, function (cfg) + _p(2,'%s = %s', slncfg[cfg], slncfg[cfg]) + end) + _p(1,"EndGlobalSection") + + _p(1,"GlobalSection(ProjectConfigurationPlatforms) = postSolution") local tr = solution.grouptree(sln) tree.traverse(tr, { onleaf = function(n) local prj = n.project - for cfg in solution.eachconfig(sln) do + table.foreachi(sorted, function (cfg) local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform) if prjcfg then local prjplatform = vstudio.projectPlatform(prjcfg) @@ -159,10 +176,10 @@ _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 diff --git a/src/actions/vstudio/vs200x_vcproj.lua b/src/actions/vstudio/vs200x_vcproj.lua index 16c5e13b..fe99245f 100644 --- a/src/actions/vstudio/vs200x_vcproj.lua +++ b/src/actions/vstudio/vs200x_vcproj.lua @@ -643,7 +643,7 @@ _p(3,' 0 then - _x(4,'CommandLine="%s"', table.implode(steps, "", "", "\r\n")) + _x(4,'CommandLine="%s"', table.implode(steps, "", "\r\n", "")) end _p(3,'/>') end @@ -724,7 +724,6 @@ onbranchenter = function(node, depth) _p(depth, '') end, diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index 70603c63..209c06be 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -63,7 +63,7 @@ vc2010.import(prj) - _p('') + io.printf('') end diff --git a/src/project/config.lua b/src/project/config.lua index 418ef3a0..b3104f27 100755 --- a/src/project/config.lua +++ b/src/project/config.lua @@ -351,7 +351,7 @@ -- If I'm building a list of link directories, include libdirs - if part == "directory" and kind == "all" then + if part == "directory" then table.foreachi(cfg.libdirs, function(dir) table.insert(result, project.getrelative(cfg.project, dir)) end) diff --git a/tests/actions/vstudio/sln2005/test_platforms.lua b/tests/actions/vstudio/sln2005/test_platforms.lua index d1b212af..1601e9fa 100644 --- a/tests/actions/vstudio/sln2005/test_platforms.lua +++ b/tests/actions/vstudio/sln2005/test_platforms.lua @@ -1,7 +1,7 @@ -- -- tests/actions/vstudio/sln2005/test_platforms.lua -- Test the Visual Studio 2005-2010 platform mapping blocks. --- Copyright (c) 2009-2012 Jason Perkins and the Premake project +-- Copyright (c) 2009-2013 Jason Perkins and the Premake project -- T.vstudio_sln2005_platforms = { } @@ -495,20 +495,20 @@ prepare() test.capture [[ GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 Debug|x64 = Debug|x64 - Release|x86 = Release|x86 + Debug|x86 = Debug|x86 Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x86.ActiveCfg = Debug|x86 - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x86.Build.0 = Debug|x86 {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x64.ActiveCfg = Debug|x64 {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x64.Build.0 = Debug|x64 - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x86.ActiveCfg = Release|x86 - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x86.Build.0 = Release|x86 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x86.ActiveCfg = Debug|x86 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x86.Build.0 = Debug|x86 {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x64.ActiveCfg = Release|x64 {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x64.Build.0 = Release|x64 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x86.ActiveCfg = Release|x86 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x86.Build.0 = Release|x86 EndGlobalSection ]] end @@ -523,28 +523,28 @@ prepare() test.capture [[ GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 Debug|x64 = Debug|x64 - Release|x86 = Release|x86 + Debug|x86 = Debug|x86 Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {52AD9329-0D74-4F66-A213-E649D8CCD737}.Debug|x86.ActiveCfg = Debug|x86 - {52AD9329-0D74-4F66-A213-E649D8CCD737}.Debug|x86.Build.0 = Debug|x86 {52AD9329-0D74-4F66-A213-E649D8CCD737}.Debug|x64.ActiveCfg = Debug|x64 {52AD9329-0D74-4F66-A213-E649D8CCD737}.Debug|x64.Build.0 = Debug|x64 - {52AD9329-0D74-4F66-A213-E649D8CCD737}.Release|x86.ActiveCfg = Release|x86 - {52AD9329-0D74-4F66-A213-E649D8CCD737}.Release|x86.Build.0 = Release|x86 + {52AD9329-0D74-4F66-A213-E649D8CCD737}.Debug|x86.ActiveCfg = Debug|x86 + {52AD9329-0D74-4F66-A213-E649D8CCD737}.Debug|x86.Build.0 = Debug|x86 {52AD9329-0D74-4F66-A213-E649D8CCD737}.Release|x64.ActiveCfg = Release|x64 {52AD9329-0D74-4F66-A213-E649D8CCD737}.Release|x64.Build.0 = Release|x64 - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x86.ActiveCfg = Debug|Win32 - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x86.Build.0 = Debug|Win32 + {52AD9329-0D74-4F66-A213-E649D8CCD737}.Release|x86.ActiveCfg = Release|x86 + {52AD9329-0D74-4F66-A213-E649D8CCD737}.Release|x86.Build.0 = Release|x86 {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x64.ActiveCfg = Debug|x64 {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x64.Build.0 = Debug|x64 - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x86.ActiveCfg = Release|Win32 - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x86.Build.0 = Release|Win32 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x86.ActiveCfg = Debug|Win32 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x86.Build.0 = Debug|Win32 {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x64.ActiveCfg = Release|x64 {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x64.Build.0 = Release|x64 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x86.ActiveCfg = Release|Win32 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x86.Build.0 = Release|Win32 EndGlobalSection ]] end @@ -616,3 +616,32 @@ EndGlobalSection ]] end + + +--- +-- Check the sort order of the configurations. +--- + + function suite.sortsByBuildCfgAndPlatform() + platforms { "Windows", "PS3" } + project "MyProject" + prepare() + test.capture [[ + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|PS3 = Debug|PS3 + Debug|Windows = Debug|Windows + Release|PS3 = Release|PS3 + Release|Windows = Release|Windows + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|PS3.ActiveCfg = Debug PS3|Win32 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|PS3.Build.0 = Debug PS3|Win32 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Windows.ActiveCfg = Debug Windows|Win32 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Windows.Build.0 = Debug Windows|Win32 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|PS3.ActiveCfg = Release PS3|Win32 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|PS3.Build.0 = Release PS3|Win32 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Windows.ActiveCfg = Release Windows|Win32 + {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Windows.Build.0 = Release Windows|Win32 + EndGlobalSection + ]] + end diff --git a/tests/actions/vstudio/vc200x/test_build_steps.lua b/tests/actions/vstudio/vc200x/test_build_steps.lua new file mode 100644 index 00000000..7bcab47b --- /dev/null +++ b/tests/actions/vstudio/vc200x/test_build_steps.lua @@ -0,0 +1,54 @@ +-- +-- tests/actions/vstudio/vc200x/test_build_steps.lua +-- Test generation of custom build step elements. +-- Copyright (c) 2013 Jason Perkins and the Premake project +-- + + local suite = test.declare("vs200x_build_steps") + local vc200x = premake.vstudio.vc200x + + +-- +-- Setup/teardown +-- + + local sln, prj, cfg + + function suite.setup() + sln, prj = test.createsolution() + end + + local function prepare() + cfg = premake5.project.getconfig(prj, "Debug") + vc200x.VCPreBuildEventTool(cfg) + end + + +--- +-- Should output empty element wrapper on no build steps. +--- + + function suite.noCommandLine_onNoBuildSteps() + prepare() + test.capture [[ + + ]] + end + + +--- +-- Should insert CR-LF at end of each command line. +--- + + function suite.addsCRLF() + prebuildcommands { "command_1", "command_2" } + prepare() + test.capture [[ + + ]] + end diff --git a/tests/actions/vstudio/vc200x/test_files.lua b/tests/actions/vstudio/vc200x/test_files.lua index 1c5d4f79..9139df4a 100644 --- a/tests/actions/vstudio/vc200x/test_files.lua +++ b/tests/actions/vstudio/vc200x/test_files.lua @@ -54,7 +54,6 @@