Patchwork [1,of,2,V4] setup: test setproctitle before building osutil

login
register
mail settings
Submitter Jun Wu
Date Nov. 14, 2016, 4:35 p.m.
Message ID <98761d64eaaf67f3bdb9.1479141341@x1c>
Download mbox | patch
Permalink /patch/17563/
State Accepted
Headers show

Comments

Jun Wu - Nov. 14, 2016, 4:35 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1478897140 0
#      Fri Nov 11 20:45:40 2016 +0000
# Node ID 98761d64eaaf67f3bdb99f3f80a57910e2624b78
# Parent  038547a14d850f14ecd2671852093dc07848a134
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 98761d64eaaf
setup: test setproctitle before building osutil

We are going to use setproctitle (provided by FreeBSD) if it's available in
the next patch. Therefore provide a macro to give some clues to the C
pre-processor so it could choose code path wisely.

Patch

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -68,4 +68,5 @@  if 'FORCE_SETUPTOOLS' in os.environ:
 else:
     from distutils.core import setup
+from distutils.ccompiler import new_compiler
 from distutils.core import Command, Extension
 from distutils.dist import Distribution
@@ -554,6 +555,12 @@  common_depends = ['mercurial/bitmanipula
                   'mercurial/util.h']
 
+osutil_cflags = []
 osutil_ldflags = []
 
+# platform specific macros: HAVE_SETPROCTITLE
+for plat, func in [(re.compile('freebsd'), 'setproctitle')]:
+    if plat.search(sys.platform) and hasfunction(new_compiler(), func):
+        osutil_cflags.append('-DHAVE_%s' % func.upper())
+
 if sys.platform == 'darwin':
     osutil_ldflags += ['-framework', 'ApplicationServices']
@@ -576,4 +583,5 @@  extmodules = [
               depends=common_depends),
     Extension('mercurial.osutil', ['mercurial/osutil.c'],
+              extra_compile_args=osutil_cflags,
               extra_link_args=osutil_ldflags,
               depends=common_depends),