Patch extension DLL to match Python on Windows

So we can support any 3.x version like on the other platforms.

The Python 3.x ABI is stable so there is no need to build an extension
for each minor version. Due to the limited dynamic linking support on
Windows, however, there's no way around hard-coding the Python DLL name
in the extension it is compiled for.

As we don't expect users to install via easy_install on Python 3.x, but
assume they're using pip, we just have to tweak our setup.py so it fixes
up the extension after grabbing it from the .egg.
This commit is contained in:
Ole André Vadla Ravnås
2019-12-18 04:32:07 +01:00
parent eefb5e4930
commit 9671514a8b
+3
View File
@@ -11,6 +11,7 @@ except:
from StringIO import StringIO as BytesIO
import os
import platform
import re
from setuptools import setup
from setuptools.command.build_ext import build_ext
from setuptools.extension import Extension
@@ -135,6 +136,8 @@ class FridaPrebuiltExt(build_ext):
egg_zip = zipfile.ZipFile(egg_file)
extension_member = [info for info in egg_zip.infolist() if info.filename.endswith(target_extension)][0]
extension_data = egg_zip.read(extension_member)
if system == 'Windows' and python_major_version >= 3:
extension_data = re.sub(b"python[3-9][0-9].dll", "python{0}{1}.dll".format(*python_version).encode('utf-8'), extension_data)
with open(target, 'wb') as f:
f.write(extension_data)
else: