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