Mercurial > hg
changeset 31622:2243ba216f66
statfs: change Linux feature detection
Previously we check three things: "statfs" function, "linux/magic.h" and
"sys/vfs.h" headers. But we didn't check "struct statfs" or the "f_type"
field. That means if a system has "statfs" but "struct statfs" is not
defined in the two header files we check, or defined without the "f_type"
field, the compilation will fail.
This patch combines the checks (2 headers + 1 function + 1 field) together
and sets "HAVE_LINUX_STATFS". It makes setup.py faster (less checks), and
more reliable (immutable to the issue above).
author | Jun Wu <quark@fb.com> |
---|---|
date | Fri, 24 Mar 2017 14:59:19 -0700 |
parents | b26975483841 |
children | a01e1132f6fa |
files | mercurial/osutil.c setup.py |
diffstat | 2 files changed, 14 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/osutil.c Fri Mar 24 16:20:10 2017 -0700 +++ b/mercurial/osutil.c Fri Mar 24 14:59:19 2017 -0700 @@ -24,16 +24,14 @@ #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> -#ifdef HAVE_LINUX_MAGIC_H +#ifdef HAVE_LINUX_STATFS #include <linux/magic.h> +#include <sys/vfs.h> #endif #ifdef HAVE_BSD_STATFS #include <sys/mount.h> #include <sys/param.h> #endif -#ifdef HAVE_SYS_VFS_H -#include <sys/vfs.h> -#endif #endif #ifdef __APPLE__ @@ -796,7 +794,7 @@ } #endif /* ndef SETPROCNAME_USE_NONE */ -#ifdef HAVE_STATFS +#if defined(HAVE_BSD_STATFS) || defined(HAVE_LINUX_STATFS) /* given a directory path, return filesystem type (best-effort), or None */ const char *getfstype(const char *path) { #ifdef HAVE_BSD_STATFS @@ -810,10 +808,10 @@ r = statfs(path, &buf); if (r != 0) return NULL; -#ifdef HAVE_BSD_STATFS +#if defined(HAVE_BSD_STATFS) /* BSD or OSX provides a f_fstypename field */ return buf.f_fstypename; -#endif +#elif defined(HAVE_LINUX_STATFS) /* Begin of Linux filesystems */ #ifdef ADFS_SUPER_MAGIC if (buf.f_type == ADFS_SUPER_MAGIC) @@ -1084,6 +1082,7 @@ return "xfs"; #endif /* End of Linux filesystems */ +#endif /* def HAVE_LINUX_STATFS */ return NULL; } @@ -1100,7 +1099,7 @@ PyObject *result = Py_BuildValue("s", type); return result; } -#endif /* def HAVE_STATFS */ +#endif /* defined(HAVE_LINUX_STATFS) || defined(HAVE_BSD_STATFS) */ #endif /* ndef _WIN32 */ @@ -1278,7 +1277,7 @@ {"setprocname", (PyCFunction)setprocname, METH_VARARGS, "set process title (best-effort)\n"}, #endif -#ifdef HAVE_STATFS +#if defined(HAVE_BSD_STATFS) || defined(HAVE_LINUX_STATFS) {"getfstype", (PyCFunction)pygetfstype, METH_VARARGS, "get filesystem type (best-effort)\n"}, #endif
--- a/setup.py Fri Mar 24 16:20:10 2017 -0700 +++ b/setup.py Fri Mar 24 14:59:19 2017 -0700 @@ -591,24 +591,21 @@ osutil_ldflags = [] # platform specific macros -for plat, func in [('bsd', 'setproctitle'), ('bsd|darwin|linux', 'statfs')]: +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, header in [ - ('linux', 'linux/magic.h'), - ('linux', 'sys/vfs.h'), -]: - if re.search(plat, sys.platform) and hasheader(new_compiler(), header): - macro = header.replace('/', '_').replace('.', '_').upper() - osutil_cflags.append('-DHAVE_%s' % macro) - 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)