cabal-helper 0.6.2.0 → 0.6.3.0
raw patch · 3 files changed
+81/−45 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Distribution.Helper: compilerVersion :: MonadIO m => Query m (String, Version)
+ Distribution.Helper: instance Control.Monad.Trans.Class.MonadTrans Distribution.Helper.Query
+ Distribution.Helper: prepare' :: MonadIO m => QueryEnv -> m ()
+ Distribution.Helper: writeAutogenFiles' :: MonadIO m => QueryEnv -> m ()
Files
- Distribution/Helper.hs +77/−43
- cabal-helper.cabal +2/−1
- tests/Spec.hs +2/−1
Distribution/Helper.hs view
@@ -48,6 +48,7 @@ , configFlags , nonDefaultConfigFlags , packageId+ , compilerVersion -- * Result types , ChModuleName(..)@@ -63,8 +64,10 @@ -- * Managing @dist/@ , prepare+ , prepare' , reconfigure , writeAutogenFiles+ , writeAutogenFiles' -- * $libexec related error handling , LibexecNotFoundError(..)@@ -79,6 +82,7 @@ import Control.Exception as E import Data.Char import Data.List+import Data.Maybe import Data.Version import Data.Typeable import Distribution.Simple.BuildPaths (exeExtension)@@ -154,7 +158,8 @@ slbiPkgLicenses :: [(String, [(String, Version)])], slbiFlags :: [(String, Bool)], slbiConfigFlags :: [(String, Bool)],- slbiNonDefaultConfigFlags :: [(String, Bool)]+ slbiNonDefaultConfigFlags :: [(String, Bool)],+ slbiCompilerVersion :: (String, Version) } deriving (Eq, Ord, Read, Show) -- | Caches helper executable result so it doesn't have to be run more than once@@ -164,6 +169,9 @@ (ReaderT QueryEnv m) a } deriving (Functor, Applicative, Monad, MonadIO) +instance MonadTrans Query where+ lift = Query . lift . lift+ type MonadQuery m = ( MonadIO m , MonadState (Maybe SomeLocalBuildInfo) m , MonadReader QueryEnv m)@@ -230,6 +238,9 @@ -- i.e. don't rely on these being the flags set by the user directly. nonDefaultConfigFlags :: MonadIO m => Query m [(String, Bool)] +-- | The version of GHC the project is configured to use+compilerVersion :: MonadIO m => Query m (String, Version)+ -- | Package identifier, i.e. package name and version packageId :: MonadIO m => Query m (String, Version) @@ -246,6 +257,7 @@ flags = Query $ slbiFlags `liftM` getSlbi configFlags = Query $ slbiConfigFlags `liftM` getSlbi nonDefaultConfigFlags = Query $ slbiNonDefaultConfigFlags `liftM` getSlbi+compilerVersion = Query $ slbiCompilerVersion `liftM` getSlbi packageId = Query $ getPackageId -- | Run @cabal configure@@@ -266,50 +278,57 @@ _ <- liftIO $ readProc (cabalProgram progs) ("configure":progOpts) "" return () ---invokeHelper :: MonadQuery m => [String] -> m [Maybe ChResponse]-invokeHelper args = ask >>= \QueryEnv {..} -> do- let progs = qePrograms- projdir = qeProjectDir- distdir = qeDistDir+readHelper :: (MonadIO m, MonadQuery m) => [String] -> m [Maybe ChResponse]+readHelper args = ask >>= \qe -> liftIO $ do+ out <- either error id <$> invokeHelper qe args+ let res = read out+ liftIO $ evaluate res `E.catch` \se@(SomeException _) -> do+ md <- lookupEnv' "CABAL_HELPER_DEBUG"+ let msg = "readHelper: exception: '" ++ show se ++ "'"+ error $ msg ++ case md of+ Nothing -> ", for more information set the environment variable CABAL_HELPER_DEBUG"+ Just _ -> ", output: '"++ out ++"'" - progArgs = [ "--with-ghc=" ++ ghcProgram progs- , "--with-ghc-pkg=" ++ ghcPkgProgram progs- , "--with-cabal=" ++ cabalProgram progs+invokeHelper :: QueryEnv -> [String] -> IO (Either String String)+invokeHelper QueryEnv {..} args = do+ let progArgs = [ "--with-ghc=" ++ ghcProgram qePrograms+ , "--with-ghc-pkg=" ++ ghcPkgProgram qePrograms+ , "--with-cabal=" ++ cabalProgram qePrograms ]+ exe <- findLibexecExe "cabal-helper-wrapper"+ let args' = progArgs ++ qeProjectDir:qeDistDir:args+ out <- qeReadProcess exe args' ""+ (Right <$> evaluate out) `E.catch` \(SomeException _) ->+ return $ Left $ concat+ ["invokeHelper", ": ", exe, " "+ , intercalate " " (map show args')+ , " failed"+ ] - liftIO $ do- exe <- findLibexecExe "cabal-helper-wrapper"- let args' = progArgs ++ projdir:distdir:args- out <- qeReadProcess exe args' ""- evaluate (read out) `E.catch` \(SomeException _) ->- error $ concat ["invokeHelper", ": ", exe, " "- , intercalate " " (map show args')- , " (read failed)"- ] getPackageId :: MonadQuery m => m (String, Version) getPackageId = ask >>= \QueryEnv {..} -> do- [ Just (ChResponseVersion pkgName pkgVer) ] <- invokeHelper [ "package-id" ]+ [ Just (ChResponseVersion pkgName pkgVer) ] <- readHelper [ "package-id" ] return (pkgName, pkgVer) getSomeConfigState :: MonadQuery m => m SomeLocalBuildInfo getSomeConfigState = ask >>= \QueryEnv {..} -> do- res <- invokeHelper [ "package-db-stack"- , "entrypoints"- , "source-dirs"- , "ghc-options"- , "ghc-src-options"- , "ghc-pkg-options"- , "ghc-merged-pkg-options"- , "ghc-lang-options"- , "licenses"- , "flags"- , "config-flags"- , "non-default-config-flags"- ]+ res <- readHelper+ [ "package-db-stack"+ , "entrypoints"+ , "source-dirs"+ , "ghc-options"+ , "ghc-src-options"+ , "ghc-pkg-options"+ , "ghc-merged-pkg-options"+ , "ghc-lang-options"+ , "licenses"+ , "flags"+ , "config-flags"+ , "non-default-config-flags"+ , "compiler-version"+ ] let [ Just (ChResponsePkgDbs pkgDbs), Just (ChResponseEntrypoints eps), Just (ChResponseCompList srcDirs),@@ -321,28 +340,31 @@ Just (ChResponseLicenses pkgLics), Just (ChResponseFlags fls), Just (ChResponseFlags cfls),- Just (ChResponseFlags ndcfls)+ Just (ChResponseFlags ndcfls),+ Just (ChResponseVersion comp compVer) ] = res return $ SomeLocalBuildInfo- pkgDbs eps srcDirs ghcOpts ghcSrcOpts ghcPkgOpts ghcMergedPkgOpts ghcLangOpts pkgLics fls cfls ndcfls+ pkgDbs eps srcDirs ghcOpts ghcSrcOpts ghcPkgOpts ghcMergedPkgOpts ghcLangOpts pkgLics fls cfls ndcfls (comp, compVer) --- | Make sure the appropriate helper executable for the given project is--- installed and ready to run queries. prepare :: MonadIO m => (FilePath -> [String] -> String -> IO String) -> FilePath- -- ^ Path to project directory, i.e. the one containing the- -- @project.cabal@ file -> FilePath- -- ^ Path to the @dist/@ directory -> m () prepare readProc projdir distdir = liftIO $ do exe <- findLibexecExe "cabal-helper-wrapper" void $ readProc exe [projdir, distdir] "" --- | Create @cabal_macros.h@ and @Paths_\<pkg\>@ possibly other generated files--- in the usual place.+{-# DEPRECATED prepare+ "Will be replaced by prepare' in the next major release" #-}++-- | Make sure the appropriate helper executable for the given project is+-- installed and ready to run queries.+prepare' :: MonadIO m => QueryEnv -> m ()+prepare' qe =+ liftIO $ void $ invokeHelper qe []+ writeAutogenFiles :: MonadIO m => (FilePath -> [String] -> String -> IO String) -> FilePath@@ -355,6 +377,15 @@ exe <- findLibexecExe "cabal-helper-wrapper" void $ readProc exe [projdir, distdir, "write-autogen-files"] "" +{-# DEPRECATED writeAutogenFiles+ "Will be replaced by writeAutogenFiles' in the next major release" #-}++-- | Create @cabal_macros.h@ and @Paths_\<pkg\>@ possibly other generated files+-- in the usual place.+writeAutogenFiles' :: MonadIO m => QueryEnv -> m ()+writeAutogenFiles' qe =+ liftIO $ void $ invokeHelper qe ["write-autogen-files"]+ -- | Get the path to the sandbox package-db in a project getSandboxPkgDb :: (FilePath -> [String] -> String -> IO String) -> FilePath@@ -442,3 +473,6 @@ #else getProgName #endif++lookupEnv' :: String -> IO (Maybe String)+lookupEnv' k = lookup k <$> getEnvironment
cabal-helper.cabal view
@@ -1,5 +1,5 @@ name: cabal-helper-version: 0.6.2.0+version: 0.6.3.0 synopsis: Simple interface to some of Cabal's configuration state used by ghc-mod description: @cabal-helper@ provides a library which wraps the internal use of@@ -68,6 +68,7 @@ CabalHelper.Data CabalHelper.Compile CabalHelper.Log+ CabalHelper.Sandbox GHC-Options: -Wall X-Install-Target: $libexecdir Build-Depends: base >= 4.5 && < 5
tests/Spec.hs view
@@ -8,6 +8,7 @@ import Data.Functor import Control.Exception as E import Control.Arrow+import Prelude import CabalHelper.Common import CabalHelper.Compile@@ -18,7 +19,7 @@ flip (setEnv "HOME") True =<< fromMaybe "/tmp" <$> lookupEnv "TMPDIR" _ <- rawSystem "cabal" ["update"] - writeAutogenFiles readProcess "." "./dist"+ writeAutogenFiles' $ defaultQueryEnv "." "./dist" let vers :: [(Version, [Version])] vers = map (parseVer *** map parseVer) [