diff options
author | starkos <none@none> | 2009-03-26 22:29:21 +0300 |
---|---|---|
committer | starkos <none@none> | 2009-03-26 22:29:21 +0300 |
commit | 0c794084b29f35a3af53d414f320aab4a2195bca (patch) | |
tree | 5a2e186db2d66a0e7b453becbaa86d22ec02f350 | |
parent | 0776e56996fa3f25d4f746bd05e3b6badc339644 (diff) |
Refactored current platform code for VS2005 and VS2008
-rw-r--r-- | src/actions/vstudio/_vstudio.lua | 26 | ||||
-rw-r--r-- | src/actions/vstudio/vs2005_solution.lua | 83 | ||||
-rw-r--r-- | src/actions/vstudio/vs200x_vcproj.lua | 30 | ||||
-rw-r--r-- | tests/premake4.lua | 1 | ||||
-rw-r--r-- | tests/test_vs2005_sln.lua | 98 | ||||
-rw-r--r-- | tests/test_vs200x_vcproj.lua | 45 | ||||
-rw-r--r-- | tests/test_vstudio.lua | 34 | ||||
-rw-r--r-- | tests/testfx.lua | 9 |
8 files changed, 153 insertions, 173 deletions
diff --git a/src/actions/vstudio/_vstudio.lua b/src/actions/vstudio/_vstudio.lua index d4fe419..c421212 100644 --- a/src/actions/vstudio/_vstudio.lua +++ b/src/actions/vstudio/_vstudio.lua @@ -143,6 +143,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 6177248..68a2882 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 @@ -105,53 +117,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 c8c604d..ebb553f 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<Tool') - io.printf('\t\t\t\tName="%s"', 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<Tool') io.printf('\t\t\t\tName="%s"', name) @@ -50,7 +41,15 @@ io.printf('\tKeyword="%s"', iif(prj.flags.Managed, "ManagedCProj", "Win32Proj")) io.printf('\t>') - premake.vs200x_vcproj_platforms(prj) + -- list target platforms + local platforms = premake.vstudio_get_platforms(prj.solution.platforms, _ACTION) + io.printf('\t<Platforms>') + for _, platform in ipairs(platforms) do + io.printf('\t\t<Platform') + io.printf('\t\t\tName="%s"', platform) + io.printf('\t\t/>') + end + io.printf('\t</Platforms>') if _ACTION > "vs2003" then io.printf('\t<ToolFiles>') @@ -59,10 +58,7 @@ io.printf('\t<Configurations>') - 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<Configuration') @@ -217,7 +213,9 @@ -- End build event blocks -- else - printemptyblock(block) + io.printf('\t\t\t<Tool') + io.printf('\t\t\t\tName="%s"', block) + io.printf('\t\t\t/>') end end io.printf('\t\t</Configuration>') diff --git a/tests/premake4.lua b/tests/premake4.lua index 4230802..581197a 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 2d0e07c..659334e 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 4e0da1a..a495b7d 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 [[ <Platforms> <Platform Name="Win32" @@ -245,20 +244,46 @@ Name="x64" /> </Platforms> - ]] + ]] 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 '<Configuration\r\n\t\t\tName="Debug|Win32"\r\n') test.istrue(result:find '<Configuration\r\n\t\t\tName="Release|Win32"\r\n') test.istrue(result:find '<Configuration\r\n\t\t\tName="Debug|x64"\r\n') test.istrue(result:find '<Configuration\r\n\t\t\tName="Release|x64"\r\n') end + + + + function T.vs200x_vcproj.PlatformsBlock_Ignored_OnVs2003() + platforms { "x32", "x64" } + _ACTION = "vs2003" + prepare() + premake.vs200x_vcproj(prj) + test.capturecontains [[ + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + ]] + 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 '<Configuration\r\n\t\t\tName="Debug|Win32"\r\n') + test.istrue(result:find '<Configuration\r\n\t\t\tName="Release|Win32"\r\n') + test.isfalse(result:find '<Configuration\r\n\t\t\tName="Debug|x64"\r\n') + test.isfalse(result:find '<Configuration\r\n\t\t\tName="Release|x64"\r\n') + end diff --git a/tests/test_vstudio.lua b/tests/test_vstudio.lua new file mode 100644 index 0000000..13861dc --- /dev/null +++ b/tests/test_vstudio.lua @@ -0,0 +1,34 @@ +-- +-- tests/test_vstudio.lua +-- Automated test suite for Visual Studio 200* general functions. +-- Copyright (c) 2009 Jason Perkins and the Premake project +-- + + T.vstudio = { } + + + +-- +-- Test platform mapping +-- + + function T.vstudio.Platforms_OnVs2002() + local result = premake.vstudio_get_platforms(premake.fields.platforms.allowed, "vs2002") + test.isequal("Win32", table.concat(result, "|")) + end + + function T.vstudio.Platforms_OnVs2003() + local result = premake.vstudio_get_platforms(premake.fields.platforms.allowed, "vs2003") + test.isequal("Win32", table.concat(result, "|")) + end + + function T.vstudio.Platforms_OnVs2005() + local result = premake.vstudio_get_platforms(premake.fields.platforms.allowed, "vs2005") + test.isequal("Win32|x64", table.concat(result, "|")) + end + + function T.vstudio.Platforms_OnVs2008() + local result = premake.vstudio_get_platforms(premake.fields.platforms.allowed, "vs2008") + test.isequal("Win32|x64", table.concat(result, "|")) + end + diff --git a/tests/testfx.lua b/tests/testfx.lua index a135d52..a571514 100644 --- a/tests/testfx.lua +++ b/tests/testfx.lua @@ -39,6 +39,15 @@ end + function test.capturecontains(expected) + local actual = io.endcapture() + expected = expected:gsub("\n", io.eol) + if (not actual:find(expected)) then + test.fail("result did not contain the expected text") + end + end + + function test.fail(format, ...) -- convert nils into something more usefuls for i = 1, arg.n do |