Make `check` recognise `main-is` in conditional branches (#9768)
[cabal.git] / Cabal / src / Distribution / Compat / Directory.hs
blob9698102842a8eb3d57ec6b25c1c37022a3b04abd
1 {-# LANGUAGE CPP #-}
3 module Distribution.Compat.Directory
4 ( listDirectory
5 , makeAbsolute
6 , doesPathExist
7 ) where
9 #if MIN_VERSION_directory(1,2,7)
10 import System.Directory as Dir hiding (doesPathExist)
11 import System.Directory (doesPathExist)
12 #else
13 import System.Directory as Dir
14 #endif
15 #if !MIN_VERSION_directory(1,2,2)
16 import System.FilePath as Path
17 #endif
19 #if !MIN_VERSION_directory(1,2,5)
21 listDirectory :: FilePath -> IO [FilePath]
22 listDirectory path =
23 filter f `fmap` Dir.getDirectoryContents path
24 where f filename = filename /= "." && filename /= ".."
26 #endif
28 #if !MIN_VERSION_directory(1,2,2)
30 makeAbsolute :: FilePath -> IO FilePath
31 makeAbsolute p | Path.isAbsolute p = return p
32 | otherwise = do
33 cwd <- Dir.getCurrentDirectory
34 return $ cwd </> p
36 #endif
38 #if !MIN_VERSION_directory(1,2,7)
40 doesPathExist :: FilePath -> IO Bool
41 doesPathExist path = do
42 -- not using Applicative, as this way we can do less IO
43 e <- doesDirectoryExist path
44 if e
45 then return True
46 else doesFileExist path
48 #endif