Merge pull request #10662 from haskell/ulysses4ever-prerelease-cleanup-fixup
[cabal.git] / cabal-testsuite / src / Test / Cabal / Workdir.hs
blob148508eb606b89137a19bdd90eb8f77f13cbb3ba
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.Environment ( getExecutablePath )
19 import System.FilePath
21 -- | Guess what the dist directory of a running executable is,
22 -- by using the conventional layout of built executables
23 -- in relation to the top of a dist directory. Will not work
24 -- if the executable has been installed somewhere else.
25 guessDistDir :: IO (SymbolicPath Pkg (Dir Dist))
26 guessDistDir = do
27 exe_path <- canonicalizePath =<< getExecutablePath
28 let dist0 = dropFileName exe_path </> ".." </> ".."
29 b <- doesFileExist (dist0 </> "setup-config")
30 if b
31 then do
32 cwd <- getCurrentDirectory
33 dist1 <- canonicalizePath dist0
34 return $ makeSymbolicPath $ makeRelative (normalise cwd) dist1
35 else do
36 d <- getSymbolicPath <$> findDistPrefOrDefault NoFlag
37 makeSymbolicPath <$> canonicalizePath d