# HG changeset patch # User Jun Wu # Date 1490048888 25200 # Node ID 9639ff4a93ae3f47e36700efca988a9fd9841b5b # Parent 13dc00c233b7e374a6fa0b9846510a94c2615671 setup: split "hasfunction" to test arbitrary code The next patch wants to test include files. diff -r 13dc00c233b7 -r 9639ff4a93ae setup.py --- 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