[PATCH 1 of 6] setup: split "hasfunction" to test arbitrary code

Jun Wu quark at fb.com
Tue Mar 21 00:04:34 UTC 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1490048888 25200
#      Mon Mar 20 15:28:08 2017 -0700
# Node ID 272f2d2a56cad143c899d4beb4b36610f68e6310
# Parent  44c591f634584c721778c5a77edeb04cd919ac43
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 272f2d2a56ca
setup: split "hasfunction" to test arbitrary code

The next patch wants to test include files.

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -95,15 +95,11 @@ if os.name == 'nt':
     scripts.append('contrib/win32/hg.bat')
 
-# simplified version of distutils.ccompiler.CCompiler.has_function
-# that actually removes its temporary files.
-def hasfunction(cc, funcname):
+def cancompile(cc, code):
     tmpdir = tempfile.mkdtemp(prefix='hg-install-')
     devnull = oldstderr = None
     try:
-        fname = os.path.join(tmpdir, 'funcname.c')
+        fname = os.path.join(tmpdir, 'testcomp.c')
         f = open(fname, 'w')
-        f.write('int main(void) {\n')
-        f.write('    %s();\n' % funcname)
-        f.write('}\n')
+        f.write(code)
         f.close()
         # Redirect stderr to /dev/null to hide any error messages
@@ -126,4 +122,10 @@ def hasfunction(cc, funcname):
         shutil.rmtree(tmpdir)
 
+# simplified version of distutils.ccompiler.CCompiler.has_function
+# that actually removes its temporary files.
+def hasfunction(cc, funcname):
+    code = 'int main(void) { %s(); }\n' % funcname
+    return cancompile(cc, code)
+
 # py2exe needs to be installed to work
 try:


More information about the Mercurial-devel mailing list