Last active
November 7, 2015 05:17
-
-
Save schoettl/b321baa5002ca48a46c5 to your computer and use it in GitHub Desktop.
Extract all hs-source-dirs from a cabal file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to use this program to set the path variable in Vim. I think I need this to get htags work...