diff --git a/fsnotify.cabal b/fsnotify.cabal index 8bc6581..042f090 100644 --- a/fsnotify.cabal +++ b/fsnotify.cabal @@ -49,13 +49,11 @@ library , unix-compat >=0.2 default-language: Haskell2010 if os(linux) - cpp-options: -DOS_Linux + cpp-options: -DOS_Linux -DHAVE_NATIVE_WATCHER if os(windows) - cpp-options: -DOS_Win32 + cpp-options: -DOS_Win32 -DHAVE_NATIVE_WATCHER if os(darwin) - cpp-options: -DOS_Mac - if os(freebsd) || os(netbsd) || os(openbsd) - cpp-options: -DOS_BSD + cpp-options: -DOS_Mac -DHAVE_NATIVE_WATCHER if os(linux) other-modules: System.FSNotify.Linux @@ -103,13 +101,11 @@ executable example , unliftio default-language: Haskell2010 if os(linux) - cpp-options: -DOS_Linux + cpp-options: -DOS_Linux -DHAVE_NATIVE_WATCHER if os(windows) - cpp-options: -DOS_Win32 + cpp-options: -DOS_Win32 -DHAVE_NATIVE_WATCHER if os(darwin) - cpp-options: -DOS_Mac - if os(freebsd) || os(netbsd) || os(openbsd) - cpp-options: -DOS_BSD + cpp-options: -DOS_Mac -DHAVE_NATIVE_WATCHER test-suite tests type: exitcode-stdio-1.0 @@ -140,13 +136,11 @@ test-suite tests , unliftio >=0.2.20 default-language: Haskell2010 if os(linux) - cpp-options: -DOS_Linux + cpp-options: -DOS_Linux -DHAVE_NATIVE_WATCHER if os(windows) - cpp-options: -DOS_Win32 + cpp-options: -DOS_Win32 -DHAVE_NATIVE_WATCHER if os(darwin) - cpp-options: -DOS_Mac - if os(freebsd) || os(netbsd) || os(openbsd) - cpp-options: -DOS_BSD + cpp-options: -DOS_Mac -DHAVE_NATIVE_WATCHER if os(windows) build-depends: Win32 diff --git a/package.yaml b/package.yaml index c1ad00a..d811d77 100644 --- a/package.yaml +++ b/package.yaml @@ -16,13 +16,11 @@ extra-source-files: when: - condition: os(linux) - cpp-options: -DOS_Linux + cpp-options: -DOS_Linux -DHAVE_NATIVE_WATCHER - condition: os(windows) - cpp-options: -DOS_Win32 + cpp-options: -DOS_Win32 -DHAVE_NATIVE_WATCHER - condition: os(darwin) - cpp-options: -DOS_Mac -- condition: os(freebsd) || os(netbsd) || os(openbsd) - cpp-options: -DOS_BSD + cpp-options: -DOS_Mac -DHAVE_NATIVE_WATCHER default-extensions: - ScopedTypeVariables diff --git a/src/System/FSNotify.hs b/src/System/FSNotify.hs index 6b61fd4..60a6a83 100644 --- a/src/System/FSNotify.hs +++ b/src/System/FSNotify.hs @@ -110,10 +110,10 @@ data WatchManager = forall manager argType. FileListener manager argType => -- | Default configuration -- --- * Uses OS watch mode and single thread. +-- * Uses OS watch mode (if possible) and single thread. defaultConfig :: WatchConfig defaultConfig = WatchConfig { -#ifdef OS_BSD +#ifndef HAVE_NATIVE_WATCHER confWatchMode = WatchModePoll 500000 #else confWatchMode = WatchModeOS @@ -163,12 +163,12 @@ startManagerConf conf = do case confWatchMode conf of WatchModePoll interval -> WatchManager conf <$> liftIO (createPollManager interval) <*> globalWatchChan -#ifndef OS_BSD +#ifdef HAVE_NATIVE_WATCHER WatchModeOS -> liftIO (initSession ()) >>= createManager #endif where -#ifndef OS_BSD +#ifdef HAVE_NATIVE_WATCHER createManager :: Either T.Text NativeManager -> IO WatchManager createManager (Right nativeManager) = WatchManager conf nativeManager <$> globalWatchChan createManager (Left err) = throwIO $ userError $ T.unpack $ "Error: couldn't start native file manager: " <> err diff --git a/src/System/FSNotify/Types.hs b/src/System/FSNotify/Types.hs index 48dc2a7..00b7ace 100644 --- a/src/System/FSNotify/Types.hs +++ b/src/System/FSNotify/Types.hs @@ -61,10 +61,10 @@ data WatchMode = } -- ^ Detect changes by polling the filesystem. Less efficient and may miss fast changes. Not recommended -- unless you're experiencing problems with 'WatchModeOS' (or 'WatchModeOS' is not supported on your platform). -#ifndef OS_BSD +#ifdef HAVE_NATIVE_WATCHER | WatchModeOS -- ^ Use OS-specific mechanisms to be notified of changes (inotify on Linux, FSEvents on OSX, etc.). - -- Not currently available on *BSD. + -- Not currently available on e.g. *BSD and WASI. #endif data ThreadingMode = diff --git a/test/FSNotify/Test/EventTests.hs b/test/FSNotify/Test/EventTests.hs index bfc2368..4497162 100644 --- a/test/FSNotify/Test/EventTests.hs +++ b/test/FSNotify/Test/EventTests.hs @@ -29,7 +29,7 @@ eventTests :: ( MonadUnliftIO m, MonadThrow m ) => ThreadingMode -> SpecFree context m () eventTests threadingMode = describe "Tests" $ parallelWithoutDirectory $ do - let pollOptions = if isBSD then [True] else [False, True] + let pollOptions = if haveNativeWatcher then [False, True] else [True] forM_ pollOptions $ \poll -> describe (if poll then "Polling" else "Native") $ parallelWithoutDirectory $ do forM_ [False, True] $ \recursive -> describe (if recursive then "Recursive" else "Non-recursive") $ parallelWithoutDirectory $ diff --git a/test/FSNotify/Test/Util.hs b/test/FSNotify/Test/Util.hs index d0d392b..24e1b42 100644 --- a/test/FSNotify/Test/Util.hs +++ b/test/FSNotify/Test/Util.hs @@ -66,11 +66,11 @@ isLinux = True isLinux = False #endif -isBSD :: Bool -#ifdef OS_BSD -isBSD = True +haveNativeWatcher :: Bool +#ifdef HAVE_NATIVE_WATCHER +haveNativeWatcher = True #else -isBSD = False +haveNativeWatcher = False #endif waitUntil :: MonadUnliftIO m => Double -> m a -> m a @@ -132,7 +132,7 @@ withTestFolder threadingMode poll recursive nested setup action = do when (isMac || poll) $ threadDelay (max 1000000 pollInterval) let conf = defaultConfig { -#ifdef OS_BSD +#ifndef HAVE_NATIVE_WATCHER confWatchMode = if poll then WatchModePoll pollInterval else error "No native watcher available." #else confWatchMode = if poll then WatchModePoll pollInterval else WatchModeOS