changeset 6373:7010e4557963

setup.py: hide compiler error messages while searching for inotify
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Sun, 23 Mar 2008 21:35:57 -0300
parents 8f79820443a4
children 31a01e3d99cc
files setup.py
diffstat 1 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py	Sun Mar 23 23:18:20 2008 +0100
+++ b/setup.py	Sun Mar 23 21:35:57 2008 -0300
@@ -24,20 +24,32 @@
 # that actually removes its temporary files.
 def has_function(cc, funcname):
     tmpdir = tempfile.mkdtemp(prefix='hg-install-')
+    devnull = oldstderr = None
     try:
-        fname = os.path.join(tmpdir, 'funcname.c')
-        f = open(fname, 'w')
-        f.write('int main(void) {\n')
-        f.write('    %s();\n' % funcname)
-        f.write('}\n')
-        f.close()
         try:
+            fname = os.path.join(tmpdir, 'funcname.c')
+            f = open(fname, 'w')
+            f.write('int main(void) {\n')
+            f.write('    %s();\n' % funcname)
+            f.write('}\n')
+            f.close()
+            # Redirect stderr to /dev/null to hide any error messages
+            # from the compiler.
+            # This will have to be changed if we ever have to check
+            # for a function on Windows.
+            devnull = open('/dev/null', 'w')
+            oldstderr = os.dup(sys.stderr.fileno())
+            os.dup2(devnull.fileno(), sys.stderr.fileno())
             objects = cc.compile([fname])
             cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
         except:
             return False
         return True
     finally:
+        if oldstderr is not None:
+            os.dup2(oldstderr, sys.stderr.fileno())
+        if devnull is not None:
+            devnull.close()
         shutil.rmtree(tmpdir)
 
 # py2exe needs to be installed to work