55 raise SystemExit( |
55 raise SystemExit( |
56 "Couldn't import standard bz2 (incomplete Python install).") |
56 "Couldn't import standard bz2 (incomplete Python install).") |
57 |
57 |
58 ispypy = "PyPy" in sys.version |
58 ispypy = "PyPy" in sys.version |
59 |
59 |
|
60 import ctypes |
60 import os, stat, subprocess, time |
61 import os, stat, subprocess, time |
61 import re |
62 import re |
62 import shutil |
63 import shutil |
63 import tempfile |
64 import tempfile |
64 from distutils import log |
65 from distutils import log |
367 if os.name != 'nt': |
368 if os.name != 'nt': |
368 return |
369 return |
369 if isinstance(self.compiler, HackedMingw32CCompiler): |
370 if isinstance(self.compiler, HackedMingw32CCompiler): |
370 self.compiler.compiler_so = self.compiler.compiler # no -mdll |
371 self.compiler.compiler_so = self.compiler.compiler # no -mdll |
371 self.compiler.dll_libraries = [] # no -lmsrvc90 |
372 self.compiler.dll_libraries = [] # no -lmsrvc90 |
372 hv = sys.hexversion |
373 |
373 pythonlib = 'python%d%d' % (hv >> 24, (hv >> 16) & 0xff) |
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 with open('mercurial/hgpythonlib.h', 'wb') as f: |
401 with open('mercurial/hgpythonlib.h', 'wb') as f: |
375 f.write('/* this file is autogenerated by setup.py */\n') |
402 f.write('/* this file is autogenerated by setup.py */\n') |
376 f.write('#define HGPYTHONLIB "%s"\n' % pythonlib) |
403 f.write('#define HGPYTHONLIB "%s"\n' % pythonlib) |
377 objects = self.compiler.compile(['mercurial/exewrapper.c'], |
404 objects = self.compiler.compile(['mercurial/exewrapper.c'], |
378 output_dir=self.build_temp) |
405 output_dir=self.build_temp) |