From ec90b60d94dda359be787888208ec10464b29296 Mon Sep 17 00:00:00 2001 From: starkos Date: Thu, 26 Mar 2009 19:29:21 +0000 Subject: [PATCH] Refactored current platform code for VS2005 and VS2008 --- src/actions/vstudio/_vstudio.lua | 26 +++++++ src/actions/vstudio/vs2005_solution.lua | 83 ++++++--------------- src/actions/vstudio/vs200x_vcproj.lua | 30 ++++---- tests/premake4.lua | 1 + tests/test_vs2005_sln.lua | 98 +++---------------------- tests/test_vs200x_vcproj.lua | 45 +++++++++--- tests/test_vstudio.lua | 34 +++++++++ tests/testfx.lua | 9 +++ 8 files changed, 153 insertions(+), 173 deletions(-) create mode 100644 tests/test_vstudio.lua diff --git a/src/actions/vstudio/_vstudio.lua b/src/actions/vstudio/_vstudio.lua index d4fe419d..c4212120 100644 --- a/src/actions/vstudio/_vstudio.lua +++ b/src/actions/vstudio/_vstudio.lua @@ -142,6 +142,32 @@ +-- +-- Map a list of platforms to their Visual Studio equivalents, taking the +-- Visual Studio version into account. Note that multiple target platforms +-- is only supported for Visual Studio 2005 or later right now. +-- + + function premake.vstudio_get_platforms(platforms, version) + local result = { } + if version > "vs2003" and platforms then + for _, platform in ipairs(platforms) do + if platform == "x32" then + table.insert(result, "Win32") + elseif platform == "x64" then + table.insert(result, "x64") + end + end + end + + -- make sure I've got at least one + if #result == 0 then + result = { "Win32" } + end + return result + end + + -- -- Write out entries for the files element; called from premake.walksources(). -- diff --git a/src/actions/vstudio/vs2005_solution.lua b/src/actions/vstudio/vs2005_solution.lua index 61772487..68a28825 100644 --- a/src/actions/vstudio/vs2005_solution.lua +++ b/src/actions/vstudio/vs2005_solution.lua @@ -8,6 +8,24 @@ function premake.vs2005_solution(sln) io.eol = '\r\n' + -- Build the list of target platforms + local hascpp = premake.hascppproject(sln) + local hasdotnet = premake.hasdotnetproject(sln) + + local platforms = { } + if hasdotnet then + table.insert(platforms, "Any CPU") + end + if hasdotnet and hascpp then + table.insert(platforms, "Mixed Platforms") + end + if hascpp then + platforms.cppdefault = #platforms + 1 + for _, p in ipairs(premake.vstudio_get_platforms(sln.platforms, _ACTION)) do + table.insert(platforms, p) + end + end + -- Mark the file as Unicode io.printf('\239\187\191') @@ -19,7 +37,7 @@ io.printf('Microsoft Visual Studio Solution File, Format Version 10.00') io.printf('# Visual Studio 2008') end - + -- Write out the list of project entries for prj in premake.eachproject(sln) do -- Build a relative path from the solution file to the project file @@ -38,8 +56,8 @@ end io.printf('Global') - premake.vs2005_solution_configurations(sln) - premake.vs2005_solution_project_configurations(sln) + premake.vs2005_solution_configurations(sln, platforms) + premake.vs2005_solution_project_configurations(sln, platforms) premake.vs2005_solution_properties(sln) io.printf('EndGlobal') end @@ -51,16 +69,13 @@ -- lists all of the configuration/platform pairs that exist in the solution. -- - function premake.vs2005_solution_configurations(sln) - local platforms = premake.vs2005_solution_platforms(sln) + function premake.vs2005_solution_configurations(sln, platforms) io.printf('\tGlobalSection(SolutionConfigurationPlatforms) = preSolution') - for _, cfgname in ipairs(sln.configurations) do for _, platname in ipairs(platforms) do io.printf('\t\t%s|%s = %s|%s', cfgname, platname, cfgname, platname) end end - io.printf('\tEndGlobalSection') end @@ -71,10 +86,8 @@ -- the configuration/platform pairs into each project of the solution. -- - function premake.vs2005_solution_project_configurations(sln) - local platforms = premake.vs2005_solution_platforms(sln) + function premake.vs2005_solution_project_configurations(sln, platforms) io.printf('\tGlobalSection(ProjectConfigurationPlatforms) = postSolution') - for prj in premake.eachproject(sln) do for _, cfgname in ipairs(sln.configurations) do for i, platname in ipairs(platforms) do @@ -86,7 +99,6 @@ end end end - io.printf('\tEndGlobalSection') end @@ -104,53 +116,6 @@ --- --- Translate the generic list of platforms into their Visual Studio equivalents. --- - - function premake.vs2005_solution_platforms(sln) - -- see if I've already cached the list - if sln.__vs2005_platforms then - return sln.__vs2005_platforms - end - - local hascpp = premake.hascppproject(sln) - local hasdotnet = premake.hasdotnetproject(sln) - local result = { } - - if hasdotnet then - table.insert(result, "Any CPU") - end - - if hasdotnet and hascpp then - table.insert(result, "Mixed Platforms") - end - - if hascpp then - result._firstCppPlatform = #result + 1 - if sln.platforms then - for _, pid in ipairs(sln.platforms) do - if pid == "x32" then - table.insert(result, "Win32") - elseif pid == "x64" then - table.insert(result, "x64") - end - end - end - - -- if no VS-compatible platforms were found, add a default - if #result < result._firstCppPlatform then - table.insert(result, "Win32") - end - end - - -- cache the result; I need it pretty often - sln.__vs2005_platforms = result - return result - end - - - -- -- Map a solution-level platform to one compatible with the provided project. -- C++ platforms are mapped to "Any CPU" for .NET projects, and vice versa. @@ -164,5 +129,5 @@ -- C++ projects use the current platform, or the first C++ platform -- if the current one is for .NET - return platforms[math.max(i, platforms._firstCppPlatform)] + return platforms[math.max(i, platforms.cppdefault)] end \ No newline at end of file diff --git a/src/actions/vstudio/vs200x_vcproj.lua b/src/actions/vstudio/vs200x_vcproj.lua index c8c604dd..ebb553ff 100644 --- a/src/actions/vstudio/vs200x_vcproj.lua +++ b/src/actions/vstudio/vs200x_vcproj.lua @@ -4,17 +4,8 @@ -- Copyright (c) 2009 Jason Perkins and the Premake project -- - -- - -- Write out an empty tool block; there are quite a few of these. - -- - local function printemptyblock(name) - io.printf('\t\t\t') - end - - -- Write out a custom build steps block. + -- Write out a custom build steps block local function buildstepsblock(name, steps) io.printf('\t\t\t') - premake.vs200x_vcproj_platforms(prj) + -- list target platforms + local platforms = premake.vstudio_get_platforms(prj.solution.platforms, _ACTION) + io.printf('\t') + for _, platform in ipairs(platforms) do + io.printf('\t\t') + end + io.printf('\t') if _ACTION > "vs2003" then io.printf('\t') @@ -59,10 +58,7 @@ io.printf('\t') - local platforms = premake.vs2005_solution_platforms(prj.solution) - for i = platforms._firstCppPlatform, #platforms do - local platform = platforms[i] - + for _, platform in ipairs(platforms) do for cfg in premake.eachconfig(prj) do -- Start a configuration io.printf('\t\t') end end io.printf('\t\t') diff --git a/tests/premake4.lua b/tests/premake4.lua index 42308020..581197a3 100644 --- a/tests/premake4.lua +++ b/tests/premake4.lua @@ -16,6 +16,7 @@ dofile("test_api.lua") dofile("test_targets.lua") dofile("test_keywords.lua") + dofile("test_vstudio.lua") dofile("test_vs2002_sln.lua") dofile("test_vs2003_sln.lua") dofile("test_vs2005_sln.lua") diff --git a/tests/test_vs2005_sln.lua b/tests/test_vs2005_sln.lua index 2d0e07ca..659334e9 100644 --- a/tests/test_vs2005_sln.lua +++ b/tests/test_vs2005_sln.lua @@ -63,12 +63,15 @@ EndGlobal -- Test a mixed runtime (C++/.NET) solution. -- - function T.vs2005_sln.MixedRuntime() + function T.vs2005_sln.MixedPlatformsAndRuntime() project "MyNetProject" language "C#" kind "ConsoleApp" uuid "C9135098-6047-8142-B10E-D27E7F73FCB3" + solution() + platforms { "x32", "x64" } + io.capture() premake.buildconfigs() premake.vs2005_solution(sln) @@ -85,97 +88,12 @@ Global Debug|Any CPU = Debug|Any CPU Debug|Mixed Platforms = Debug|Mixed Platforms Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU Release|Mixed Platforms = Release|Mixed Platforms Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.Build.0 = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.Build.0 = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Any CPU.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Mixed Platforms.Build.0 = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.Build.0 = Release|Win32 - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Win32.ActiveCfg = Debug|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.Build.0 = Release|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Win32.ActiveCfg = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal - ]]) - end - - --- --- Test combinations of C++ and .NET platforms --- - - function T.vs2005_sln.SolutionConfigs_OnMultipleCppPlatforms() - solution() - platforms { "x32", "x64" } - - io.capture() - premake.buildconfigs() - premake.vs2005_solution_configurations(sln) - test.capture [[ - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 Release|x64 = Release|x64 EndGlobalSection - ]] - end - - - function T.vs2005_sln.ProjectConfigs_OnMultipleCppPlatforms() - solution() - platforms { "x32", "x64" } - - io.capture() - premake.buildconfigs() - premake.vs2005_solution_project_configurations(sln) - test.capture [[ - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.ActiveCfg = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.Build.0 = Debug|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|x64.ActiveCfg = Debug|x64 - {AE61726D-187C-E440-BD07-2556188A6565}.Debug|x64.Build.0 = Debug|x64 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.ActiveCfg = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.Build.0 = Release|Win32 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|x64.ActiveCfg = Release|x64 - {AE61726D-187C-E440-BD07-2556188A6565}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - ]] - end - - - function T.vs2005_sln.ProjectConfigs_OnMultipleCppPlatformsAndMixedRuntimes() - project "MyNetProject" - language "C#" - kind "ConsoleApp" - uuid "C9135098-6047-8142-B10E-D27E7F73FCB3" - - solution() - platforms { "x32", "x64" } - - io.capture() - premake.buildconfigs() - premake.vs2005_solution_project_configurations(sln) - test.capture [[ GlobalSection(ProjectConfigurationPlatforms) = postSolution {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Any CPU.ActiveCfg = Debug|Win32 {AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 @@ -204,5 +122,9 @@ EndGlobal {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Win32.ActiveCfg = Release|Any CPU {C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x64.ActiveCfg = Release|Any CPU EndGlobalSection - ]] + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal + ]]) end diff --git a/tests/test_vs200x_vcproj.lua b/tests/test_vs200x_vcproj.lua index 4e0da1a3..a495b7dc 100644 --- a/tests/test_vs200x_vcproj.lua +++ b/tests/test_vs200x_vcproj.lua @@ -231,12 +231,11 @@ -- Test multiple platforms -- - function T.vs200x_vcproj.Platforms_OnMultiplePlatforms() - platforms { "x32", "x64" } - + function T.vs200x_vcproj.PlatformsBlock_OnMultiplePlatforms() + platforms { "x32", "x64" } prepare() - premake.vs200x_vcproj_platforms(prj) - test.capture [[ + premake.vs200x_vcproj(prj) + test.capturecontains [[ - ]] + ]] end - - function T.vs200x_vcproj.Platforms_OnMultiplePlatforms() + function T.vs200x_vcproj.PlatformConfigs_OnMultiplePlatforms() platforms { "x32", "x64" } - prepare() premake.vs200x_vcproj(prj) local result = io.endcapture() - test.istrue(result:find ' + + + ]] + end + + + function T.vs200x_vcproj.PlatformConfigs_Ignored_OnMultiplePlatforms() + platforms { "x32", "x64" } + _ACTION = "vs2003" + prepare() + premake.vs200x_vcproj(prj) + local result = io.endcapture() + test.istrue(result:find '