##// END OF EJS Templates
setup.py: hide compiler error messages while searching for inotify
Alexis S. L. Carvalho -
r6373:7010e455 default
parent child Browse files
Show More
@@ -1,121 +1,133
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 #
2 #
3 # This is the mercurial setup script.
3 # This is the mercurial setup script.
4 #
4 #
5 # 'python setup.py install', or
5 # 'python setup.py install', or
6 # 'python setup.py --help' for more options
6 # 'python setup.py --help' for more options
7
7
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
13 import shutil
14 import tempfile
14 import tempfile
15 from distutils.core import setup, Extension
15 from distutils.core import setup, Extension
16 from distutils.command.install_data import install_data
16 from distutils.command.install_data import install_data
17 from distutils.ccompiler import new_compiler
17 from distutils.ccompiler import new_compiler
18
18
19 import mercurial.version
19 import mercurial.version
20
20
21 extra = {}
21 extra = {}
22
22
23 # simplified version of distutils.ccompiler.CCompiler.has_function
23 # simplified version of distutils.ccompiler.CCompiler.has_function
24 # that actually removes its temporary files.
24 # that actually removes its temporary files.
25 def has_function(cc, funcname):
25 def has_function(cc, funcname):
26 tmpdir = tempfile.mkdtemp(prefix='hg-install-')
26 tmpdir = tempfile.mkdtemp(prefix='hg-install-')
27 devnull = oldstderr = None
28 try:
27 try:
29 try:
28 fname = os.path.join(tmpdir, 'funcname.c')
30 fname = os.path.join(tmpdir, 'funcname.c')
29 f = open(fname, 'w')
31 f = open(fname, 'w')
30 f.write('int main(void) {\n')
32 f.write('int main(void) {\n')
31 f.write(' %s();\n' % funcname)
33 f.write(' %s();\n' % funcname)
32 f.write('}\n')
34 f.write('}\n')
33 f.close()
35 f.close()
34 try:
36 # Redirect stderr to /dev/null to hide any error messages
37 # from the compiler.
38 # This will have to be changed if we ever have to check
39 # for a function on Windows.
40 devnull = open('/dev/null', 'w')
41 oldstderr = os.dup(sys.stderr.fileno())
42 os.dup2(devnull.fileno(), sys.stderr.fileno())
35 objects = cc.compile([fname])
43 objects = cc.compile([fname])
36 cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
44 cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
37 except:
45 except:
38 return False
46 return False
39 return True
47 return True
40 finally:
48 finally:
49 if oldstderr is not None:
50 os.dup2(oldstderr, sys.stderr.fileno())
51 if devnull is not None:
52 devnull.close()
41 shutil.rmtree(tmpdir)
53 shutil.rmtree(tmpdir)
42
54
43 # py2exe needs to be installed to work
55 # py2exe needs to be installed to work
44 try:
56 try:
45 import py2exe
57 import py2exe
46
58
47 # Help py2exe to find win32com.shell
59 # Help py2exe to find win32com.shell
48 try:
60 try:
49 import modulefinder
61 import modulefinder
50 import win32com
62 import win32com
51 for p in win32com.__path__[1:]: # Take the path to win32comext
63 for p in win32com.__path__[1:]: # Take the path to win32comext
52 modulefinder.AddPackagePath("win32com", p)
64 modulefinder.AddPackagePath("win32com", p)
53 pn = "win32com.shell"
65 pn = "win32com.shell"
54 __import__(pn)
66 __import__(pn)
55 m = sys.modules[pn]
67 m = sys.modules[pn]
56 for p in m.__path__[1:]:
68 for p in m.__path__[1:]:
57 modulefinder.AddPackagePath(pn, p)
69 modulefinder.AddPackagePath(pn, p)
58 except ImportError:
70 except ImportError:
59 pass
71 pass
60
72
61 extra['console'] = ['hg']
73 extra['console'] = ['hg']
62
74
63 except ImportError:
75 except ImportError:
64 pass
76 pass
65
77
66 # specify version string, otherwise 'hg identify' will be used:
78 # specify version string, otherwise 'hg identify' will be used:
67 version = ''
79 version = ''
68
80
69 class install_package_data(install_data):
81 class install_package_data(install_data):
70 def finalize_options(self):
82 def finalize_options(self):
71 self.set_undefined_options('install',
83 self.set_undefined_options('install',
72 ('install_lib', 'install_dir'))
84 ('install_lib', 'install_dir'))
73 install_data.finalize_options(self)
85 install_data.finalize_options(self)
74
86
75 mercurial.version.remember_version(version)
87 mercurial.version.remember_version(version)
76 cmdclass = {'install_data': install_package_data}
88 cmdclass = {'install_data': install_package_data}
77
89
78 ext_modules=[
90 ext_modules=[
79 Extension('mercurial.mpatch', ['mercurial/mpatch.c']),
91 Extension('mercurial.mpatch', ['mercurial/mpatch.c']),
80 Extension('mercurial.bdiff', ['mercurial/bdiff.c']),
92 Extension('mercurial.bdiff', ['mercurial/bdiff.c']),
81 Extension('mercurial.base85', ['mercurial/base85.c']),
93 Extension('mercurial.base85', ['mercurial/base85.c']),
82 Extension('mercurial.diffhelpers', ['mercurial/diffhelpers.c'])
94 Extension('mercurial.diffhelpers', ['mercurial/diffhelpers.c'])
83 ]
95 ]
84
96
85 packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert']
97 packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert']
86
98
87 try:
99 try:
88 import posix
100 import posix
89 ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
101 ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
90
102
91 if sys.platform == 'linux2' and os.uname()[2] > '2.6':
103 if sys.platform == 'linux2' and os.uname()[2] > '2.6':
92 # The inotify extension is only usable with Linux 2.6 kernels.
104 # The inotify extension is only usable with Linux 2.6 kernels.
93 # You also need a reasonably recent C library.
105 # You also need a reasonably recent C library.
94 cc = new_compiler()
106 cc = new_compiler()
95 if has_function(cc, 'inotify_add_watch'):
107 if has_function(cc, 'inotify_add_watch'):
96 ext_modules.append(Extension('hgext.inotify.linux._inotify',
108 ext_modules.append(Extension('hgext.inotify.linux._inotify',
97 ['hgext/inotify/linux/_inotify.c']))
109 ['hgext/inotify/linux/_inotify.c']))
98 packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
110 packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
99 except ImportError:
111 except ImportError:
100 pass
112 pass
101
113
102 setup(name='mercurial',
114 setup(name='mercurial',
103 version=mercurial.version.get_version(),
115 version=mercurial.version.get_version(),
104 author='Matt Mackall',
116 author='Matt Mackall',
105 author_email='mpm@selenic.com',
117 author_email='mpm@selenic.com',
106 url='http://selenic.com/mercurial',
118 url='http://selenic.com/mercurial',
107 description='Scalable distributed SCM',
119 description='Scalable distributed SCM',
108 license='GNU GPL',
120 license='GNU GPL',
109 scripts=['hg'],
121 scripts=['hg'],
110 packages=packages,
122 packages=packages,
111 ext_modules=ext_modules,
123 ext_modules=ext_modules,
112 data_files=[(os.path.join('mercurial', root),
124 data_files=[(os.path.join('mercurial', root),
113 [os.path.join(root, file_) for file_ in files])
125 [os.path.join(root, file_) for file_ in files])
114 for root, dirs, files in os.walk('templates')],
126 for root, dirs, files in os.walk('templates')],
115 cmdclass=cmdclass,
127 cmdclass=cmdclass,
116 options=dict(py2exe=dict(packages=['hgext']),
128 options=dict(py2exe=dict(packages=['hgext']),
117 bdist_mpkg=dict(zipdist=True,
129 bdist_mpkg=dict(zipdist=True,
118 license='COPYING',
130 license='COPYING',
119 readme='contrib/macosx/Readme.html',
131 readme='contrib/macosx/Readme.html',
120 welcome='contrib/macosx/Welcome.html')),
132 welcome='contrib/macosx/Welcome.html')),
121 **extra)
133 **extra)
General Comments 0
You need to be logged in to leave comments. Login now