Skip to content

Commit fd645ec

Browse files
authored
[3.6] bpo-31340: Change to building with MSVC v141 (included with Visual Studio 2017) (GH-3311) (#3386)
1 parent 34c6761 commit fd645ec

File tree

12 files changed

+122
-31
lines changed

12 files changed

+122
-31
lines changed

.github/appveyor.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ test_script:
1414
- cmd: PCbuild\rt.bat -q -uall -u-cpu -rwW --slowest --timeout=1200 -j0
1515
environment:
1616
HOST_PYTHON: C:\Python36\python.exe
17+
image:
18+
- Visual Studio 2015
19+
- Visual Studio 2017
1720

1821
# Only trigger AppVeyor if actual code or its configuration changes
1922
only_commits:

Doc/make.bat

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,29 @@ pushd %~dp0
66
set this=%~n0
77

88
call ..\PCBuild\find_python.bat %PYTHON%
9-
if "%SPHINXBUILD%" EQU "" if "%PYTHON%" NEQ "" (
10-
set SPHINXBUILD=%PYTHON%\..\Scripts\sphinx-build.exe
11-
rem Cannot use %SPHINXBUILD% in the same block where we set it
12-
if not exist "%PYTHON%\..\Scripts\sphinx-build.exe" (
9+
if not defined SPHINXBUILD if defined PYTHON (
10+
%PYTHON% -c "import sphinx" > nul 2> nul
11+
if errorlevel 1 (
1312
echo Installing sphinx with %PYTHON%
14-
"%PYTHON%" -m pip install sphinx
13+
%PYTHON% -m pip install sphinx
1514
if errorlevel 1 exit /B
1615
)
16+
set SPHINXBUILD=%PYTHON% -c "import sphinx, sys; sys.argv[0] = 'sphinx-build'; sphinx.main()"
1717
)
1818

19-
if "%PYTHON%" EQU "" set PYTHON=py
20-
if "%SPHINXBUILD%" EQU "" set SPHINXBUILD=sphinx-build
19+
if not defined BLURB if defined PYTHON (
20+
%PYTHON% -c "import blurb" > nul 2> nul
21+
if errorlevel 1 (
22+
echo Installing blurb with %PYTHON%
23+
%PYTHON% -m pip install blurb
24+
if errorlevel 1 exit /B
25+
)
26+
set BLURB=%PYTHON% -m blurb
27+
)
28+
29+
if not defined PYTHON set PYTHON=py
30+
if not defined SPHINXBUILD set SPHINXBUILD=sphinx-build
31+
if not defined BLURB set BLURB=blurb
2132

2233
if "%1" NEQ "htmlhelp" goto :skiphhcsearch
2334
if exist "%HTMLHELP%" goto :skiphhcsearch
@@ -96,6 +107,19 @@ echo.be passed by setting the SPHINXOPTS environment variable.
96107
goto end
97108

98109
:build
110+
if exist ..\Misc\NEWS (
111+
echo.Copying Misc\NEWS to build\NEWS
112+
copy ..\Misc\NEWS build\NEWS > nul
113+
) else if exist ..\Misc\NEWS.D (
114+
if defined BLURB (
115+
echo.Merging Misc/NEWS with %BLURB%
116+
%BLURB% merge -f build\NEWS
117+
) else (
118+
echo.No Misc/NEWS file and Blurb is not available.
119+
exit /B 1
120+
)
121+
)
122+
99123
if NOT "%PAPER%" == "" (
100124
set SPHINXOPTS=-D latex_elements.papersize=%PAPER% %SPHINXOPTS%
101125
)

Lib/distutils/command/bdist_wininst.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,26 +318,30 @@ def get_exe_bytes(self):
318318
# string compares seem wrong, but are what sysconfig.py itself uses
319319
if self.target_version and self.target_version < cur_version:
320320
if self.target_version < "2.4":
321-
bv = 6.0
321+
bv = '6.0'
322322
elif self.target_version == "2.4":
323-
bv = 7.1
323+
bv = '7.1'
324324
elif self.target_version == "2.5":
325-
bv = 8.0
325+
bv = '8.0'
326326
elif self.target_version <= "3.2":
327-
bv = 9.0
327+
bv = '9.0'
328328
elif self.target_version <= "3.4":
329-
bv = 10.0
329+
bv = '10.0'
330330
else:
331-
bv = 14.0
331+
bv = '14.0'
332332
else:
333333
# for current version - use authoritative check.
334334
try:
335335
from msvcrt import CRT_ASSEMBLY_VERSION
336336
except ImportError:
337337
# cross-building, so assume the latest version
338-
bv = 14.0
338+
bv = '14.0'
339339
else:
340-
bv = float('.'.join(CRT_ASSEMBLY_VERSION.split('.', 2)[:2]))
340+
bv = '.'.join(CRT_ASSEMBLY_VERSION.split('.', 2)[:2])
341+
if bv == '14.11':
342+
# v141 and v140 are binary compatible,
343+
# so keep using the 14.0 stub.
344+
bv = '14.0'
341345

342346

343347
# wininst-x.y.exe is in the same directory as this file
@@ -353,7 +357,7 @@ def get_exe_bytes(self):
353357
else:
354358
sfix = ''
355359

356-
filename = os.path.join(directory, "wininst-%.1f%s.exe" % (bv, sfix))
360+
filename = os.path.join(directory, "wininst-%s%s.exe" % (bv, sfix))
357361
f = open(filename, "rb")
358362
try:
359363
return f.read()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Change to building with MSVC v141 (included with Visual Studio 2017)

PCbuild/build.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ if "%kill%"=="true" call :Kill
104104

105105
if "%do_pgo%"=="true" (
106106
set conf=PGInstrument
107-
call :Build
107+
call :Build %1 %2 %3 %4 %5 %6 %7 %8 %9
108108
del /s "%dir%\*.pgc"
109109
del /s "%dir%\..\Lib\*.pyc"
110110
echo on

PCbuild/find_msbuild.bat

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,21 @@
2929
@where msbuild > "%TEMP%\msbuild.loc" 2> nul && set /P MSBUILD= < "%TEMP%\msbuild.loc" & del "%TEMP%\msbuild.loc"
3030
@if exist "%MSBUILD%" set MSBUILD="%MSBUILD%" & (set _Py_MSBuild_Source=PATH) & goto :found
3131

32-
@rem VS 2017 sets exactly one install as the "main" install, so we may find MSBuild in there.
33-
@reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v 15.0 /reg:32 >nul 2>nul
34-
@if NOT ERRORLEVEL 1 @for /F "tokens=1,2*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v 15.0 /reg:32') DO @(
35-
@if "%%i"=="15.0" @if exist "%%k\MSBuild\15.0\Bin\msbuild.exe" @(set MSBUILD="%%k\MSBuild\15.0\Bin\msbuild.exe")
36-
)
37-
@if exist %MSBUILD% (set _Py_MSBuild_Source=Visual Studio 2017 registry) & goto :found
38-
3932
@rem VS 2015 and earlier register MSBuild separately, so we can find it.
33+
@rem Prefer MSBuild 14.0 over MSBuild 15.0, since the latter may not be able to find a VC14 install.
4034
@reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0" /v MSBuildToolsPath /reg:32 >nul 2>nul
4135
@if NOT ERRORLEVEL 1 @for /F "tokens=1,2*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0" /v MSBuildToolsPath /reg:32') DO @(
4236
@if "%%i"=="MSBuildToolsPath" @if exist "%%k\msbuild.exe" @(set MSBUILD="%%k\msbuild.exe")
4337
)
4438
@if exist %MSBUILD% (set _Py_MSBuild_Source=registry) & goto :found
4539

40+
@rem VS 2017 sets exactly one install as the "main" install, so we may find MSBuild in there.
41+
@reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v 15.0 /reg:32 >nul 2>nul
42+
@if NOT ERRORLEVEL 1 @for /F "tokens=1,2*" %%i in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v 15.0 /reg:32') DO @(
43+
@if "%%i"=="15.0" @if exist "%%k\MSBuild\15.0\Bin\msbuild.exe" @(set MSBUILD="%%k\MSBuild\15.0\Bin\msbuild.exe")
44+
)
45+
@if exist %MSBUILD% (set _Py_MSBuild_Source=Visual Studio 2017 registry) & goto :found
46+
4647

4748
@exit /b 1
4849

PCbuild/pyproject.props

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,28 @@ foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses
147147
Targets="CleanAll" />
148148
</Target>
149149

150+
<Target Name="CopyPGCFiles" BeforeTargets="PrepareForBuild" Condition="$(Configuration) == 'PGUpdate'">
151+
<ItemGroup>
152+
<_PGCFiles Include="$(OutDir)instrumented\$(TargetName)!*.pgc" />
153+
<_PGDFile Include="$(OutDir)instrumented\$(TargetName).pgd" />
154+
<_CopyFiles Include="@(_PGCFiles);@(_PGDFile)" Condition="Exists(%(FullPath))" />
155+
</ItemGroup>
156+
<Delete Files="@(_CopyFiles->'$(OutDir)%(Filename)%(Extension)')" />
157+
<Error Text="PGO run did not succeed (no $(TargetName)!*.pgc files) and there is no data to merge"
158+
Condition="$(RequirePGCFiles) == 'true' and @(_PGCFiles) == ''" />
159+
<Copy SourceFiles="@(_CopyFiles)"
160+
DestinationFolder="$(OutDir)"
161+
UseHardLinksIfPossible="true"
162+
OverwriteReadOnlyFiles="true" />
163+
</Target>
164+
150165
<PropertyGroup>
151-
<SdkBinPath Condition="'$(SdkBinPath)' == '' or !Exists($(SdkBinPath))">$(registry:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows Kits\Installed Roots@KitsRoot10)\bin\x86</SdkBinPath>
166+
<SdkBinPath Condition="'$(SdkBinPath)' == '' or !Exists($(SdkBinPath))">$(registry:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows Kits\Installed Roots@KitsRoot10)\bin\$(DefaultWindowsSDKVersion)\x86</SdkBinPath>
167+
<SdkBinPath Condition="!Exists($(SdkBinPath))">$(registry:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows Kits\Installed Roots@KitsRoot10)\bin\x86</SdkBinPath>
152168
<SdkBinPath Condition="!Exists($(SdkBinPath))">$(registry:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows Kits\Installed Roots@KitsRoot81)\bin\x86</SdkBinPath>
153169
<SdkBinPath Condition="!Exists($(SdkBinPath))">$(registry:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows Kits\Installed Roots@KitsRoot)\bin\x86</SdkBinPath>
154170
<SdkBinPath Condition="!Exists($(SdkBinPath))">$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1A@InstallationFolder)\Bin\</SdkBinPath>
155-
<_SignCommand Condition="Exists($(SdkBinPath)) and '$(SigningCertificate)' != '' and $(SupportSigning)">"$(SdkBinPath)\signtool.exe" sign /q /n "$(SigningCertificate)" /fd sha256 /t http://timestamp.verisign.com/scripts/timestamp.dll /d "Python $(PythonVersion)"</_SignCommand>
156-
<_MakeCatCommand Condition="Exists($(SdkBinPath))">"$(SdkBinPath)\makecat.exe"</_MakeCatCommand>
171+
<_SignCommand Condition="Exists($(SdkBinPath)) and '$(SigningCertificate)' != '' and $(SupportSigning)">"$(SdkBinPath)\signtool.exe" sign /q /a /n "$(SigningCertificate)" /fd sha256 /t http://timestamp.verisign.com/scripts/timestamp.dll /d "Python $(PythonVersion)"</_SignCommand> <_MakeCatCommand Condition="Exists($(SdkBinPath))">"$(SdkBinPath)\makecat.exe"</_MakeCatCommand>
157172
</PropertyGroup>
158173

159174
<Target Name="_SignBuild" AfterTargets="AfterBuild" Condition="'$(SigningCertificate)' != '' and $(SupportSigning)">

PCbuild/python.props

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1111
We set BasePlatformToolset for ICC's benefit, it's otherwise ignored.
1212
-->
13+
<BasePlatformToolset Condition="'$(BasePlatformToolset)' == '' and ('$(MSBuildToolsVersion)' == '15.0' or '$(VisualStudioVersion)' == '15.0')">v141</BasePlatformToolset>
1314
<BasePlatformToolset Condition="'$(BasePlatformToolset)' == '' and '$(VCTargetsPath14)' != ''">v140</BasePlatformToolset>
1415
<BasePlatformToolset Condition="'$(BasePlatformToolset)' == '' and '$(VCTargetsPath12)' != ''">v120</BasePlatformToolset>
1516
<BasePlatformToolset Condition="'$(BasePlatformToolset)' == '' and '$(VCTargetsPath11)' != ''">v110</BasePlatformToolset>
@@ -39,6 +40,7 @@
3940
<BuildPath Condition="'$(ArchName)' == 'amd64'">$(BuildPath64)</BuildPath>
4041
<BuildPath Condition="'$(BuildPath)' == ''">$(PySourcePath)PCBuild\$(ArchName)\</BuildPath>
4142
<BuildPath Condition="!HasTrailingSlash($(BuildPath))">$(BuildPath)\</BuildPath>
43+
<BuildPath Condition="$(Configuration) == 'PGInstrument'">$(BuildPath)instrumented\</BuildPath>
4244

4345
<!-- Directories of external projects. tcltk is handled in tcltk.props -->
4446
<ExternalsDir>$([System.IO.Path]::GetFullPath(`$(PySourcePath)externals\`))</ExternalsDir>
@@ -62,7 +64,24 @@
6264
<!-- Full path of the resulting python.exe binary -->
6365
<PythonExe Condition="'$(PythonExe)' == ''">$(BuildPath)python$(PyDebugExt).exe</PythonExe>
6466
</PropertyGroup>
65-
67+
68+
<PropertyGroup Condition="$(DefaultWindowsSDKVersion) == ''">
69+
<!--
70+
Attempt to select the latest installed WinSDK. If we don't find any, then we will
71+
let the MSBuild targets determine which one it wants to use (typically the earliest
72+
possible version). Since we limit WINVER to Windows 7 anyway, it doesn't really
73+
matter which WinSDK version we use.
74+
-->
75+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.15063'">10.0.15063.0</DefaultWindowsSDKVersion>
76+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.15063'">10.0.15063.0</DefaultWindowsSDKVersion>
77+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.14393'">10.0.14393.0</DefaultWindowsSDKVersion>
78+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.14393'">10.0.14393.0</DefaultWindowsSDKVersion>
79+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.10586'">10.0.10586.0</DefaultWindowsSDKVersion>
80+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.10586'">10.0.10586.0</DefaultWindowsSDKVersion>
81+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.10240'">10.0.10240.0</DefaultWindowsSDKVersion>
82+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.10240'">10.0.10240.0</DefaultWindowsSDKVersion>
83+
</PropertyGroup>
84+
6685
<PropertyGroup Condition="'$(OverrideVersion)' == ''">
6786
<!--
6887
Read version information from Include\patchlevel.h. The following properties are set:

PCbuild/python.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ set PYTHONPATH=$(PySourcePath)Lib
9696
<PropertyGroup>
9797
<_PGOPath Condition="$(Configuration) == 'PGInstrument' and $(Platform) == 'Win32'">@set PATH=%PATH%%3B$(VCInstallDir)bin</_PGOPath>
9898
<_PGOPath Condition="$(Configuration) == 'PGInstrument' and $(Platform) == 'x64'">@set PATH=%PATH%%3B$(VCInstallDir)bin\amd64</_PGOPath>
99+
<_PGOPath Condition="$(Configuration) == 'PGInstrument' and $(VC_PGO_RunTime_Dir) != ''">@set PATH=%PATH%%3B$(VC_PGO_RunTime_Dir)</_PGOPath>
99100
<_Content>@rem This script invokes the most recently built Python with all arguments
100101
@rem passed through to the interpreter. This file is generated by the
101102
@rem build process and any changes *will* be thrown away by the next

PCbuild/pythoncore.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
</ImportGroup>
5050
<PropertyGroup>
5151
<KillPython>true</KillPython>
52+
<RequirePGCFiles>true</RequirePGCFiles>
5253
</PropertyGroup>
5354
<ImportGroup Label="PropertySheets">
5455
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
@@ -428,7 +429,7 @@
428429
</ClCompile>
429430
</ItemGroup>
430431
</Target>
431-
<Target Name="_WarnAboutToolset" BeforeTargets="PrepareForBuild" Condition="$(PlatformToolset) != 'v140'">
432+
<Target Name="_WarnAboutToolset" BeforeTargets="PrepareForBuild" Condition="$(PlatformToolset) != 'v140' and $(PlatformToolset) != 'v141'">
432433
<Warning Text="Toolset $(PlatformToolset) is not used for official builds. Your build may have errors or incompatibilities." />
433434
</Target>
434435
</Project>

0 commit comments

Comments
 (0)