Fix systemversion("latest") on VS2017

This commit is contained in:
starkos 2020-04-15 09:02:37 -04:00
parent 3b5f6e60c7
commit a38135d712
3 changed files with 91 additions and 87 deletions

View File

@ -44,6 +44,7 @@
test.capture [[ test.capture [[
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{42B5DBC6-AE1F-903D-F75D-41E363076E92}</ProjectGuid> <ProjectGuid>{42B5DBC6-AE1F-903D-F75D-41E363076E92}</ProjectGuid>
<LatestTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</LatestTargetPlatformVersion>
<Keyword>Android</Keyword> <Keyword>Android</Keyword>
<RootNamespace>MyProject</RootNamespace> <RootNamespace>MyProject</RootNamespace>
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion> <MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>

View File

@ -254,31 +254,43 @@
]] ]]
end end
-- ---
-- Check that the "latest" systemversion works. -- Check handling of systemversion("latest")
-- note: we override the os.getWindowsRegistry method for reliable tests. ---
--
function suite.windowsTargetPlatformVersionLatest_on2017() function suite.windowsTargetPlatformVersion_latest_on2015()
p.action.set("vs2015")
systemversion "latest"
prepare()
test.capture [[
<PropertyGroup Label="Globals">
<ProjectGuid>{42B5DBC6-AE1F-903D-F75D-41E363076E92}</ProjectGuid>
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
<Keyword>Win32Proj</Keyword>
<RootNamespace>MyProject</RootNamespace>
</PropertyGroup>
]]
end
function suite.windowsTargetPlatformVersion_latest_on2017()
p.action.set("vs2017") p.action.set("vs2017")
systemversion "latest" systemversion "latest"
local oldRegistry = os["getWindowsRegistry"]
os["getWindowsRegistry"] = function (key) return "10.0.11111" end
prepare() prepare()
os["getWindowsRegistry"] = oldRegistry
test.capture [[ test.capture [[
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{42B5DBC6-AE1F-903D-F75D-41E363076E92}</ProjectGuid> <ProjectGuid>{42B5DBC6-AE1F-903D-F75D-41E363076E92}</ProjectGuid>
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename> <IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>MyProject</RootNamespace> <RootNamespace>MyProject</RootNamespace>
<WindowsTargetPlatformVersion>10.0.11111.0</WindowsTargetPlatformVersion> <LatestTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</LatestTargetPlatformVersion>
<WindowsTargetPlatformVersion>$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
]] ]]
end end
function suite.windowsTargetPlatformVersionLatest_on2019() function suite.windowsTargetPlatformVersion_latest_on2019()
p.action.set("vs2019") p.action.set("vs2019")
systemversion "latest" systemversion "latest"
prepare() prepare()
@ -293,49 +305,12 @@
]] ]]
end end
--
-- Check that the "latest" systemversion will not add <WindowsTargetPlatformVersion>
-- when the action is less than 2017
--
function suite.windowsTargetPlatformVersionLatest_on2015() ---
p.action.set("vs2015") -- Check handling of per-configuration systemversion
systemversion "latest" ---
prepare()
test.capture [[ function suite.windowsTargetPlatformVersion_perConfig_on2015()
<PropertyGroup Label="Globals">
<ProjectGuid>{42B5DBC6-AE1F-903D-F75D-41E363076E92}</ProjectGuid>
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
<Keyword>Win32Proj</Keyword>
<RootNamespace>MyProject</RootNamespace>
</PropertyGroup>
]]
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 [[
<PropertyGroup Label="Globals">
<ProjectGuid>{42B5DBC6-AE1F-903D-F75D-41E363076E92}</ProjectGuid>
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
<Keyword>Win32Proj</Keyword>
<RootNamespace>MyProject</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Globals">
<WindowsTargetPlatformVersion>10.0.10240.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Globals">
<WindowsTargetPlatformVersion>10.0.10240.1</WindowsTargetPlatformVersion>
</PropertyGroup>
]]
end
function suite.windowsTargetPlatformVersionGlobalMultipleConditional_on2015Default()
p.action.set("vs2015") p.action.set("vs2015")
systemversion "8.1" systemversion "8.1"
filter "Debug" filter "Debug"
@ -359,4 +334,31 @@
</PropertyGroup> </PropertyGroup>
]] ]]
end 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 [[
<PropertyGroup Label="Globals">
<ProjectGuid>{42B5DBC6-AE1F-903D-F75D-41E363076E92}</ProjectGuid>
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
<Keyword>Win32Proj</Keyword>
<RootNamespace>MyProject</RootNamespace>
<LatestTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</LatestTargetPlatformVersion>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Globals">
<WindowsTargetPlatformVersion>$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Globals">
<WindowsTargetPlatformVersion>10.0.10240.1</WindowsTargetPlatformVersion>
</PropertyGroup>
]]
end

View File

@ -131,13 +131,14 @@
m.keyword, m.keyword,
m.projectName, m.projectName,
m.preferredToolArchitecture, m.preferredToolArchitecture,
m.targetPlatformVersionGlobal, m.latestTargetPlatformVersion,
m.windowsTargetPlatformVersion,
} }
end end
m.elements.globalsCondition = function(prj, cfg) m.elements.globalsCondition = function(prj, cfg)
return { return {
m.targetPlatformVersionCondition, m.windowsTargetPlatformVersion,
} }
end end
@ -2580,43 +2581,43 @@
end 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) function m.windowsTargetPlatformVersion(prj, cfg)
-- handle special "latest" version if _ACTION < "vs2015" then
if min == "latest" then return
-- vs2015 and lower can't build against SDK 10 end
-- vs2019 allows for automatic assignment to latest
-- Windows 10 sdk if you set to "10.0" local target = cfg or prj
if _ACTION >= "vs2019" then local version = project.systemversion(target)
min = "10.0"
else -- if this is a config, only emit if different from project
min = iif(_ACTION == "vs2017", m.latestSDK10Version(), nil) if cfg then
end local prjVersion = project.systemversion(prj)
if not prjVersion or version == prjVersion then
return
end end
return min
end end
end -- See https://developercommunity.visualstudio.com/content/problem/140294/windowstargetplatformversion-makes-it-impossible-t.html
if version == "latest" then
if _ACTION == "vs2015" then
function m.targetPlatformVersionGlobal(prj) version = nil -- SDK v10 is not supported by VS2015
local min = m.targetPlatformVersion(prj) elseif _ACTION == "vs2017" then
if min ~= nil then version = "$(LatestTargetPlatformVersion)"
m.element("WindowsTargetPlatformVersion", nil, min) else
version = "10.0"
end
end end
end
if version then
function m.targetPlatformVersionCondition(prj, cfg) m.element("WindowsTargetPlatformVersion", nil, version)
local cfgPlatformVersion = m.targetPlatformVersion(cfg)
local prjPlatformVersion = m.targetPlatformVersion(prj)
if cfgPlatformVersion ~= nil and cfgPlatformVersion ~= prjPlatformVersion then
m.element("WindowsTargetPlatformVersion", nil, cfgPlatformVersion)
end end
end end