[PATCH 0 of 2] setup: don't build inotify extension when <sys/inotify.h> is too old
Christian Boos
cboos at neuf.fr
Mon Jun 21 02:53:08 CDT 2010
On 6/17/2010 3:58 AM, Renato Cunha wrote:
> Hello,
>
> On Wed, Jun 16, 2010 at 14:30,<cboos at neuf.fr> wrote:
>> This is admittedly because of my too old sys/inotify.h header,
>> or some other brokenness on my system, but as I don't want to use
>> the inotify extension anyway, I'd prefer to simply avoid building
>> inotify when it's anyway going to fail.
>>
>> To that end, I added an "hasflags" function, which reuses the
>> "hasfunction" code.
>
> The idea is interesting, as inotify is not a mercurial requirement.
> But wouldn't it be better if, instead of checking for arbitrary flags
> in some include files, it was possible for the build process to go on
> when non-core stuff failed building?
Thanks for the suggestion!
Here's a new patch, which ignore failures to build extensions marked as
optional (so only inotify currently), in the same way distutils does it
in Python 3.
Here's the code for build_ext.build_extensions() in Python 2.x:
def build_extensions(self):
# First, sanity-check the 'extensions' list
self.check_extensions_list(self.extensions)
for ext in self.extensions:
self.build_extension(ext)
Here's the corresponding method in Python 3.x versions:
def build_extensions(self):
# First, sanity-check the 'extensions' list
self.check_extensions_list(self.extensions)
for ext in self.extensions:
try:
self.build_extension(ext)
except (CCompilerError, DistutilsError, CompileError) as e:
if not ext.optional:
raise
self.warn('building extension "%s" failed: %s' %
(ext.name, e))
So I added something similar in setup.py.
# HG changeset patch
# User Christian Boos <cboos at neuf.fr>
# Date 1277106460 -7200
# Node ID ce6870449d03a18471aa145ae8065bf09942420a
# Parent 6f1d1ed3e19aaf4bfc14741956e0e6ff06fbe9d2
setup: ignore failure to build optional inotify extension
diff -r 6f1d1ed3e19a -r ce6870449d03 setup.py
--- a/setup.py Sun Jun 20 14:21:56 2010 -0500
+++ b/setup.py Mon Jun 21 09:47:40 2010 +0200
@@ -38,9 +38,11 @@
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 +211,20 @@
Distribution.global_options.append(('pure', None, "use pure (slow)
Python "
"code instead of C extensions"))
+class hgbuildext(build_ext):
+
+ def build_extensions(self):
+ # First, sanity-check the 'extensions' list
+ self.check_extensions_list(self.extensions)
+
+ for ext in self.extensions:
+ try:
+ self.build_extension(ext)
+ except CCompilerError:
+ if not hasattr(ext, 'optional') or not ext.optional:
+ raise
+ print>>sys.stderr, "Skipping optional '%s'" % ext.name
+
class hgbuildpy(build_py):
def finalize_options(self):
@@ -232,6 +248,7 @@
yield module
cmdclass = {'build_mo': hgbuildmo,
+ 'build_ext': hgbuildext,
'build_py': hgbuildpy}
packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert',
@@ -260,6 +277,7 @@
if hasfunction(cc, 'inotify_add_watch'):
extmodules.append(Extension('hgext.inotify.linux._inotify',
['hgext/inotify/linux/_inotify.c']))
+ extmodules[-1].optional = True
packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
packagedata = {'mercurial': ['locale/*/LC_MESSAGES/hg.mo',
More information about the Mercurial-devel
mailing list