Mercurial > hg
comparison setup.py @ 43678:52e4bfebc4ba
setup: conditionalize access to `sys.dllhandle` when building extensions
This code is only run on Windows, and was crashing PyOxidizer when running in
`setup-py-install` mode. Now an oxidized binary can be built by simply pointing
to setup.py.
Something is slightly different now that it's not being built from a virtualenv.
Previously, `hg version` could print to the screen, but now it aborts saying
"Incorrect function". But I can see the output if redirected to a file, and
it's not complaining about missing C extensions, so I think those are loading
now (unlike from the virtualenv). The interesting this about this incorrect
function output is that it failed when initially built. I then went back and
did a `make clean` and `make local` with py3 and then py2 to ensure I didn't
break the existing code. At that point I ran the oxidized executable again and
it was able to print to the screen normally! So I ran `pyoxidizer build` again,
it only output the following, and then running the executable failed to output
again:
(pyO2_venv) C:\Users\Matt\hg3\hg_pyO2>pyoxidizer build
Finished dev [unoptimized + debuginfo] target(s) in 0.12s
packaging application into C:/Users/Matt/hg3/hg_pyO2\build\apps\hg_pyO2\x86_64-pc-windows-msvc\debug
purging C:/Users/Matt/hg3/hg_pyO2\build\apps\hg_pyO2\x86_64-pc-windows-msvc\debug
copying C:/Users/Matt/hg3/hg_pyO2\build\target\x86_64-pc-windows-msvc\debug\hg_pyO2.exe to
C:/Users/Matt/hg3/hg_pyO2\build\apps\hg_pyO2\x86_64-pc-windows-msvc\debug\hg_pyO2.exe
resolving packaging state...
writing license for [...]
hg_pyO2 packaged into C:/Users/Matt/hg3/hg_pyO2\build\apps\hg_pyO2\x86_64-pc-windows-msvc\debug
executable path: C:/Users/Matt/hg3/hg_pyO2\build\apps\hg_pyO2\x86_64-pc-windows-msvc\debug\hg_pyO2.exe
Differential Revision: https://phab.mercurial-scm.org/D7444
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 16 Nov 2019 12:19:43 -0500 |
parents | 6a5dc4d767a0 |
children | c7fc2d92067e |
comparison
equal
deleted
inserted
replaced
43676:6a5dc4d767a0 | 43678:52e4bfebc4ba |
---|---|
711 return | 711 return |
712 if isinstance(self.compiler, HackedMingw32CCompiler): | 712 if isinstance(self.compiler, HackedMingw32CCompiler): |
713 self.compiler.compiler_so = self.compiler.compiler # no -mdll | 713 self.compiler.compiler_so = self.compiler.compiler # no -mdll |
714 self.compiler.dll_libraries = [] # no -lmsrvc90 | 714 self.compiler.dll_libraries = [] # no -lmsrvc90 |
715 | 715 |
716 # Different Python installs can have different Python library | 716 pythonlib = None |
717 # names. e.g. the official CPython distribution uses pythonXY.dll | 717 |
718 # and MinGW uses libpythonX.Y.dll. | 718 if getattr(sys, 'dllhandle', None): |
719 _kernel32 = ctypes.windll.kernel32 | 719 # Different Python installs can have different Python library |
720 _kernel32.GetModuleFileNameA.argtypes = [ | 720 # names. e.g. the official CPython distribution uses pythonXY.dll |
721 ctypes.c_void_p, | 721 # and MinGW uses libpythonX.Y.dll. |
722 ctypes.c_void_p, | 722 _kernel32 = ctypes.windll.kernel32 |
723 ctypes.c_ulong, | 723 _kernel32.GetModuleFileNameA.argtypes = [ |
724 ] | 724 ctypes.c_void_p, |
725 _kernel32.GetModuleFileNameA.restype = ctypes.c_ulong | 725 ctypes.c_void_p, |
726 size = 1000 | 726 ctypes.c_ulong, |
727 buf = ctypes.create_string_buffer(size + 1) | 727 ] |
728 filelen = _kernel32.GetModuleFileNameA( | 728 _kernel32.GetModuleFileNameA.restype = ctypes.c_ulong |
729 sys.dllhandle, ctypes.byref(buf), size | 729 size = 1000 |
730 ) | 730 buf = ctypes.create_string_buffer(size + 1) |
731 | 731 filelen = _kernel32.GetModuleFileNameA( |
732 if filelen > 0 and filelen != size: | 732 sys.dllhandle, ctypes.byref(buf), size |
733 dllbasename = os.path.basename(buf.value) | 733 ) |
734 if not dllbasename.lower().endswith(b'.dll'): | 734 |
735 raise SystemExit( | 735 if filelen > 0 and filelen != size: |
736 'Python DLL does not end with .dll: %s' % dllbasename | 736 dllbasename = os.path.basename(buf.value) |
737 ) | 737 if not dllbasename.lower().endswith(b'.dll'): |
738 pythonlib = dllbasename[:-4] | 738 raise SystemExit( |
739 else: | 739 'Python DLL does not end with .dll: %s' % dllbasename |
740 ) | |
741 pythonlib = dllbasename[:-4] | |
742 | |
743 if not pythonlib: | |
740 log.warn( | 744 log.warn( |
741 'could not determine Python DLL filename; assuming pythonXY' | 745 'could not determine Python DLL filename; assuming pythonXY' |
742 ) | 746 ) |
743 | 747 |
744 hv = sys.hexversion | 748 hv = sys.hexversion |