packages feed

ghc-check 0.1.0.2 → 0.1.0.3

raw patch · 3 files changed

+67/−43 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- GHC.Check.Internal: getGHCVersion :: Ghc (Maybe Version)
- GHC.Check.Internal: getGHCVersionIO :: IO Version
- GHC.Check.Internal: getLibdir :: IO FilePath
+ GHC.Check: Match :: VersionCheck
+ GHC.Check: Mismatch :: Version -> Maybe Version -> VersionCheck
+ GHC.Check: [compileTime] :: VersionCheck -> Version
+ GHC.Check: [runTime] :: VersionCheck -> Maybe Version
+ GHC.Check: compileTimeVersionFromLibdir :: IO FilePath -> TExpQ Version
+ GHC.Check: data VersionCheck
+ GHC.Check: instance GHC.Classes.Eq GHC.Check.VersionCheck
+ GHC.Check: instance GHC.Show.Show GHC.Check.VersionCheck
+ GHC.Check.Internal: compileTimeVersionFromLibdir :: IO FilePath -> TExpQ Version
+ GHC.Check.Internal: getGhcVersion :: Ghc (Maybe Version)
+ GHC.Check.Internal: getGhcVersionIO :: FilePath -> IO Version
+ GHC.Check.Internal: guessLibdir :: IO FilePath
- GHC.Check: checkGhcVersion :: Ghc Bool
+ GHC.Check: checkGhcVersion :: Ghc VersionCheck

Files

ghc-check.cabal view
@@ -1,9 +1,9 @@ cabal-version:       1.20 build-type:          Simple name:                ghc-check-version:             0.1.0.2-synopsis:            detect mismatches between compile-time and run-time versions of the ghc api-description:         detect mismatches between compile-time and run-time versions of the ghc api+version:             0.1.0.3+synopsis:            Detect mismatches between compile-time and run-time versions of the ghc api+description:         Detect mismatches between compile-time and run-time versions of the ghc api bug-reports:         https://github.com/pepeiborra/ghc-check/issues license:             BSD3 license-file:        LICENSE
src/GHC/Check.hs view
@@ -1,23 +1,37 @@ {-# LANGUAGE TemplateHaskell #-}-module GHC.Check (checkGhcVersion, compileTimeVersion, runTimeVersion) where+module GHC.Check+( VersionCheck(..)+, checkGhcVersion+, compileTimeVersion+, compileTimeVersionFromLibdir+, runTimeVersion+) where  import           Data.Version               (Version) import           GHC import           GHC.Check.Internal-import           GHC.Exts                   (IsList (fromList), toList)-import           Language.Haskell.TH-import           Language.Haskell.TH.Syntax (lift) --- | Returns the compile-time version of the 'ghc' package+-- | Returns the compile-time version of the 'ghc' package.+--   Uses 'guessLibdir' to find the GHC lib dir compileTimeVersion :: Version-compileTimeVersion = fromList $(lift =<< toList <$> runIO getGHCVersionIO)+compileTimeVersion = $$(compileTimeVersionFromLibdir guessLibdir)  -- | Returns the run-time version of the 'ghc' package by looking up in the package database runTimeVersion :: Ghc (Maybe Version)-runTimeVersion = getGHCVersion+runTimeVersion = getGhcVersion +data VersionCheck+    = Match+    | Mismatch { compileTime :: Version+               , runTime     :: Maybe Version+               }+    deriving (Eq, Show)+ -- | Returns 'True' if the run-time version of the 'ghc' package matches the compile-time version-checkGhcVersion :: Ghc Bool+--   For using your own GHC libdir at compile time, inline this logic in your program+checkGhcVersion :: Ghc VersionCheck checkGhcVersion = do-    v <- getPackageVersion "ghc"-    return (Just compileTimeVersion == v)+    v <- getGhcVersion+    return $ if v == Just compileTimeVersion+        then GHC.Check.Match+        else Mismatch compileTimeVersion v
src/GHC/Check/Internal.hs view
@@ -1,42 +1,52 @@ {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell #-} module GHC.Check.Internal where -import Control.Applicative-import GHC-import GHC.Paths-import Data.Version (makeVersion, Version)-import Data.Maybe (fromMaybe)-import System.Environment (lookupEnv)-import Packages (initPackages, lookupInstalledPackage, lookupPackageName, lookupPackage)-import PackageConfig (PackageName(PackageName))-import Maybes (runMaybeT, MaybeT(MaybeT))-import Module (componentIdToInstalledUnitId)-import Control.Monad.Trans.Class (MonadTrans(lift))-import Packages (InstalledPackageInfo(packageVersion))-import Control.Monad (join)-import Data.String (IsString(fromString))+import           Control.Monad.Trans.Class as Monad (MonadTrans (lift))+import           Data.Maybe                (fromMaybe)+import           Data.String               (IsString (fromString))+import           Data.Version              (Version)+import           GHC+import           GHC.Exts                   (IsList (fromList), toList)+import qualified GHC.Paths+import           Language.Haskell.TH+import           Language.Haskell.TH.Syntax as TH (TExp(TExp), lift)+import           Maybes                    (MaybeT (MaybeT), runMaybeT)+import           Module                    (componentIdToInstalledUnitId)+import           PackageConfig             (PackageName (PackageName))+import           Packages                  (lookupInstalledPackage, lookupPackageName)+import           Packages                  (InstalledPackageInfo (packageVersion))+import           System.Environment        (lookupEnv) --- Set the GHC libdir to the nix libdir if it's present.-getLibdir :: IO FilePath-getLibdir = fromMaybe GHC.Paths.libdir <$> lookupEnv "NIX_GHC_LIBDIR"+-- | Look up the GHC lib dir in the NIX environment, then in the 'GHC.Paths'+guessLibdir :: IO FilePath+guessLibdir = fromMaybe GHC.Paths.libdir <$> lookupEnv "NIX_GHC_LIBDIR"  getPackageVersion :: String -> Ghc (Maybe Version) getPackageVersion packageName = runMaybeT $ do-    dflags <- lift getSessionDynFlags+    dflags <- Monad.lift getSessionDynFlags     component <- MaybeT $ return $ lookupPackageName dflags $ PackageName $ fromString packageName     p <- MaybeT $ return $ lookupInstalledPackage dflags (componentIdToInstalledUnitId component)     return $ packageVersion p -getGHCVersion :: Ghc (Maybe Version)-getGHCVersion = getPackageVersion "ghc"+getGhcVersion :: Ghc (Maybe Version)+getGhcVersion = getPackageVersion "ghc" -getGHCVersionIO :: IO Version-getGHCVersionIO = do-    libdir <- getLibdir-    runGhc (Just libdir) $ do-        dflags <- getSessionDynFlags-        _ <- setSessionDynFlags dflags-        ghcV <- getGHCVersion-        case ghcV of-            Just v -> return v-            Nothing -> error "Cannot get version of ghc package"+getGhcVersionIO :: FilePath -> IO Version+getGhcVersionIO libdir = runGhc (Just libdir) $ do+    dflags <- getSessionDynFlags+    _ <- setSessionDynFlags dflags+    ghcV <- getGhcVersion+    case ghcV of+        Just v  -> return v+        Nothing -> error "Cannot get version of ghc package"++-- | Returns the compile-time version of the 'ghc' package given the GHC libdir+compileTimeVersionFromLibdir :: IO FilePath -> TExpQ Version+compileTimeVersionFromLibdir getLibdir = do+    ver <- runIO $ do+        libdir <- getLibdir+        v <- getGhcVersionIO libdir+        return (toList v)+    verLifted <- TH.lift (toList ver)+    [|| fromList $$(pure $ TExp verLifted) ||]