Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-47103: Copy pgort140.dll into output directory when building PGInstrument on Windows #32083

Merged
merged 4 commits into from Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1201,20 +1201,11 @@ def tmpdir_with_python(self, subdir=None):

if MS_WINDOWS:
# Copy pythonXY.dll (or pythonXY_d.dll)
ver = sys.version_info
dll = f'python{ver.major}{ver.minor}'
dll3 = f'python{ver.major}'
if debug_build(sys.executable):
dll += '_d'
dll3 += '_d'
dll += '.dll'
dll3 += '.dll'
dll = os.path.join(os.path.dirname(self.test_exe), dll)
dll3 = os.path.join(os.path.dirname(self.test_exe), dll3)
dll_copy = os.path.join(tmpdir, os.path.basename(dll))
dll3_copy = os.path.join(tmpdir, os.path.basename(dll3))
shutil.copyfile(dll, dll_copy)
shutil.copyfile(dll3, dll3_copy)
import fnmatch
exedir = os.path.dirname(self.test_exe)
for f in os.listdir(exedir):
if fnmatch.fnmatch(f, '*.dll'):
shutil.copyfile(os.path.join(exedir, f), os.path.join(tmpdir, f))

# Copy Python program
exec_copy = os.path.join(tmpdir, os.path.basename(self.test_exe))
@@ -0,0 +1,2 @@
Windows ``PGInstrument`` builds now copy a required DLL into the output
directory, making it easier to run the profile stage of a PGO build.
@@ -133,9 +133,6 @@ set PYTHONPATH=$(PySourcePath)Lib
</Target>
<Target Name="GeneratePythonBat" AfterTargets="AfterBuild">
<PropertyGroup>
Copy link
Contributor

@neonene neonene Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<PropertyGroup>
<PropertyGroup>
<_PGOPath Condition="$(Configuration) == 'PGInstrument'">@set PATH=%PATH%%3B$(OutDir)</_PGOPath>

Copy link
Contributor

@neonene neonene Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving $(_PGOPath) like this fixes my errors. The way is more generic than #32146.

Copy link
Member Author

@zooba zooba Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, your other PR is better. We shouldn't rely on PATH for resolving DLLs, but should copy the right one alongside the executable.

Copy link
Member Author

@zooba zooba Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I see you've closed it, so I'll add a similar change to this PR.

Copy link
Contributor

@neonene neonene Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The additional change is perfect for PGO/non-PGO.
I can confirm PGInstrument builds work with this.

<_PGOPath Condition="$(Configuration) == 'PGInstrument' and $(Platform) == 'Win32'">@set PATH=%PATH%%3B$(VCInstallDir)bin</_PGOPath>
<_PGOPath Condition="$(Configuration) == 'PGInstrument' and $(Platform) == 'x64'">@set PATH=%PATH%%3B$(VCInstallDir)bin\amd64</_PGOPath>
<_PGOPath Condition="$(Configuration) == 'PGInstrument' and $(VC_PGO_RunTime_Dir) != ''">@set PATH=%PATH%%3B$(VC_PGO_RunTime_Dir)</_PGOPath>
<_Content>@rem This script invokes the most recently built Python with all arguments
@rem passed through to the interpreter. This file is generated by the
@rem build process and any changes *will* be thrown away by the next
@@ -145,11 +142,21 @@ set PYTHONPATH=$(PySourcePath)Lib
@echo Running $(Configuration)^|$(Platform) interpreter...
@setlocal
@set PYTHONHOME=$(PySourcePath)
$(_PGOPath)
@"$(OutDir)python$(PyDebugExt).exe" %*
</_Content>
<_ExistingContent Condition="Exists('$(PySourcePath)python.bat')">$([System.IO.File]::ReadAllText('$(PySourcePath)python.bat'))</_ExistingContent>
</PropertyGroup>
<WriteLinesToFile File="$(PySourcePath)python.bat" Lines="$(_Content)" Overwrite="true" Condition="'$(_Content)' != '$(_ExistingContent)'" />
</Target>
<Target Name="CopyPGORT" AfterTargets="Link" Condition="$(Configuration) == 'PGInstrument'">
<ItemGroup>
<_PGORT Include="$(VCToolsInstallDir)bin\Hostx86\x86\pgort140.dll" Condition="$(Platform) == 'Win32'" />
<_PGORT Include="$(VCToolsInstallDir)bin\Hostx64\x64\pgort140.dll" Condition="$(Platform) == 'x64'" />
<_PGORT Include="$(VCToolsInstallDir)bin\arm64\pgort140.dll" Condition="$(Platform) == 'ARM64'" />
</ItemGroup>
<Warning Text="Unable to locate pgort140.dll for $(Platform)." Condition="@(_PGORT) == '' or !Exists(@(_PGORT))" />
<Copy SourceFiles="@(_PGORT)" DestinationFolder="$(OutDir)">
<Output TaskParameter="CopiedFiles" ItemName="FileWrites" />
</Copy>
</Target>
</Project>