setup.py
changeset 6251 87053f0b0fad
parent 6245 0d0939b2d272
child 6373 7010e4557963
equal deleted inserted replaced
6250:bf0dd23f55fa 6251:87053f0b0fad
     8 import sys
     8 import sys
     9 if not hasattr(sys, 'version_info') or sys.version_info < (2, 3, 0, 'final'):
     9 if not hasattr(sys, 'version_info') or sys.version_info < (2, 3, 0, 'final'):
    10     raise SystemExit, "Mercurial requires python 2.3 or later."
    10     raise SystemExit, "Mercurial requires python 2.3 or later."
    11 
    11 
    12 import os
    12 import os
       
    13 import shutil
       
    14 import tempfile
    13 from distutils.core import setup, Extension
    15 from distutils.core import setup, Extension
    14 from distutils.command.install_data import install_data
    16 from distutils.command.install_data import install_data
    15 from distutils.ccompiler import new_compiler
    17 from distutils.ccompiler import new_compiler
    16 
    18 
    17 import mercurial.version
    19 import mercurial.version
    18 
    20 
    19 extra = {}
    21 extra = {}
       
    22 
       
    23 # simplified version of distutils.ccompiler.CCompiler.has_function
       
    24 # that actually removes its temporary files.
       
    25 def has_function(cc, funcname):
       
    26     tmpdir = tempfile.mkdtemp(prefix='hg-install-')
       
    27     try:
       
    28         fname = os.path.join(tmpdir, 'funcname.c')
       
    29         f = open(fname, 'w')
       
    30         f.write('int main(void) {\n')
       
    31         f.write('    %s();\n' % funcname)
       
    32         f.write('}\n')
       
    33         f.close()
       
    34         try:
       
    35             objects = cc.compile([fname])
       
    36             cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
       
    37         except:
       
    38             return False
       
    39         return True
       
    40     finally:
       
    41         shutil.rmtree(tmpdir)
    20 
    42 
    21 # py2exe needs to be installed to work
    43 # py2exe needs to be installed to work
    22 try:
    44 try:
    23     import py2exe
    45     import py2exe
    24 
    46 
    68 
    90 
    69     if sys.platform == 'linux2' and os.uname()[2] > '2.6':
    91     if sys.platform == 'linux2' and os.uname()[2] > '2.6':
    70         # The inotify extension is only usable with Linux 2.6 kernels.
    92         # The inotify extension is only usable with Linux 2.6 kernels.
    71         # You also need a reasonably recent C library.
    93         # You also need a reasonably recent C library.
    72         cc = new_compiler()
    94         cc = new_compiler()
    73         if cc.has_function('inotify_add_watch'):
    95         if has_function(cc, 'inotify_add_watch'):
    74             ext_modules.append(Extension('hgext.inotify.linux._inotify',
    96             ext_modules.append(Extension('hgext.inotify.linux._inotify',
    75                                          ['hgext/inotify/linux/_inotify.c']))
    97                                          ['hgext/inotify/linux/_inotify.c']))
    76             packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
    98             packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
    77 except ImportError:
    99 except ImportError:
    78     pass
   100     pass