##// END OF EJS Templates
setup.py: use a simplified custom version of CCompiler.has_function...
Alexis S. L. Carvalho -
r6251:87053f0b default
parent child Browse files
Show More
@@ -10,6 +10,8 b" if not hasattr(sys, 'version_info') or s"
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
@@ -18,6 +20,26 b' import mercurial.version'
18
20
19 extra = {}
21 extra = {}
20
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)
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
@@ -70,7 +92,7 b' try:'
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'])
General Comments 0
You need to be logged in to leave comments. Login now