
Cabal-helper looks like just the ticket, thanks!
On 11 Mar 2016 12:32, "Daniel Gröber"
On Fri, Mar 11, 2016 at 09:27:40AM +0000, David Turner wrote:
I've also briefly contemplated using the Cabal library to read my .cabal file and work out what to do, but I'm unsure that this would work nicely under stack. At least, I'm not sure quite what to do with all the package databases and other stuff that stack does for you.
Using the Cabal library to do this works very well in general, we do this in ghc-mod these days. The only way I've seen problems creep up so far is if cabal-install is linked against a different version of Cabal than your program. If your analysis program doesn't have to work on the same cabal dist directory as cabal-install (like ghc-mod does) then that's a non problem though.
Anyways we've wrapped all the ugly stuff to work around this problem into a library called cabal-helper:
http://hackage.haskell.org/package/cabal-helper/docs/Distribution-Helper.htm...
Here's a little example program using that library which should do what you want:
``` import System.Environment import System.Directory import System.Process import Distribution.Helper import Data.Char import Data.List
main = do [project_dir] <- getArgs setCurrentDirectory project_dir dist_dir <- dropWhileEnd isSpace <$> readProcess "stack" ["path", "--dist-dir"] "" print =<< (runQuery (defaultQueryEnv "." dist_dir) $ ghcOptions)
```
--Daniel