Mercurial > public > mercurial-scm > hg-stable
comparison setup.py @ 17225:a06e2681dd17 stable 2.3-rc
merge default into stable for 2.3 code freeze
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 18 Jul 2012 19:08:25 -0500 |
parents | d13f47c800fd |
children | bf5bb38bcc7c |
comparison
equal
deleted
inserted
replaced
17222:98823bd0d697 | 17225:a06e2681dd17 |
---|---|
21 | 21 |
22 # Solaris Python packaging brain damage | 22 # Solaris Python packaging brain damage |
23 try: | 23 try: |
24 import hashlib | 24 import hashlib |
25 sha = hashlib.sha1() | 25 sha = hashlib.sha1() |
26 except: | 26 except ImportError: |
27 try: | 27 try: |
28 import sha | 28 import sha |
29 except: | 29 except ImportError: |
30 raise SystemExit( | 30 raise SystemExit( |
31 "Couldn't import standard hashlib (incomplete Python install).") | 31 "Couldn't import standard hashlib (incomplete Python install).") |
32 | 32 |
33 try: | 33 try: |
34 import zlib | 34 import zlib |
35 except: | 35 except ImportError: |
36 raise SystemExit( | 36 raise SystemExit( |
37 "Couldn't import standard zlib (incomplete Python install).") | 37 "Couldn't import standard zlib (incomplete Python install).") |
38 | 38 |
39 # The base IronPython distribution (as of 2.7.1) doesn't support bz2 | 39 # The base IronPython distribution (as of 2.7.1) doesn't support bz2 |
40 isironpython = False | 40 isironpython = False |
41 try: | 41 try: |
42 isironpython = platform.python_implementation().lower().find("ironpython") != -1 | 42 isironpython = (platform.python_implementation() |
43 except: | 43 .lower().find("ironpython") != -1) |
44 except AttributeError: | |
44 pass | 45 pass |
45 | 46 |
46 if isironpython: | 47 if isironpython: |
47 sys.stderr.write("warning: IronPython detected (no bz2 support)\n") | 48 sys.stderr.write("warning: IronPython detected (no bz2 support)\n") |
48 else: | 49 else: |
49 try: | 50 try: |
50 import bz2 | 51 import bz2 |
51 except: | 52 except ImportError: |
52 raise SystemExit( | 53 raise SystemExit( |
53 "Couldn't import standard bz2 (incomplete Python install).") | 54 "Couldn't import standard bz2 (incomplete Python install).") |
54 | 55 |
55 import os, subprocess, time | 56 import os, subprocess, time |
56 import shutil | 57 import shutil |
62 from distutils.command.build_ext import build_ext | 63 from distutils.command.build_ext import build_ext |
63 from distutils.command.build_py import build_py | 64 from distutils.command.build_py import build_py |
64 from distutils.command.install_scripts import install_scripts | 65 from distutils.command.install_scripts import install_scripts |
65 from distutils.spawn import spawn, find_executable | 66 from distutils.spawn import spawn, find_executable |
66 from distutils.ccompiler import new_compiler | 67 from distutils.ccompiler import new_compiler |
68 from distutils import cygwinccompiler | |
67 from distutils.errors import CCompilerError, DistutilsExecError | 69 from distutils.errors import CCompilerError, DistutilsExecError |
68 from distutils.sysconfig import get_python_inc | 70 from distutils.sysconfig import get_python_inc |
69 from distutils.version import StrictVersion | 71 from distutils.version import StrictVersion |
70 | 72 |
71 convert2to3 = '--c2to3' in sys.argv | 73 convert2to3 = '--c2to3' in sys.argv |
105 devnull = open('/dev/null', 'w') | 107 devnull = open('/dev/null', 'w') |
106 oldstderr = os.dup(sys.stderr.fileno()) | 108 oldstderr = os.dup(sys.stderr.fileno()) |
107 os.dup2(devnull.fileno(), sys.stderr.fileno()) | 109 os.dup2(devnull.fileno(), sys.stderr.fileno()) |
108 objects = cc.compile([fname], output_dir=tmpdir) | 110 objects = cc.compile([fname], output_dir=tmpdir) |
109 cc.link_executable(objects, os.path.join(tmpdir, "a.out")) | 111 cc.link_executable(objects, os.path.join(tmpdir, "a.out")) |
110 except: | 112 except Exception: |
111 return False | 113 return False |
112 return True | 114 return True |
113 finally: | 115 finally: |
114 if oldstderr is not None: | 116 if oldstderr is not None: |
115 os.dup2(oldstderr, sys.stderr.fileno()) | 117 os.dup2(oldstderr, sys.stderr.fileno()) |
209 | 211 |
210 class hgbuild(build): | 212 class hgbuild(build): |
211 # Insert hgbuildmo first so that files in mercurial/locale/ are found | 213 # Insert hgbuildmo first so that files in mercurial/locale/ are found |
212 # when build_py is run next. | 214 # when build_py is run next. |
213 sub_commands = [('build_mo', None), | 215 sub_commands = [('build_mo', None), |
214 # We also need build_ext before build_py. Otherwise, when 2to3 is called (in | 216 |
215 # build_py), it will not find osutil & friends, thinking that those modules are | 217 # We also need build_ext before build_py. Otherwise, when 2to3 is |
216 # global and, consequently, making a mess, now that all module imports are | 218 # called (in build_py), it will not find osutil & friends, |
217 # global. | 219 # thinking that those modules are global and, consequently, making |
220 # a mess, now that all module imports are global. | |
221 | |
218 ('build_ext', build.has_ext_modules), | 222 ('build_ext', build.has_ext_modules), |
219 ] + build.sub_commands | 223 ] + build.sub_commands |
220 | 224 |
221 class hgbuildmo(build): | 225 class hgbuildmo(build): |
222 | 226 |
290 if ext.name.startswith("mercurial."): | 294 if ext.name.startswith("mercurial."): |
291 self.py_modules.append("mercurial.pure.%s" % ext.name[10:]) | 295 self.py_modules.append("mercurial.pure.%s" % ext.name[10:]) |
292 self.distribution.ext_modules = [] | 296 self.distribution.ext_modules = [] |
293 else: | 297 else: |
294 if not os.path.exists(os.path.join(get_python_inc(), 'Python.h')): | 298 if not os.path.exists(os.path.join(get_python_inc(), 'Python.h')): |
295 raise SystemExit("Python headers are required to build Mercurial") | 299 raise SystemExit('Python headers are required to build ' |
300 'Mercurial') | |
296 | 301 |
297 def find_modules(self): | 302 def find_modules(self): |
298 modules = build_py.find_modules(self) | 303 modules = build_py.find_modules(self) |
299 for module in modules: | 304 for module in modules: |
300 if module[0] == "mercurial.pure": | 305 if module[0] == "mercurial.pure": |
328 f = open(self._indexfilename, 'w') | 333 f = open(self._indexfilename, 'w') |
329 f.write('# this file is autogenerated by setup.py\n') | 334 f.write('# this file is autogenerated by setup.py\n') |
330 f.write('docs = ') | 335 f.write('docs = ') |
331 f.write(out) | 336 f.write(out) |
332 f.close() | 337 f.close() |
338 | |
339 class buildhgexe(build_ext): | |
340 description = 'compile hg.exe from mercurial/exewrapper.c' | |
341 | |
342 def build_extensions(self): | |
343 if os.name != 'nt': | |
344 return | |
345 objects = self.compiler.compile(['mercurial/exewrapper.c'], | |
346 output_dir=self.build_temp) | |
347 dir = os.path.dirname(self.get_ext_fullpath('dummy')) | |
348 target = os.path.join(dir, 'hg') | |
349 self.compiler.link_executable(objects, target, | |
350 output_dir=self.build_temp) | |
333 | 351 |
334 class hginstallscripts(install_scripts): | 352 class hginstallscripts(install_scripts): |
335 ''' | 353 ''' |
336 This is a specialization of install_scripts that replaces the @LIBDIR@ with | 354 This is a specialization of install_scripts that replaces the @LIBDIR@ with |
337 the configured directory for modules. If possible, the path is made relative | 355 the configured directory for modules. If possible, the path is made relative |
380 cmdclass = {'build': hgbuild, | 398 cmdclass = {'build': hgbuild, |
381 'build_mo': hgbuildmo, | 399 'build_mo': hgbuildmo, |
382 'build_ext': hgbuildext, | 400 'build_ext': hgbuildext, |
383 'build_py': hgbuildpy, | 401 'build_py': hgbuildpy, |
384 'build_hgextindex': buildhgextindex, | 402 'build_hgextindex': buildhgextindex, |
385 'install_scripts': hginstallscripts} | 403 'install_scripts': hginstallscripts, |
386 | 404 'build_hgexe': buildhgexe, |
387 packages = ['mercurial', 'mercurial.hgweb', | 405 } |
388 'mercurial.httpclient', 'mercurial.httpclient.tests', | 406 |
407 packages = ['mercurial', 'mercurial.hgweb', 'mercurial.httpclient', | |
389 'hgext', 'hgext.convert', 'hgext.highlight', 'hgext.zeroconf', | 408 'hgext', 'hgext.convert', 'hgext.highlight', 'hgext.zeroconf', |
390 'hgext.largefiles'] | 409 'hgext.largefiles'] |
391 | 410 |
392 pymodules = [] | 411 pymodules = [] |
393 | 412 |
408 if sys.platform == 'win32' and sys.version_info < (2, 5, 0, 'final'): | 427 if sys.platform == 'win32' and sys.version_info < (2, 5, 0, 'final'): |
409 pymodules.append('mercurial.pure.osutil') | 428 pymodules.append('mercurial.pure.osutil') |
410 else: | 429 else: |
411 extmodules.append(Extension('mercurial.osutil', ['mercurial/osutil.c'], | 430 extmodules.append(Extension('mercurial.osutil', ['mercurial/osutil.c'], |
412 extra_link_args=osutil_ldflags)) | 431 extra_link_args=osutil_ldflags)) |
432 | |
433 # the -mno-cygwin option has been deprecated for years | |
434 Mingw32CCompiler = cygwinccompiler.Mingw32CCompiler | |
435 | |
436 class HackedMingw32CCompiler(cygwinccompiler.Mingw32CCompiler): | |
437 def __init__(self, *args, **kwargs): | |
438 Mingw32CCompiler.__init__(self, *args, **kwargs) | |
439 for i in 'compiler compiler_so linker_exe linker_so'.split(): | |
440 try: | |
441 getattr(self, i).remove('-mno-cygwin') | |
442 except ValueError: | |
443 pass | |
444 | |
445 cygwinccompiler.Mingw32CCompiler = HackedMingw32CCompiler | |
413 | 446 |
414 if sys.platform.startswith('linux') and os.uname()[2] > '2.6': | 447 if sys.platform.startswith('linux') and os.uname()[2] > '2.6': |
415 # The inotify extension is only usable with Linux 2.6 kernels. | 448 # The inotify extension is only usable with Linux 2.6 kernels. |
416 # You also need a reasonably recent C library. | 449 # You also need a reasonably recent C library. |
417 # In any case, if it fails to build the error will be skipped ('optional'). | 450 # In any case, if it fails to build the error will be skipped ('optional'). |