Skip to content

Commit 074da78

Browse files
authored
bpo-47103: Copy pgort140.dll into output directory when building PGInstrument on Windows (pythonGH-32083)
1 parent 35bcf9f commit 074da78

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

Lib/test/test_embed.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,20 +1206,11 @@ def tmpdir_with_python(self, subdir=None):
12061206

12071207
if MS_WINDOWS:
12081208
# Copy pythonXY.dll (or pythonXY_d.dll)
1209-
ver = sys.version_info
1210-
dll = f'python{ver.major}{ver.minor}'
1211-
dll3 = f'python{ver.major}'
1212-
if debug_build(sys.executable):
1213-
dll += '_d'
1214-
dll3 += '_d'
1215-
dll += '.dll'
1216-
dll3 += '.dll'
1217-
dll = os.path.join(os.path.dirname(self.test_exe), dll)
1218-
dll3 = os.path.join(os.path.dirname(self.test_exe), dll3)
1219-
dll_copy = os.path.join(tmpdir, os.path.basename(dll))
1220-
dll3_copy = os.path.join(tmpdir, os.path.basename(dll3))
1221-
shutil.copyfile(dll, dll_copy)
1222-
shutil.copyfile(dll3, dll3_copy)
1209+
import fnmatch
1210+
exedir = os.path.dirname(self.test_exe)
1211+
for f in os.listdir(exedir):
1212+
if fnmatch.fnmatch(f, '*.dll'):
1213+
shutil.copyfile(os.path.join(exedir, f), os.path.join(tmpdir, f))
12231214

12241215
# Copy Python program
12251216
exec_copy = os.path.join(tmpdir, os.path.basename(self.test_exe))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Windows ``PGInstrument`` builds now copy a required DLL into the output
2+
directory, making it easier to run the profile stage of a PGO build.

PCbuild/python.vcxproj

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ set PYTHONPATH=$(PySourcePath)Lib
133133
</Target>
134134
<Target Name="GeneratePythonBat" AfterTargets="AfterBuild">
135135
<PropertyGroup>
136-
<_PGOPath Condition="$(Configuration) == 'PGInstrument' and $(Platform) == 'Win32'">@set PATH=%PATH%%3B$(VCInstallDir)bin</_PGOPath>
137-
<_PGOPath Condition="$(Configuration) == 'PGInstrument' and $(Platform) == 'x64'">@set PATH=%PATH%%3B$(VCInstallDir)bin\amd64</_PGOPath>
138-
<_PGOPath Condition="$(Configuration) == 'PGInstrument' and $(VC_PGO_RunTime_Dir) != ''">@set PATH=%PATH%%3B$(VC_PGO_RunTime_Dir)</_PGOPath>
139136
<_Content>@rem This script invokes the most recently built Python with all arguments
140137
@rem passed through to the interpreter. This file is generated by the
141138
@rem build process and any changes *will* be thrown away by the next
@@ -145,11 +142,21 @@ set PYTHONPATH=$(PySourcePath)Lib
145142
@echo Running $(Configuration)^|$(Platform) interpreter...
146143
@setlocal
147144
@set PYTHONHOME=$(PySourcePath)
148-
$(_PGOPath)
149145
@"$(OutDir)python$(PyDebugExt).exe" %*
150146
</_Content>
151147
<_ExistingContent Condition="Exists('$(PySourcePath)python.bat')">$([System.IO.File]::ReadAllText('$(PySourcePath)python.bat'))</_ExistingContent>
152148
</PropertyGroup>
153149
<WriteLinesToFile File="$(PySourcePath)python.bat" Lines="$(_Content)" Overwrite="true" Condition="'$(_Content)' != '$(_ExistingContent)'" />
154150
</Target>
151+
<Target Name="CopyPGORT" AfterTargets="Link" Condition="$(Configuration) == 'PGInstrument'">
152+
<ItemGroup>
153+
<_PGORT Include="$(VCToolsInstallDir)bin\Hostx86\x86\pgort140.dll" Condition="$(Platform) == 'Win32'" />
154+
<_PGORT Include="$(VCToolsInstallDir)bin\Hostx64\x64\pgort140.dll" Condition="$(Platform) == 'x64'" />
155+
<_PGORT Include="$(VCToolsInstallDir)bin\arm64\pgort140.dll" Condition="$(Platform) == 'ARM64'" />
156+
</ItemGroup>
157+
<Warning Text="Unable to locate pgort140.dll for $(Platform)." Condition="@(_PGORT) == '' or !Exists(@(_PGORT))" />
158+
<Copy SourceFiles="@(_PGORT)" DestinationFolder="$(OutDir)">
159+
<Output TaskParameter="CopiedFiles" ItemName="FileWrites" />
160+
</Copy>
161+
</Target>
155162
</Project>

0 commit comments

Comments
 (0)