on master help sign in
Use inotify flags only if the kernel supports them
commit9fd6f723039c5e984ea8402897c4f58d4c0e66cd authorHarendra Kumar <harendra@composewell.com> dateMon 17 Aug 2020, 04:11 (6 years ago) parent87700f6
8 files changed+114−15
configure+75−3 configure.ac+5−1 src/Streamly/Internal/Data/Time/Clock.hsc+1−1 src/Streamly/Internal/Data/Time/TimeSpec.hsc+1−1 src/Streamly/Internal/Data/Time/config-clock.h+1−1 src/Streamly/Internal/FileSystem/Event/Linux.hs+19−3 src/Streamly/Internal/Data/Time/config.h.in → src/config.h.in+9−1 streamly.cabal+3−4
configure+75−3
@@ -1435,6 +1435,52 @@ fi
14351435
14361436} # ac_fn_c_try_compile
14371437
1438+# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
1439+# ---------------------------------------------
1440+# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
1441+# accordingly.
1442+ac_fn_c_check_decl ()
1443+{
1444+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
1445+ as_decl_name=`echo $2|sed 's/ *(.*//'`
1446+ as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
1447+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
1448+$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
1449+if eval \${$3+:} false; then :
1450+ $as_echo_n "(cached) " >&6
1451+else
1452+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1453+/* end confdefs.h. */
1454+$4
1455+int
1456+main ()
1457+{
1458+#ifndef $as_decl_name
1459+#ifdef __cplusplus
1460+ (void) $as_decl_use;
1461+#else
1462+ (void) $as_decl_name;
1463+#endif
1464+#endif
1465+
1466+ ;
1467+ return 0;
1468+}
1469+_ACEOF
1470+if ac_fn_c_try_compile "$LINENO"; then :
1471+ eval "$3=yes"
1472+else
1473+ eval "$3=no"
1474+fi
1475+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
1476+fi
1477+eval ac_res=\$$3
1478+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
1479+$as_echo "$ac_res" >&6; }
1480+ eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
1481+
1482+} # ac_fn_c_check_decl
1483+
14381484# ac_fn_c_try_cpp LINENO
14391485# ----------------------
14401486# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
@@ -2109,7 +2155,7 @@ if test "${with_compiler+set}" = set; then :
21092155fi
21102156
21112157
2112−# Check headers and functions required
2158+# XXX Do this only for linux
21132159ac_ext=c
21142160ac_cpp='$CPP $CPPFLAGS'
21152161ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -2900,6 +2946,32 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
29002946ac_compiler_gnu=$ac_cv_c_compiler_gnu
29012947
29022948
2949+ac_fn_c_check_decl "$LINENO" "IN_MASK_CREATE" "ac_cv_have_decl_IN_MASK_CREATE" "#include <sys/inotify.h>
2950+"
2951+if test "x$ac_cv_have_decl_IN_MASK_CREATE" = xyes; then :
2952+ ac_have_decl=1
2953+else
2954+ ac_have_decl=0
2955+fi
2956+
2957+cat >>confdefs.h <<_ACEOF
2958+#define HAVE_DECL_IN_MASK_CREATE $ac_have_decl
2959+_ACEOF
2960+
2961+ac_fn_c_check_decl "$LINENO" "IN_EXCL_UNLINK" "ac_cv_have_decl_IN_EXCL_UNLINK" "#include <sys/inotify.h>
2962+"
2963+if test "x$ac_cv_have_decl_IN_EXCL_UNLINK" = xyes; then :
2964+ ac_have_decl=1
2965+else
2966+ ac_have_decl=0
2967+fi
2968+
2969+cat >>confdefs.h <<_ACEOF
2970+#define HAVE_DECL_IN_EXCL_UNLINK $ac_have_decl
2971+_ACEOF
2972+
2973+
2974+# Check headers and functions required
29032975ac_ext=c
29042976ac_cpp='$CPP $CPPFLAGS'
29052977ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -3322,7 +3394,7 @@ done
33223394
33233395
33243396# Output
3325−ac_config_headers="$ac_config_headers src/Streamly/Internal/Data/Time/config.h"
3397+ac_config_headers="$ac_config_headers src/config.h"
33263398
33273399cat >confcache <<\_ACEOF
33283400# This file is a shell script that caches the results of configure
@@ -3996,7 +4068,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
39964068for ac_config_target in $ac_config_targets
39974069do
39984070 case $ac_config_target in
3999− "src/Streamly/Internal/Data/Time/config.h") CONFIG_HEADERS="$CONFIG_HEADERS src/Streamly/Internal/Data/Time/config.h" ;;
4071+ "src/config.h") CONFIG_HEADERS="$CONFIG_HEADERS src/config.h" ;;
40004072
40014073 *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
40024074 esac
configure.ac+5−1
@@ -8,10 +8,14 @@ AC_INIT([streamly], [0.7.2], [streamly@composewell.com], [streamly])
88# To suppress "WARNING: unrecognized options: --with-compiler"
99AC_ARG_WITH([compiler], [GHC])
1010
11+# XXX Do this only for linux
12+AC_CHECK_DECLS([IN_MASK_CREATE],[],[],[#include <sys/inotify.h>])
13+AC_CHECK_DECLS([IN_EXCL_UNLINK],[],[],[#include <sys/inotify.h>])
14+
1115# Check headers and functions required
1216AC_CHECK_HEADERS([time.h])
1317AC_CHECK_FUNCS([clock_gettime])
1418
1519# Output
16−AC_CONFIG_HEADERS([src/Streamly/Internal/Data/Time/config.h])
20+AC_CONFIG_HEADERS([src/config.h])
1721AC_OUTPUT
src/Streamly/Internal/Data/Time/Clock.hsc+1−1
@@ -5,7 +5,7 @@
55#include "config.h"
66#endif
77
8−#include "config-clock.h"
8+#include "Streamly/Internal/Data/Time/config-clock.h"
99
1010-- |
1111-- Module : Streamly.Internal.Data.Time.Clock
src/Streamly/Internal/Data/Time/TimeSpec.hsc+1−1
@@ -7,7 +7,7 @@
77#include "config.h"
88#endif
99
10−#include "config-clock.h"
10+#include "Streamly/Internal/Data/Time/config-clock.h"
1111
1212-- |
1313-- Module : Streamly.Internal.Data.Time.TimeSpec
src/Streamly/Internal/Data/Time/config-clock.h+1−1
@@ -2,7 +2,7 @@
22#define HS_CLOCK_GHCJS 1
33#elif defined(_WIN32)
44#define HS_CLOCK_WINDOWS 1
5−#elif (defined (HAVE_TIME_H) && defined(HAVE_CLOCK_GETTIME))
5+#elif HAVE_TIME_H && HAVE_CLOCK_GETTIME
66#define HS_CLOCK_POSIX 1
77#elif __APPLE__
88#define HS_CLOCK_OSX 1
src/Streamly/Internal/FileSystem/Event/Linux.hs+19−3
@@ -19,6 +19,8 @@
1919-- 'Event' is an opaque type. Accessor functions (e.g. 'showEvent' above)
2020-- provided in this module are used to determine the attributes of the event.
2121--
22+-- Identical successive events may be coalesced into a single event.
23+--
2224-- =Design notes
2325--
2426-- For reference documentation see:
@@ -53,6 +55,9 @@
5355-- 4. On Linux 'watchPaths' fails if a path does not exist, on macOS it does
5456-- not fail.
5557
58+#include "config.h"
59+
60+#if HAVE_DECL_IN_EXCL_UNLINK
5661module Streamly.Internal.FileSystem.Event.Linux
5762 (
5863 -- * Subscribing to events
@@ -231,8 +236,11 @@ foreign import capi
231236setUnwatchMoved :: Toggle -> Config -> Config
232237setUnwatchMoved = setFlag iN_EXCL_UNLINK
233238
239+#if HAVE_DECL_IN_MASK_CREATE
234240foreign import capi
235241 "sys/inotify.h value IN_MASK_CREATE" iN_MASK_CREATE :: Word32
242+#endif
243+
236244foreign import capi
237245 "sys/inotify.h value IN_MASK_ADD" iN_MASK_ADD :: Word32
238246
@@ -242,9 +250,11 @@ foreign import capi
242250-- /Internal/
243251--
244252data WhenExists =
245− FailIfExists -- ^ Fail the API
246− | AddIfExists -- ^ Do not set an existing setting to 'Off' only set to 'On'
253+ AddIfExists -- ^ Do not set an existing setting to 'Off' only set to 'On'
247254 | ReplaceIfExists -- ^ Replace the existing settings with new settings
255+#if HAVE_DECL_IN_MASK_CREATE
256+ | FailIfExists -- ^ Fail the API
257+#endif
248258
249259-- | When adding a new path to the watch, specify what to do if a watch already
250260-- exists on that path.
@@ -256,9 +266,11 @@ data WhenExists =
256266setWhenExists :: WhenExists -> Config -> Config
257267setWhenExists val cfg =
258268 case val of
259− FailIfExists -> setFlag iN_MASK_CREATE On cfg
260269 AddIfExists -> setFlag iN_MASK_ADD On cfg
261270 ReplaceIfExists -> setFlag iN_MASK_ADD Off cfg
271+#if HAVE_DECL_IN_MASK_CREATE
272+ FailIfExists -> setFlag iN_MASK_CREATE On cfg
273+#endif
262274
263275foreign import capi
264276 "sys/inotify.h value IN_ONESHOT" iN_ONESHOT :: Word32
@@ -1010,3 +1022,7 @@ showEvent ev@Event{..} =
10101022 ++ "\n"
10111023
10121024 where showev f str = if f ev then "\n" ++ str else ""
1025+#else
1026+#warning "Disabling module Streamly.Internal.FileSystem.Event.Linux. Does not support kernels older than 2.6.36."
1027+module Streamly.Internal.FileSystem.Event.Linux () where
1028+#endif
src/Streamly/Internal/Data/Time/config.h.in → src/config.h.inrenamed+9−1
@@ -1,8 +1,16 @@
1−/* src/Streamly/Internal/Data/Time/config.h.in. Generated from configure.ac by autoheader. */
1+/* src/config.h.in. Generated from configure.ac by autoheader. */
22
33/* Define to 1 if you have the `clock_gettime' function. */
44#undef HAVE_CLOCK_GETTIME
55
6+/* Define to 1 if you have the declaration of `IN_EXCL_UNLINK', and to 0 if
7+ you don't. */
8+#undef HAVE_DECL_IN_EXCL_UNLINK
9+
10+/* Define to 1 if you have the declaration of `IN_MASK_CREATE', and to 0 if
11+ you don't. */
12+#undef HAVE_DECL_IN_MASK_CREATE
13+
614/* Define to 1 if you have the <inttypes.h> header file. */
715#undef HAVE_INTTYPES_H
816
streamly.cabal+3−4
@@ -145,7 +145,7 @@ extra-source-files:
145145 src/Streamly/Internal/Data/Array/PrimInclude.hs
146146 src/Streamly/Internal/Data/Array/Prim/TypesInclude.hs
147147 src/Streamly/Internal/Data/Array/Prim/MutTypesInclude.hs
148− src/Streamly/Internal/Data/Time/config.h.in
148+ src/config.h.in
149149 src/inline.hs
150150 stack.yaml
151151
@@ -153,7 +153,7 @@ extra-tmp-files:
153153 config.log
154154 config.status
155155 autom4te.cache
156− src/Streamly/Internal/Data/Time/config.h
156+ src/config.h
157157
158158source-repository head
159159 type: git
@@ -347,8 +347,7 @@ library
347347 default-extensions: QuantifiedConstraints
348348
349349 js-sources: jsbits/clock.js
350− include-dirs: src/Streamly/Internal/Data/Time
351− , src
350+ include-dirs: src
352351 if os(windows)
353352 c-sources: src/Streamly/Internal/Data/Time/Windows.c
354353 if os(darwin)