{-# LANGUAGE TypeSynonymInstances #-}{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE MultiParamTypeClasses #-}-- | Utility functions for reading cabal file fields through template haskell.moduleDistribution.PackageDescription.TH(-- * Template Haskell functionspackageVariable,packageVariableFrom,-- * Cabal file data structures-- | The data structures for the cabal file are re-exported here for ease of use.PackageDescription(..),PackageIdentifier(..),Version(..))whereimportDistribution.PackageDescriptionimportDistribution.PackageimportDistribution.VersionimportDistribution.Text(Text,display)importDistribution.Verbosity(silent)importDistribution.PackageDescription.Parse(readPackageDescription)importSystem.Directory(getCurrentDirectory,getDirectoryContents)importData.List(isSuffixOf)importLanguage.Haskell.TH(Q,Exp,stringE,runIO)-- | Renders the package variable specified by the function.-- The cabal file interrogated is the first one that is found -- in the current working directory.packageVariable::Texta=>(PackageDescription->a)->QExppackageVariable=renderFieldcurrentPackageDescription-- | Renders the package variable specified by the function, from a cabal file-- and the given path.packageVariableFrom::Texta=>FilePath->(PackageDescription->a)->QExppackageVariableFroms=renderField$fmappackageDescription(readPackageDescriptionsilents)------renderField::Textb=>IOa->(a->b)->QExprenderFieldpdf=runIOpd>>=stringE.display.fcurrentPackageDescription::IOPackageDescriptioncurrentPackageDescription=fmappackageDescription$dodir<-getCurrentDirectorycs<-cabalFilesdircasecsof(c:_)->readPackageDescriptionsilentc[]->error$"Couldn't find a cabal file in the current working directory ("++dir++")"cabalFiles::FilePath->IO[FilePath]cabalFilesdir=dofiles<-getDirectoryContentsdirreturn$filter(".cabal"`isSuffixOf`)files{-
Smart ways of getting the cabal file:
* Get this module name, use TH.location and loc_module. Parse each
cabal file in the cwd and look for references to this module
in each thing.
-}