Clarify why we can't run .bat files
[cabal.git] / cabal-testsuite / src / Test / Cabal / Workdir.hs
blobbbb545c6494af8b0fbb6b375ec1833d8025d6633
1 {-# LANGUAGE DataKinds #-}
3 -- | Functions for interrogating the current working directory
4 module Test.Cabal.Workdir where
6 import Distribution.Simple.Setup
7 import Distribution.Simple.Configure
8 import Distribution.Utils.Path
9 ( FileOrDir(..)
10 , Pkg
11 , Dist
12 , SymbolicPath
13 , makeSymbolicPath
14 , getSymbolicPath
17 import System.Directory
18 import System.FilePath
20 import System.Environment ( getExecutablePath )
22 -- | Guess what the dist directory of a running executable is,
23 -- by using the conventional layout of built executables
24 -- in relation to the top of a dist directory. Will not work
25 -- if the executable has been installed somewhere else.
26 guessDistDir :: IO (SymbolicPath Pkg (Dir Dist))
27 guessDistDir = do
28 exe_path <- canonicalizePath =<< getExecutablePath
29 let dist0 = dropFileName exe_path </> ".." </> ".."
30 b <- doesFileExist (dist0 </> "setup-config")
31 if b
32 then do
33 cwd <- getCurrentDirectory
34 dist1 <- canonicalizePath dist0
35 return $ makeSymbolicPath $ makeRelative (normalise cwd) dist1
36 else do
37 d <- getSymbolicPath <$> findDistPrefOrDefault NoFlag
38 makeSymbolicPath <$> canonicalizePath d