diff --git a/cabal-install/Distribution/Client/FileMonitor.hs b/cabal-install/Distribution/Client/FileMonitor.hs index affe9c70e568e30eb0ea2ac60d02f1d81ea08060..c8c5c8486e376552fa70b91743ebfacbae9fdff7 100644 --- a/cabal-install/Distribution/Client/FileMonitor.hs +++ b/cabal-install/Distribution/Client/FileMonitor.hs @@ -24,6 +24,7 @@ module Distribution.Client.FileMonitor ( beginUpdateFileMonitor, matchFileGlob, + isTrivialFilePathGlob, ) where @@ -805,6 +806,14 @@ matchFileGlob root glob0 = go glob0 "" --TODO: [code cleanup] plausibly FilePathGlob and matchFileGlob should be -- moved into D.C.Glob and/or merged with similar functionality in Cabal. + +isTrivialFilePathGlob :: FilePathGlob -> Maybe FilePath +isTrivialFilePathGlob = go [] + where + go paths (GlobDir (Glob [Literal path]) globs) = go (path:paths) globs + go paths (GlobFile (Glob [Literal path])) = Just (joinPath (reverse (path:paths))) + go _ _ = Nothing + -- | We really want to avoid re-hashing files all the time. We already make -- the assumption that if a file mtime has not changed then we don't need to -- bother checking if the content hash has changed. We can apply the same diff --git a/cabal-install/Distribution/Client/RebuildMonad.hs b/cabal-install/Distribution/Client/RebuildMonad.hs index cf0f44e8648eef248d38a26acdd4b40638846a1d..c26c735a11f164b981f92949893deb2d331f8c6f 100644 --- a/cabal-install/Distribution/Client/RebuildMonad.hs +++ b/cabal-install/Distribution/Client/RebuildMonad.hs @@ -29,7 +29,8 @@ module Distribution.Client.RebuildMonad ( matchFileGlob, ) where -import Distribution.Client.FileMonitor +import Distribution.Client.FileMonitor hiding (matchFileGlob) +import qualified Distribution.Client.FileMonitor as FileMonitor (matchFileGlob) import Distribution.Simple.Utils (debug) import Distribution.Verbosity (Verbosity) @@ -107,3 +108,15 @@ rerunIfChanged verbosity rootDir monitor key action = do showReason MonitorFirstRun = "first run" showReason MonitorCorruptCache = "invalid cache file" + +-- | Utility to match a file glob against the file system, starting from a +-- given root directory. The results are all relative to the given root. +-- +-- Since this operates in the 'Rebuild' monad, it also monitrs the given glob +-- for changes. +-- +matchFileGlob :: FilePath -> FilePathGlob -> Rebuild [FilePath] +matchFileGlob root glob = do + monitorFiles [MonitorFileGlob glob] + liftIO $ FileMonitor.matchFileGlob root glob +