diff setup.py @ 32054:616e788321cc stable 4.2-rc

freeze: merge default into stable for 4.2 code freeze
author Augie Fackler <augie@google.com>
date Tue, 18 Apr 2017 12:24:34 -0400
parents 2243ba216f66
children efcaf6ab86f4
line wrap: on
line diff
--- a/setup.py	Tue Apr 18 11:22:42 2017 -0400
+++ b/setup.py	Tue Apr 18 12:24:34 2017 -0400
@@ -63,7 +63,10 @@
 import shutil
 import tempfile
 from distutils import log
-if 'FORCE_SETUPTOOLS' in os.environ:
+# We have issues with setuptools on some platforms and builders. Until
+# those are resolved, setuptools is opt-in except for platforms where
+# we don't have issues.
+if os.name == 'nt' or 'FORCE_SETUPTOOLS' in os.environ:
     from setuptools import setup
 else:
     from distutils.core import setup
@@ -91,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.
@@ -122,6 +121,16 @@
             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)
+
+def hasheader(cc, headername):
+    code = '#include <%s>\nint main(void) { return 0; }\n' % headername
+    return cancompile(cc, code)
+
 # py2exe needs to be installed to work
 try:
     import py2exe
@@ -367,7 +376,7 @@
             modulepolicy = 'c'
         with open("mercurial/__modulepolicy__.py", "w") as f:
             f.write('# this file is autogenerated by setup.py\n')
-            f.write('modulepolicy = "%s"\n' % modulepolicy)
+            f.write('modulepolicy = b"%s"\n' % modulepolicy)
 
         build_py.run(self)
 
@@ -581,11 +590,26 @@
 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):
+# platform specific macros
+for plat, func in [('bsd', 'setproctitle')]:
+    if re.search(plat, sys.platform) and hasfunction(new_compiler(), func):
         osutil_cflags.append('-DHAVE_%s' % func.upper())
 
+for plat, macro, code in [
+    ('bsd|darwin', 'BSD_STATFS', '''
+     #include <sys/param.h>
+     #include <sys/mount.h>
+     int main() { struct statfs s; return sizeof(s.f_fstypename); }
+     '''),
+    ('linux', 'LINUX_STATFS', '''
+     #include <linux/magic.h>
+     #include <sys/vfs.h>
+     int main() { struct statfs s; return sizeof(s.f_type); }
+     '''),
+]:
+    if re.search(plat, sys.platform) and cancompile(new_compiler(), code):
+        osutil_cflags.append('-DHAVE_%s' % macro)
+
 if sys.platform == 'darwin':
     osutil_ldflags += ['-framework', 'ApplicationServices']
 
@@ -658,7 +682,14 @@
             packagedata['mercurial'].append(f)
 
 datafiles = []
-setupversion = version
+
+# distutils expects version to be str/unicode. Converting it to
+# unicode on Python 2 still works because it won't contain any
+# non-ascii bytes and will be implicitly converted back to bytes
+# when operated on.
+assert isinstance(version, bytes)
+setupversion = version.decode('ascii')
+
 extra = {}
 
 if py2exeloaded: