From a38135d712b7745f5b2755c29353b6f27ac47bca Mon Sep 17 00:00:00 2001 From: starkos Date: Wed, 15 Apr 2020 09:02:37 -0400 Subject: [PATCH] Fix systemversion("latest") on VS2017 --- .../android/tests/test_android_project.lua | 1 + modules/vstudio/tests/vc2010/test_globals.lua | 110 +++++++++--------- modules/vstudio/vs2010_vcxproj.lua | 67 +++++------ 3 files changed, 91 insertions(+), 87 deletions(-) diff --git a/modules/android/tests/test_android_project.lua b/modules/android/tests/test_android_project.lua index d7f23242..43ef82b0 100644 --- a/modules/android/tests/test_android_project.lua +++ b/modules/android/tests/test_android_project.lua @@ -44,6 +44,7 @@ test.capture [[ {42B5DBC6-AE1F-903D-F75D-41E363076E92} + $([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0')) Android MyProject 15.0 diff --git a/modules/vstudio/tests/vc2010/test_globals.lua b/modules/vstudio/tests/vc2010/test_globals.lua index 874fc317..b72b7c5b 100644 --- a/modules/vstudio/tests/vc2010/test_globals.lua +++ b/modules/vstudio/tests/vc2010/test_globals.lua @@ -254,31 +254,43 @@ ]] end --- --- Check that the "latest" systemversion works. --- note: we override the os.getWindowsRegistry method for reliable tests. --- +--- +-- Check handling of systemversion("latest") +--- - function suite.windowsTargetPlatformVersionLatest_on2017() +function suite.windowsTargetPlatformVersion_latest_on2015() + p.action.set("vs2015") + systemversion "latest" + prepare() + test.capture [[ + + {42B5DBC6-AE1F-903D-F75D-41E363076E92} + true + Win32Proj + MyProject + + ]] +end + + + function suite.windowsTargetPlatformVersion_latest_on2017() p.action.set("vs2017") systemversion "latest" - local oldRegistry = os["getWindowsRegistry"] - os["getWindowsRegistry"] = function (key) return "10.0.11111" end prepare() - os["getWindowsRegistry"] = oldRegistry test.capture [[ {42B5DBC6-AE1F-903D-F75D-41E363076E92} true Win32Proj MyProject - 10.0.11111.0 + $([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0')) + $(LatestTargetPlatformVersion) ]] end - - function suite.windowsTargetPlatformVersionLatest_on2019() + + function suite.windowsTargetPlatformVersion_latest_on2019() p.action.set("vs2019") systemversion "latest" prepare() @@ -293,49 +305,12 @@ ]] end --- --- Check that the "latest" systemversion will not add --- when the action is less than 2017 --- - function suite.windowsTargetPlatformVersionLatest_on2015() - p.action.set("vs2015") - systemversion "latest" - prepare() - test.capture [[ - - {42B5DBC6-AE1F-903D-F75D-41E363076E92} - true - Win32Proj - MyProject - - ]] - end - - function suite.windowsTargetPlatformVersionMultipleConditional_on2015Default() - p.action.set("vs2015") - filter "Debug" - systemversion "10.0.10240.0" - filter "Release" - systemversion "10.0.10240.1" - prepare() - test.capture [[ - - {42B5DBC6-AE1F-903D-F75D-41E363076E92} - true - Win32Proj - MyProject - - - 10.0.10240.0 - - - 10.0.10240.1 - - ]] - end - - function suite.windowsTargetPlatformVersionGlobalMultipleConditional_on2015Default() +--- +-- Check handling of per-configuration systemversion +--- + + function suite.windowsTargetPlatformVersion_perConfig_on2015() p.action.set("vs2015") systemversion "8.1" filter "Debug" @@ -359,4 +334,31 @@ ]] end - + + + function suite.windowsTargetPlatformVersion_perConfig_on2017() + p.action.set("vs2017") + systemversion "8.1" + filter "Debug" + systemversion "latest" + filter "Release" + systemversion "10.0.10240.1" + prepare() + test.capture [[ + + {42B5DBC6-AE1F-903D-F75D-41E363076E92} + true + Win32Proj + MyProject + $([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0')) + 8.1 + + + $(LatestTargetPlatformVersion) + + + 10.0.10240.1 + + ]] + end + diff --git a/modules/vstudio/vs2010_vcxproj.lua b/modules/vstudio/vs2010_vcxproj.lua index e6a86326..acdfe4c0 100644 --- a/modules/vstudio/vs2010_vcxproj.lua +++ b/modules/vstudio/vs2010_vcxproj.lua @@ -131,13 +131,14 @@ m.keyword, m.projectName, m.preferredToolArchitecture, - m.targetPlatformVersionGlobal, + m.latestTargetPlatformVersion, + m.windowsTargetPlatformVersion, } end m.elements.globalsCondition = function(prj, cfg) return { - m.targetPlatformVersionCondition, + m.windowsTargetPlatformVersion, } end @@ -2580,43 +2581,43 @@ end - function m.targetPlatformVersion(cfgOrPrj) + function m.latestTargetPlatformVersion(prj) + -- See https://developercommunity.visualstudio.com/content/problem/140294/windowstargetplatformversion-makes-it-impossible-t.html + if _ACTION == "vs2017" then + m.element("LatestTargetPlatformVersion", nil, "$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))") + end + end - if _ACTION >= "vs2015" then - local min = project.systemversion(cfgOrPrj) - -- handle special "latest" version - if min == "latest" then - -- vs2015 and lower can't build against SDK 10 - -- vs2019 allows for automatic assignment to latest - -- Windows 10 sdk if you set to "10.0" - if _ACTION >= "vs2019" then - min = "10.0" - else - min = iif(_ACTION == "vs2017", m.latestSDK10Version(), nil) - end + + function m.windowsTargetPlatformVersion(prj, cfg) + if _ACTION < "vs2015" then + return + end + + local target = cfg or prj + local version = project.systemversion(target) + + -- if this is a config, only emit if different from project + if cfg then + local prjVersion = project.systemversion(prj) + if not prjVersion or version == prjVersion then + return end - - return min end - end - - - function m.targetPlatformVersionGlobal(prj) - local min = m.targetPlatformVersion(prj) - if min ~= nil then - m.element("WindowsTargetPlatformVersion", nil, min) + -- See https://developercommunity.visualstudio.com/content/problem/140294/windowstargetplatformversion-makes-it-impossible-t.html + if version == "latest" then + if _ACTION == "vs2015" then + version = nil -- SDK v10 is not supported by VS2015 + elseif _ACTION == "vs2017" then + version = "$(LatestTargetPlatformVersion)" + else + version = "10.0" + end end - end - - function m.targetPlatformVersionCondition(prj, cfg) - - local cfgPlatformVersion = m.targetPlatformVersion(cfg) - local prjPlatformVersion = m.targetPlatformVersion(prj) - - if cfgPlatformVersion ~= nil and cfgPlatformVersion ~= prjPlatformVersion then - m.element("WindowsTargetPlatformVersion", nil, cfgPlatformVersion) + if version then + m.element("WindowsTargetPlatformVersion", nil, version) end end