Commit 1d3de4cf authored by Moritz Angermann's avatar Moritz Angermann
Browse files

Moves wordsWhen into Base, and adjusts names and types to be more descriptive.

parent aff54c85
......@@ -24,7 +24,7 @@ module Base (
-- * Miscellaneous utilities
bimap, minusOrd, intersectOrd, replaceEq, replace, quote, chunksOfSize,
replaceSeparators, decodeModule, encodeModule, unifyPath, (-/-),
versionToInt, removeFileIfExists, removeDirectoryIfExists
versionToInt, removeFileIfExists, removeDirectoryIfExists, wordsWhen
) where
import Control.Applicative
......@@ -238,3 +238,12 @@ removeFileIfExists f = liftIO . whenM (IO.doesFileExist f) $ IO.removeFile f
removeDirectoryIfExists :: FilePath -> Action ()
removeDirectoryIfExists d =
liftIO . whenM (IO.doesDirectoryExist d) $ IO.removeDirectoryRecursive d
-- | Split function. Splits a string @s@ into chunks
-- when the predicate @p@ holds. See: http://stackoverflow.com/a/4981265
wordsWhen :: (Char -> Bool) -> String -> [String]
wordsWhen p s =
case dropWhile p s of
"" -> []
s' -> w : wordsWhen p s''
where (w, s'') = break p s'
......@@ -98,7 +98,7 @@ builderPath builder = do
case (path, windows) of
("", _) -> return path
(p, True) -> fixAbsolutePathOnWindows (p -<.> exe)
(p, False) -> lookupInPath (p -<.> exe)
(p, False) -> lookupInPathOracle (p -<.> exe)
getBuilderPath :: Builder -> ReaderT a Action FilePath
getBuilderPath = lift . builderPath
......
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
module Oracles.AbsoluteCommand (
lookupInPath, absoluteCommandOracle
lookupInPathOracle, absoluteCommandOracle
) where
import Base
......@@ -8,25 +8,17 @@ import Base
newtype AbsoluteCommand = AbsoluteCommand String
deriving (Show, Typeable, Eq, Hashable, Binary, NFData)
absoluteCommand :: String -> Action String
-- | Fetches the absolute FilePath to a given FilePath from the
-- Oracle.
absoluteCommand :: FilePath -> Action FilePath
absoluteCommand = askOracle . AbsoluteCommand
-- | Lookup a @command@ in @PATH@ environment.
lookupInPath :: FilePath -> Action FilePath
lookupInPath c
lookupInPathOracle :: FilePath -> Action FilePath
lookupInPathOracle c
| c /= takeFileName c = return c
| otherwise = absoluteCommand c
-- | Split function. Splits a string @s@ into chunks
-- when the predicate @p@ holds. See: http://stackoverflow.com/a/4981265
wordsWhen :: (Char -> Bool) -> String -> [String]
wordsWhen p s =
case dropWhile p s of
"" -> []
s' -> w : wordsWhen p s''
where (w, s'') = break p s'
absoluteCommandOracle :: Rules ()
absoluteCommandOracle = do
o <- newCache $ \c -> do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment