[PATCH 1 of 1] setup: ignore failures to build optional inotify extension

cboos at neuf.fr cboos at neuf.fr
Wed Jun 23 12:07:10 CDT 2010


# HG changeset patch
# User Christian Boos <cboos at neuf.fr>
# Date 1277293447 -7200
# Node ID 8f8114155c2b432a68a8fa5aa7b879d13428781a
# Parent  8b452fe4bf506a1a08bbc7e1bac81aceda8f4d10
setup: ignore failures to build optional inotify extension

diff -r 8b452fe4bf50 -r 8f8114155c2b setup.py
--- a/setup.py	Mon Jun 21 17:02:48 2010 -0300
+++ b/setup.py	Wed Jun 23 13:44:07 2010 +0200
@@ -35,12 +35,15 @@
 import os, subprocess, time
 import shutil
 import tempfile
+from distutils import log
 from distutils.core import setup, Extension
 from distutils.dist import Distribution
 from distutils.command.build import build
+from distutils.command.build_ext import build_ext
 from distutils.command.build_py import build_py
 from distutils.spawn import spawn, find_executable
 from distutils.ccompiler import new_compiler
+from distutils.errors import CCompilerError
 
 scripts = ['hg']
 if os.name == 'nt':
@@ -209,6 +212,17 @@
 Distribution.global_options.append(('pure', None, "use pure (slow) Python "
                                     "code instead of C extensions"))
 
+class hgbuildext(build_ext):
+
+    def build_extension(self, ext):
+        try:
+            build_ext.build_extension(self, ext)
+        except CCompilerError:
+            if not hasattr(ext, 'optional') or not ext.optional:
+                raise
+            log.warn("Failed to build optional extension '%s' (skipping)",
+                     ext.name)
+
 class hgbuildpy(build_py):
 
     def finalize_options(self):
@@ -232,6 +246,7 @@
                 yield module
 
 cmdclass = {'build_mo': hgbuildmo,
+            'build_ext': hgbuildext,
             'build_py': hgbuildpy}
 
 packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert',
@@ -256,10 +271,13 @@
 if sys.platform == 'linux2' and os.uname()[2] > '2.6':
     # The inotify extension is only usable with Linux 2.6 kernels.
     # You also need a reasonably recent C library.
+    # In any case, if it fails to build the error will be skipped ('optional').
     cc = new_compiler()
     if hasfunction(cc, 'inotify_add_watch'):
-        extmodules.append(Extension('hgext.inotify.linux._inotify',
-                                     ['hgext/inotify/linux/_inotify.c']))
+        inotify = Extension('hgext.inotify.linux._inotify',
+			    ['hgext/inotify/linux/_inotify.c'])
+        inotify.optional = True
+        extmodules.append(inotify)
         packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
 
 packagedata = {'mercurial': ['locale/*/LC_MESSAGES/hg.mo',


More information about the Mercurial-devel mailing list