setup: split "hasfunction" to test arbitrary code
The next patch wants to test include files.
--- a/setup.py Tue Mar 14 17:43:44 2017 -0700
+++ b/setup.py Mon Mar 20 15:28:08 2017 -0700
@@ -94,17 +94,13 @@
# We remove hg.bat if we are able to build hg.exe.
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
# from the compiler.
@@ -125,6 +121,12 @@
devnull.close()
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:
import py2exe