##// END OF EJS Templates
setup: detect Python DLL filename from loaded DLL...
Gregory Szorc -
r29020:ee2e4a2c stable
parent child Browse files
Show More
@@ -57,6 +57,7 b' else:'
57 57
58 58 ispypy = "PyPy" in sys.version
59 59
60 import ctypes
60 61 import os, stat, subprocess, time
61 62 import re
62 63 import shutil
@@ -369,8 +370,34 b' class buildhgexe(build_ext):'
369 370 if isinstance(self.compiler, HackedMingw32CCompiler):
370 371 self.compiler.compiler_so = self.compiler.compiler # no -mdll
371 372 self.compiler.dll_libraries = [] # no -lmsrvc90
372 hv = sys.hexversion
373 pythonlib = 'python%d%d' % (hv >> 24, (hv >> 16) & 0xff)
373
374 # Different Python installs can have different Python library
375 # names. e.g. the official CPython distribution uses pythonXY.dll
376 # and MinGW uses libpythonX.Y.dll.
377 _kernel32 = ctypes.windll.kernel32
378 _kernel32.GetModuleFileNameA.argtypes = [ctypes.c_void_p,
379 ctypes.c_void_p,
380 ctypes.c_ulong]
381 _kernel32.GetModuleFileNameA.restype = ctypes.c_ulong
382 size = 1000
383 buf = ctypes.create_string_buffer(size + 1)
384 filelen = _kernel32.GetModuleFileNameA(sys.dllhandle, ctypes.byref(buf),
385 size)
386
387 if filelen > 0 and filelen != size:
388 dllbasename = os.path.basename(buf.value)
389 if not dllbasename.lower().endswith('.dll'):
390 raise SystemExit('Python DLL does not end with .dll: %s' %
391 dllbasename)
392 pythonlib = dllbasename[:-4]
393 else:
394 log.warn('could not determine Python DLL filename; '
395 'assuming pythonXY')
396
397 hv = sys.hexversion
398 pythonlib = 'python%d%d' % (hv >> 24, (hv >> 16) & 0xff)
399
400 log.info('using %s as Python library name' % pythonlib)
374 401 with open('mercurial/hgpythonlib.h', 'wb') as f:
375 402 f.write('/* this file is autogenerated by setup.py */\n')
376 403 f.write('#define HGPYTHONLIB "%s"\n' % pythonlib)
General Comments 0
You need to be logged in to leave comments. Login now