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
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
))
27 exe_path
<- canonicalizePath
=<< getExecutablePath
28 let dist0
= dropFileName exe_path
</> ".." </> ".."
29 b
<- doesFileExist (dist0
</> "setup-config")
32 cwd
<- getCurrentDirectory
33 dist1
<- canonicalizePath dist0
34 return $ makeSymbolicPath
$ makeRelative
(normalise cwd
) dist1
36 d
<- getSymbolicPath
<$> findDistPrefOrDefault NoFlag
37 makeSymbolicPath
<$> canonicalizePath d