diff --git a/packunused.cabal b/packunused.cabal index 40f0a82..efe9ec9 100644 --- a/packunused.cabal +++ b/packunused.cabal @@ -1,5 +1,5 @@ name: packunused -version: 0.1.1.1 +version: 0.1.1.2 synopsis: Tool for detecting redundant Cabal package dependencies homepage: https://github.com/hvr/packunused bug-reports: https://github.com/hvr/packunused/issues @@ -73,4 +73,5 @@ executable packunused cmdargs ==0.10.*, directory >=1.1 && <1.3, filepath ==1.3.*, - haskell-src-exts >=1.13 && <1.16 + haskell-src-exts >=1.13 && <1.16, + split ==0.2.* diff --git a/packunused.hs b/packunused.hs index 7e8ed85..a054698 100644 --- a/packunused.hs +++ b/packunused.hs @@ -4,6 +4,7 @@ module Main where import Control.Monad import Data.List +import Data.List.Split (splitOn) import Data.Maybe import Data.Version (Version(Version), showVersion) import Distribution.InstalledPackageInfo (exposedModules, installedPackageId) @@ -240,25 +241,31 @@ readImports outDir fn = do let m = MN.fromString $ take (length fn - length ".imports") fn - parseRes <- H.parseFileWithExts exts (outDir fn) - case parseRes of + contents <- readFile (outDir fn) + case parseImportsFile contents of (H.ParseOk (H.Module _ _ _ _ _ imps _)) -> do let imps' = [ (MN.fromString mn, extractSpecs (H.importSpecs imp)) | imp <- imps, let H.ModuleName mn = H.importModule imp ] return (m, imps') - H.ParseFailed {} -> do - print parseRes + H.ParseFailed loc msg -> do + putStrLn "*ERROR* failed to parse .imports file" + putStrLn $ H.prettyPrint loc ++ ": " ++ msg exitFailure where extractSpecs (Just (False, impspecs)) = map H.prettyPrint impspecs extractSpecs _ = error "unexpected import specs" + parseImportsFile = H.parseFileContentsWithMode (H.defaultParseMode { H.extensions = exts, H.parseFilename = outDir fn }) . stripExplicitNamespaces + + -- hack to remove -XExplicitNamespaces until haskell-src-exts supports that + stripExplicitNamespaces = unwords . splitOn " type " + #if MIN_VERSION_haskell_src_exts(1,14,0) - exts = map H.EnableExtension [ H.MagicHash, H.PackageImports, H.CPP, H.TypeOperators, H.TypeFamilies ] + exts = map H.EnableExtension [ H.MagicHash, H.PackageImports, H.CPP, H.TypeOperators, H.TypeFamilies {- , H.ExplicitNamespaces -} ] #else - exts = [ H.MagicHash, H.PackageImports, H.CPP, H.TypeOperators, H.TypeFamilies {- , H.ExplicitNamespaces -} ] + exts = [ H.MagicHash, H.PackageImports, H.CPP, H.TypeOperators, H.TypeFamilies ] #endif