ghc-mod 3.0.0 → 3.0.1
raw patch · 8 files changed
+107/−41 lines, 8 filesdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Language.Haskell.GhcMod.Internal: (||>) :: Ghc a -> Ghc a -> Ghc a
+ Language.Haskell.GhcMod.Internal: (|||>) :: GhcMonad m => m a -> m a -> m a
+ Language.Haskell.GhcMod.Internal: cabalAllBuildInfo :: PackageDescription -> [BuildInfo]
+ Language.Haskell.GhcMod.Internal: cabalDependPackages :: [BuildInfo] -> [Package]
+ Language.Haskell.GhcMod.Internal: cabalSourceDirs :: [BuildInfo] -> [IncludeDir]
+ Language.Haskell.GhcMod.Internal: canCheckFast :: ModuleGraph -> Bool
+ Language.Haskell.GhcMod.Internal: fromCabalFile :: [GHCOption] -> Cradle -> IO ([GHCOption], [IncludeDir], [Package])
+ Language.Haskell.GhcMod.Internal: goNext :: Ghc a
+ Language.Haskell.GhcMod.Internal: initializeFlags :: GhcMonad m => Options -> m ()
+ Language.Haskell.GhcMod.Internal: parseCabalFile :: FilePath -> IO PackageDescription
+ Language.Haskell.GhcMod.Internal: runAnyOne :: [Ghc a] -> Ghc a
+ Language.Haskell.GhcMod.Internal: type IncludeDir = FilePath
+ Language.Haskell.GhcMod.Internal: type Package = String
- Language.Haskell.GhcMod.Internal: setTargetFiles :: GhcMonad m => [String] -> m ()
+ Language.Haskell.GhcMod.Internal: setTargetFiles :: GhcMonad m => [FilePath] -> m ()
Files
- ChangeLog +7/−1
- Language/Haskell/GhcMod/CabalApi.hs +51/−21
- Language/Haskell/GhcMod/GHCApi.hs +6/−2
- Language/Haskell/GhcMod/GHCChoice.hs +11/−9
- Language/Haskell/GhcMod/Internal.hs +24/−3
- Language/Haskell/GhcMod/Types.hs +3/−0
- ghc-mod.cabal +1/−1
- test/CabalApiSpec.hs +4/−4
ChangeLog view
@@ -1,6 +1,12 @@+2013-09-16 v3.0.1+ * Exporting more low level APIs.+ * Adding "-ibuild/autogen"+ * Adding "-optP". (Macros from a Cabal file+ and "dist/build/autogen/cabal_macros.h")+ 2013-09-06 v3.0.0 * Supporting the sandbox of cabal 1.18.- * Obsoleting the support for cabal-dev+ * Obsoleting the support for cabal-dev. 2013-09-04 v2.1.2 * Supporting multiple target files. (@nh2)
Language/Haskell/GhcMod/CabalApi.hs view
@@ -3,9 +3,9 @@ module Language.Haskell.GhcMod.CabalApi ( fromCabalFile , parseCabalFile- , cabalAllDependPackages- , cabalAllSourceDirs , cabalAllBuildInfo+ , cabalDependPackages+ , cabalSourceDirs , getGHCVersion ) where @@ -32,6 +32,9 @@ ---------------------------------------------------------------- +-- | Parsing a cabal file in 'Cradle' and returns+-- options for GHC, include directories for modules and+-- package names of dependency. fromCabalFile :: [GHCOption] -> Cradle -> IO ([GHCOption],[IncludeDir],[Package])@@ -41,7 +44,7 @@ where Just cfile = cradleCabalFile cradle -cookInfo :: [String] -> Cradle -> PackageDescription+cookInfo :: [GHCOption] -> Cradle -> PackageDescription -> ([GHCOption],[IncludeDir],[Package]) cookInfo ghcOptions cradle cabal = (gopts,idirs,depPkgs) where@@ -49,21 +52,41 @@ Just cdir = cradleCabalDir cradle Just cfile = cradleCabalFile cradle buildInfos = cabalAllBuildInfo cabal- gopts = getGHCOptions ghcOptions $ head buildInfos- idirs = includeDirectories cdir wdir $ cabalAllSourceDirs buildInfos- depPkgs = removeMe cfile $ cabalAllDependPackages buildInfos+ gopts = getGHCOptions ghcOptions cdir $ head buildInfos+ idirs = includeDirectories cdir wdir $ cabalSourceDirs buildInfos+ depPkgs = removeThem problematicPackages $ removeMe cfile $ cabalDependPackages buildInfos -removeMe :: FilePath -> [String] -> [String]+----------------------------------------------------------------+-- Dependent packages++removeMe :: FilePath -> [Package] -> [Package] removeMe cabalfile = filter (/= me) where me = dropExtension $ takeFileName cabalfile -includeDirectories :: String -> String -> [FilePath] -> [String]-includeDirectories cdir wdir [] = uniqueAndSort [cdir,wdir]-includeDirectories cdir wdir dirs = uniqueAndSort (map (cdir </>) dirs ++ [cdir,wdir])+removeThem :: [Package] -> [Package] -> [Package]+removeThem badpkgs = filter (`notElem` badpkgs) +problematicPackages :: [Package]+problematicPackages = [+ "base-compat" -- providing "Prelude"+ ]+ ----------------------------------------------------------------+-- Include directories for modules +cabalBuildDirs :: [FilePath]+cabalBuildDirs = ["dist/build"]++includeDirectories :: FilePath -> FilePath -> [FilePath] -> [FilePath]+includeDirectories cdir wdir dirs = uniqueAndSort (extdirs ++ [cdir,wdir])+ where+ extdirs = map (cdir </>) $ dirs ++ cabalBuildDirs++----------------------------------------------------------------++-- | Parsing a cabal file and returns 'PackageDescription'.+-- 'IOException' is thrown if parsing fails. parseCabalFile :: FilePath -> IO PackageDescription parseCabalFile file = do cid <- getGHCId@@ -81,16 +104,21 @@ ---------------------------------------------------------------- -getGHCOptions :: [String] -> BuildInfo -> [String]-getGHCOptions ghcOptions binfo = ghcOptions ++ exts ++ [lang] ++ libs ++ libDirs+getGHCOptions :: [GHCOption] -> FilePath -> BuildInfo -> [GHCOption]+getGHCOptions ghcOptions cdir binfo = ghcOptions ++ exts ++ [lang] ++ libs ++ libDirs ++ cpps where- exts = map (("-X" ++) . display) $ usedExtensions binfo lang = maybe "-XHaskell98" (("-X" ++) . display) $ defaultLanguage binfo- libs = map ("-l" ++) $ extraLibs binfo libDirs = map ("-L" ++) $ extraLibDirs binfo+ exts = map (("-X" ++) . display) $ usedExtensions binfo+ libs = map ("-l" ++) $ extraLibs binfo+ cpps = map ("-optP" ++) $ cppOptions binfo ++ cabalCppOptions cdir +cabalCppOptions :: FilePath -> [String]+cabalCppOptions dir = ["-include", dir </> "dist/build/autogen/cabal_macros.h"]+ ---------------------------------------------------------------- +-- | Extracting all 'BuildInfo' for libraries, executables, tests and benchmarks. cabalAllBuildInfo :: PackageDescription -> [BuildInfo] cabalAllBuildInfo pd = libBI ++ execBI ++ testBI ++ benchBI where@@ -101,16 +129,18 @@ ---------------------------------------------------------------- -cabalAllSourceDirs :: [BuildInfo] -> [FilePath]-cabalAllSourceDirs bis = uniqueAndSort $ concatMap hsSourceDirs bis--------------------------------------------------------------------cabalAllDependPackages :: [BuildInfo] -> [Package]-cabalAllDependPackages bis = uniqueAndSort $ pkgs+-- | Extracting package names of dependency.+cabalDependPackages :: [BuildInfo] -> [Package]+cabalDependPackages bis = uniqueAndSort $ pkgs where pkgs = map getDependencyPackageName $ concatMap targetBuildDepends bis getDependencyPackageName (Dependency (PackageName nm) _) = nm++----------------------------------------------------------------++-- | Extracting include directories for modules.+cabalSourceDirs :: [BuildInfo] -> [IncludeDir]+cabalSourceDirs bis = uniqueAndSort $ concatMap hsSourceDirs bis ----------------------------------------------------------------
Language/Haskell/GhcMod/GHCApi.hs view
@@ -96,6 +96,8 @@ ---------------------------------------------------------------- +-- | Initialize the 'DynFlags' relating to the compilation of a single+-- file or GHC session. initializeFlags :: GhcMonad m => Options -> m () initializeFlags opt = do dflags0 <- getSessionDynFlags@@ -146,7 +148,7 @@ ---------------------------------------------------------------- -modifyFlagsWithOpts :: GhcMonad m => DynFlags -> [String] -> m DynFlags+modifyFlagsWithOpts :: GhcMonad m => DynFlags -> [GHCOption] -> m DynFlags modifyFlagsWithOpts dflags cmdOpts = tfst <$> parseDynamicFlags dflags (map noLoc cmdOpts) where@@ -155,7 +157,7 @@ ---------------------------------------------------------------- -- | Set the files that GHC will load / compile.-setTargetFiles :: (GhcMonad m) => [String] -> m ()+setTargetFiles :: (GhcMonad m) => [FilePath] -> m () setTargetFiles [] = error "ghc-mod: setTargetFiles: No target files given" setTargetFiles files = do targets <- forM files $ \file -> guessTarget file Nothing@@ -167,6 +169,8 @@ getDynamicFlags :: IO DynFlags getDynamicFlags = runGhc (Just libdir) getSessionDynFlags +-- | Checking if Template Haskell or quasi quotes are used.+-- If not, the process can be faster. canCheckFast :: ModuleGraph -> Bool canCheckFast = not . any (hasTHorQQ . ms_hspp_opts) where
Language/Haskell/GhcMod/GHCChoice.hs view
@@ -9,20 +9,22 @@ ---------------------------------------------------------------- +-- | Try the left 'Ghc' action. If 'IOException' occurs, try+-- the right 'Ghc' action. (||>) :: Ghc a -> Ghc a -> Ghc a x ||> y = x `gcatch` (\(_ :: IOException) -> y) -(|||>) :: GhcMonad m => m a -> m a -> m a-x |||> y = x `gcatch` (\(_ :: IOException) -> y)--------------------------------------------------------------------{-| Go to the next 'Ghc' monad by throwing 'AltGhcgoNext'.--}+-- | Go to the next 'Ghc' monad by throwing 'AltGhcgoNext'. goNext :: Ghc a goNext = liftIO . throwIO $ userError "goNext" -{-| Run any one 'Ghc' monad.--}+-- | Run any one 'Ghc' monad. runAnyOne :: [Ghc a] -> Ghc a runAnyOne = foldr (||>) goNext++----------------------------------------------------------------++-- | Try the left 'GhcMonad' action. If 'IOException' occurs, try+-- the right 'GhcMonad' action.+(|||>) :: GhcMonad m => m a -> m a -> m a+x |||> y = x `gcatch` (\(_ :: IOException) -> y)
Language/Haskell/GhcMod/Internal.hs view
@@ -1,16 +1,37 @@ -- | Low level access to the ghc-mod library. module Language.Haskell.GhcMod.Internal (- -- * Low level access+ -- * Types LogReader , GHCOption+ , Package+ , IncludeDir+ -- * Cabal API+ , fromCabalFile+ , parseCabalFile+ , cabalAllBuildInfo+ , cabalDependPackages+ , cabalSourceDirs+ -- * GHC API+ , canCheckFast+ -- * Getting 'DynFlags'+ , getDynamicFlags+ -- * Initializing 'DynFlags'+ , initializeFlags , initializeFlagsWithCradle+ -- * 'GhcMonad' , setTargetFiles , checkSlowAndSet- , getDynamicFlags+ -- * 'Ghc' Choice+ , (||>)+ , goNext+ , runAnyOne+ -- * 'GhcMonad' Choice+ , (|||>) ) where +import Language.Haskell.GhcMod.CabalApi import Language.Haskell.GhcMod.ErrMsg import Language.Haskell.GhcMod.GHCApi+import Language.Haskell.GhcMod.GHCChoice import Language.Haskell.GhcMod.Types-
Language/Haskell/GhcMod/Types.hs view
@@ -94,7 +94,10 @@ -- | A single GHC option, as it would appear on the command line. type GHCOption = String +-- | Include directories for modules type IncludeDir = FilePath++-- | Package names type Package = String -- | GHC version in 'String'.
ghc-mod.cabal view
@@ -1,5 +1,5 @@ Name: ghc-mod-Version: 3.0.0+Version: 3.0.1 Author: Kazu Yamamoto <kazu@iij.ad.jp> Maintainer: Kazu Yamamoto <kazu@iij.ad.jp> License: BSD3
test/CabalApiSpec.hs view
@@ -13,14 +13,14 @@ it "throws an exception if the cabal file is broken" $ do parseCabalFile "test/data/broken-cabal/broken.cabal" `shouldThrow` (\(_::IOException) -> True) - describe "cabalAllDependPackages" $ do+ describe "cabalDependPackages" $ do it "extracts dependent packages" $ do- pkgs <- cabalAllDependPackages . cabalAllBuildInfo <$> parseCabalFile "test/data/cabalapi.cabal"+ pkgs <- cabalDependPackages . cabalAllBuildInfo <$> parseCabalFile "test/data/cabalapi.cabal" pkgs `shouldBe` ["Cabal","base","template-haskell"] - describe "cabalAllSourceDirs" $ do+ describe "cabalSourceDirs" $ do it "extracts all hs-source-dirs" $ do- dirs <- cabalAllSourceDirs . cabalAllBuildInfo <$> parseCabalFile "test/data/check-test-subdir/check-test-subdir.cabal"+ dirs <- cabalSourceDirs . cabalAllBuildInfo <$> parseCabalFile "test/data/check-test-subdir/check-test-subdir.cabal" dirs `shouldBe` ["src", "test"] describe "cabalBuildInfo" $ do