setup.py
branchstable
changeset 11468 1c1126b1d919
parent 10905 13a1b2fb7ef2
child 11532 f3732ab1149f
equal deleted inserted replaced
11467:6b836d5c8c9e 11468:1c1126b1d919
    33         "Couldn't import standard bz2 (incomplete Python install).")
    33         "Couldn't import standard bz2 (incomplete Python install).")
    34 
    34 
    35 import os, subprocess, time
    35 import os, subprocess, time
    36 import shutil
    36 import shutil
    37 import tempfile
    37 import tempfile
       
    38 from distutils import log
    38 from distutils.core import setup, Extension
    39 from distutils.core import setup, Extension
    39 from distutils.dist import Distribution
    40 from distutils.dist import Distribution
    40 from distutils.command.build import build
    41 from distutils.command.build import build
       
    42 from distutils.command.build_ext import build_ext
    41 from distutils.command.build_py import build_py
    43 from distutils.command.build_py import build_py
    42 from distutils.spawn import spawn, find_executable
    44 from distutils.spawn import spawn, find_executable
    43 from distutils.ccompiler import new_compiler
    45 from distutils.ccompiler import new_compiler
       
    46 from distutils.errors import CCompilerError
    44 
    47 
    45 scripts = ['hg']
    48 scripts = ['hg']
    46 if os.name == 'nt':
    49 if os.name == 'nt':
    47     scripts.append('contrib/win32/hg.bat')
    50     scripts.append('contrib/win32/hg.bat')
    48 
    51 
   207 
   210 
   208 Distribution.pure = 0
   211 Distribution.pure = 0
   209 Distribution.global_options.append(('pure', None, "use pure (slow) Python "
   212 Distribution.global_options.append(('pure', None, "use pure (slow) Python "
   210                                     "code instead of C extensions"))
   213                                     "code instead of C extensions"))
   211 
   214 
       
   215 class hgbuildext(build_ext):
       
   216 
       
   217     def build_extension(self, ext):
       
   218         try:
       
   219             build_ext.build_extension(self, ext)
       
   220         except CCompilerError:
       
   221             if not hasattr(ext, 'optional') or not ext.optional:
       
   222                 raise
       
   223             log.warn("Failed to build optional extension '%s' (skipping)",
       
   224                      ext.name)
       
   225 
   212 class hgbuildpy(build_py):
   226 class hgbuildpy(build_py):
   213 
   227 
   214     def finalize_options(self):
   228     def finalize_options(self):
   215         build_py.finalize_options(self)
   229         build_py.finalize_options(self)
   216 
   230 
   230                     yield ("mercurial", module[1], module[2])
   244                     yield ("mercurial", module[1], module[2])
   231             else:
   245             else:
   232                 yield module
   246                 yield module
   233 
   247 
   234 cmdclass = {'build_mo': hgbuildmo,
   248 cmdclass = {'build_mo': hgbuildmo,
       
   249             'build_ext': hgbuildext,
   235             'build_py': hgbuildpy}
   250             'build_py': hgbuildpy}
   236 
   251 
   237 packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert',
   252 packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert',
   238             'hgext.highlight', 'hgext.zeroconf']
   253             'hgext.highlight', 'hgext.zeroconf']
   239 
   254 
   254     extmodules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
   269     extmodules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
   255 
   270 
   256 if sys.platform == 'linux2' and os.uname()[2] > '2.6':
   271 if sys.platform == 'linux2' and os.uname()[2] > '2.6':
   257     # The inotify extension is only usable with Linux 2.6 kernels.
   272     # The inotify extension is only usable with Linux 2.6 kernels.
   258     # You also need a reasonably recent C library.
   273     # You also need a reasonably recent C library.
       
   274     # In any case, if it fails to build the error will be skipped ('optional').
   259     cc = new_compiler()
   275     cc = new_compiler()
   260     if hasfunction(cc, 'inotify_add_watch'):
   276     if hasfunction(cc, 'inotify_add_watch'):
   261         extmodules.append(Extension('hgext.inotify.linux._inotify',
   277         inotify = Extension('hgext.inotify.linux._inotify',
   262                                      ['hgext/inotify/linux/_inotify.c']))
   278                             ['hgext/inotify/linux/_inotify.c'])
       
   279         inotify.optional = True
       
   280         extmodules.append(inotify)
   263         packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
   281         packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
   264 
   282 
   265 packagedata = {'mercurial': ['locale/*/LC_MESSAGES/hg.mo',
   283 packagedata = {'mercurial': ['locale/*/LC_MESSAGES/hg.mo',
   266                              'help/*.txt']}
   284                              'help/*.txt']}
   267 
   285