Skip to content

Instantly share code, notes, and snippets.

@schoettl
Last active November 7, 2015 05:17
Show Gist options
  • Save schoettl/b321baa5002ca48a46c5 to your computer and use it in GitHub Desktop.
Save schoettl/b321baa5002ca48a46c5 to your computer and use it in GitHub Desktop.
Extract all hs-source-dirs from a cabal file
module Main (main) where
import System.Environment (getArgs)
import Data.Maybe (maybeToList)
import Data.List.Utils (uniq)
import Distribution.Verbosity (normal)
import Distribution.Package (Dependency)
import Distribution.PackageDescription
import Distribution.PackageDescription.Parse (readPackageDescription)
main :: IO ()
main = do
args <- getArgs
packageDescription <- readPackageDescription normal (head args)
mapM_ putStrLn $ extractHsSourceDirs packageDescription
extractHsSourceDirs :: GenericPackageDescription -> [FilePath]
extractHsSourceDirs d = uniq $ concatMap ($d) extractorFunctions
where
extractorFunctions =
[ getAllHsSourceDirs libBuildInfo . condLibraryAsList
, getAllHsSourceDirs buildInfo . condExecutables
, getAllHsSourceDirs testBuildInfo . condTestSuites
, getAllHsSourceDirs benchmarkBuildInfo . condBenchmarks
]
condLibraryAsList = map (\ x -> (Nothing, x)) . maybeToList . condLibrary
getAllHsSourceDirs :: (a -> BuildInfo) -> [(b, CondTree ConfVar [Dependency] a)] -> [FilePath]
getAllHsSourceDirs f = concatMap (hsSourceDirs . f . condTreeData . snd)
@schoettl
Copy link
Author

schoettl commented Nov 7, 2015

I want to use this program to set the path variable in Vim. I think I need this to get htags work...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment