packages feed

ghc-check 0.1.0.3 → 0.2.0.0

raw patch · 3 files changed

+33/−22 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- GHC.Check: compileTimeVersionFromLibdir :: IO FilePath -> TExpQ Version
- GHC.Check.Internal: compileTimeVersionFromLibdir :: IO FilePath -> TExpQ Version
- GHC.Check.Internal: getGhcVersionIO :: FilePath -> IO Version
+ GHC.Check: ghcCompileTimeVersion :: Version
+ GHC.Check.Internal: compileTimeVersion :: IO FilePath -> String -> TExpQ Version
+ GHC.Check.Internal: getPackageVersionIO :: FilePath -> String -> IO Version
- GHC.Check: compileTimeVersion :: Version
+ GHC.Check: compileTimeVersion :: IO FilePath -> String -> TExpQ Version

Files

ghc-check.cabal view
@@ -1,9 +1,9 @@ cabal-version:       1.20 build-type:          Simple name:                ghc-check-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+version:             0.2.0.0+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
@@ -3,7 +3,7 @@ ( VersionCheck(..) , checkGhcVersion , compileTimeVersion-, compileTimeVersionFromLibdir+, ghcCompileTimeVersion , runTimeVersion ) where @@ -11,12 +11,12 @@ import           GHC import           GHC.Check.Internal --- | 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 = $$(compileTimeVersionFromLibdir guessLibdir)+ghcCompileTimeVersion :: Version+ghcCompileTimeVersion = $$(compileTimeVersion guessLibdir "ghc") --- | Returns the run-time version of the 'ghc' package by looking up in the package database+-- | Returns the run-time version of the @ghc@ package in the package database runTimeVersion :: Ghc (Maybe Version) runTimeVersion = getGhcVersion @@ -27,11 +27,11 @@                }     deriving (Eq, Show) --- | Returns 'True' if the run-time version of the 'ghc' package matches the compile-time version---   For using your own GHC libdir at compile time, inline this logic in your program+-- | Checks if the run-time version of the @ghc@ package matches the compile-time version.+--   To be able to specify a custom libdir, inline this logic in your program. checkGhcVersion :: Ghc VersionCheck checkGhcVersion = do     v <- getGhcVersion-    return $ if v == Just compileTimeVersion+    return $ if v == Just ghcCompileTimeVersion         then GHC.Check.Match-        else Mismatch compileTimeVersion v+        else Mismatch ghcCompileTimeVersion v
src/GHC/Check/Internal.hs view
@@ -22,6 +22,8 @@ guessLibdir :: IO FilePath guessLibdir = fromMaybe GHC.Paths.libdir <$> lookupEnv "NIX_GHC_LIBDIR" +-- | @getPackageVersion p@ returns the version of package @p@ in+--     the package database getPackageVersion :: String -> Ghc (Maybe Version) getPackageVersion packageName = runMaybeT $ do     dflags <- Monad.lift getSessionDynFlags@@ -29,24 +31,33 @@     p <- MaybeT $ return $ lookupInstalledPackage dflags (componentIdToInstalledUnitId component)     return $ packageVersion p +-- | Returns the version of the @ghc@ package in the environment package database getGhcVersion :: Ghc (Maybe Version) getGhcVersion = getPackageVersion "ghc" -getGhcVersionIO :: FilePath -> IO Version-getGhcVersionIO libdir = runGhc (Just libdir) $ do+-- | @getPackageVersionIO ghc-libdir p@ returns the version of package @p@+--   in the default package database+getPackageVersionIO :: FilePath -> String -> IO Version+getPackageVersionIO libdir package = runGhc (Just libdir) $ do+    -- initialize the Ghc session+    -- there's probably a beteter way to do this.     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 <- getPackageVersion package+    case ver of+        Just v  ->+            return v+        Nothing ->+            error $ "Cannot find " <> package <> " in the package database at " <> libdir++-- | @compileTimeVersion get-libdir p@ returns the version of package @p@ in+--   the compile-time package database.+compileTimeVersion :: IO FilePath -> String -> TExpQ Version+compileTimeVersion getLibdir package = do     ver <- runIO $ do         libdir <- getLibdir-        v <- getGhcVersionIO libdir+        v <- getPackageVersionIO libdir package         return (toList v)     verLifted <- TH.lift (toList ver)     [|| fromList $$(pure $ TExp verLifted) ||]