packages feed

cabal-ghci 0.2.1 → 0.3

raw patch · 3 files changed

+72/−41 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CabalGHCI.hs view
@@ -12,10 +12,16 @@            f _ _ = (args, False)  main = do-  args ← getArgs-  let (args', pretend) = opt0 "print-ghci-args" args-  withOpts args' putStrLn $-    if pretend then mapM_ putStrLn-    else \opts → do+    args ← getArgs+    let (args', pretend) = opt0 "print-ghci-args" args+    withOpts args' errCont $+        if pretend then mapM_ putStrLn+        else \opts → do           putStrLn $ "Executing ghci with the following options: " ++ unwords opts           rawSystem "ghci" opts >> return ()+  where+    errCont "Current directory is not a cabal project" = do+          putStrLn "WARNING: no .cabal file found, falling back to default GHCi session & ignoring any passed args"+          rawSystem "ghci" []+          return ()+    errCont msg = putStrLn msg
Distribution/Dev/Interactive.hs view
@@ -10,25 +10,28 @@   cabalSet, packageOpts, loadCabal, lookForCabalFile, withOpts, LoadCabalRet(..)   ) where -import Distribution.Text-import Distribution.Compiler-import Distribution.Verbosity-import Distribution.System-import Distribution.Package-import Distribution.PackageDescription-import Distribution.PackageDescription.Parse-import Distribution.PackageDescription.Configuration-import Distribution.Simple.PackageIndex-import Distribution.Simple.LocalBuildInfo hiding (compiler)-import Data.Version+import Distribution.Text (display)+import Distribution.Compiler (buildCompilerFlavor, CompilerId(..))+import Distribution.Verbosity (normal)+import Distribution.System (buildPlatform)+import Distribution.Package (PackageName(..), Dependency(..))+import Distribution.PackageDescription (+  FlagName(..), FlagAssignment, BuildInfo(..), hcOptions, allExtensions,+  PackageDescription(..), Executable(..), allBuildInfo)+import Distribution.PackageDescription.Parse (readPackageDescription)+import Distribution.PackageDescription.Configuration (+  finalizePackageDescription)+import Distribution.Simple.PackageIndex (lookupDependency)+import Distribution.Simple.LocalBuildInfo (LocalBuildInfo, installedPkgs)+import Data.Version (Version, showVersion)+import Distribution.Simple.BuildPaths (autogenModulesDir, cppHeaderName) -import System.FilePath-import System.Directory-import System.Info-import Data.Maybe-import Data.Either-import Control.Exception-import Data.List+import System.FilePath (takeDirectory, (</>), takeExtension)+import System.Directory (+  getDirectoryContents, getCurrentDirectory, canonicalizePath)+import System.Info (compilerVersion)+import Data.Maybe (listToMaybe, fromMaybe)+import Control.Exception (try, SomeException)  type Deps = [(PackageName, Version)] @@ -50,7 +53,7 @@   → String -- ^ name of executable   → Maybe [String] packageOpts path pkg mlbi executable =-  maybe Nothing (\bi → Just $ ghcOpts path bi (listDeps bi =<< mlbi)) $+  maybe Nothing (\bi → Just $ ghcOpts path bi mlbi (listDeps bi =<< mlbi)) $   listToMaybe $     if executable == ""     then allBuildInfo pkg@@ -69,26 +72,43 @@       return (pkg, ver)  -- | GHC options for a 'BuildInfo'-ghcOpts ∷ FilePath → BuildInfo → Maybe Deps → [String]-ghcOpts path bi deps = concat $ +ghcOpts ∷ FilePath → BuildInfo → Maybe LocalBuildInfo → Maybe Deps → [String]+ghcOpts path bi mlbi deps = filter validGHCiFlag $ concat $   maybe [] ((noPkgs:) . add "-package=" . map addDep) deps :   map ($ bi) [   hcOptions buildCompilerFlavor,   addf "-X" display . allExtensions,-  addf "-i" (combine dir) . ("/dist/build/autogen":) . hsSourceDirs,+  addf "-i" (dir </>) . (autogendir:) . hsSourceDirs,   add "-optP" . cppOptions,   add "-optc" . ccOptions,-  add "-optl" . ldOptions-  -- TODO frameworks cSources otherModules extraLibs extraLibsDirs includes +  add "-optl" . ldOptions,+  const ["-optP-include", "-optP" ++ (autogendir </> cppHeaderName)]+  -- Other cabal settings currently ignored by cabal-ghci: +  -- frameworks cSources otherModules extraLibs extraLibsDirs includes   ]   where-    dir = takeDirectory path+    autogendir+      | Just lbi ← mlbi = autogenModulesDir lbi+      | otherwise = "dist/build/autogen"++    dir+      | s@(_:_) ← takeDirectory path = s+      | otherwise = "."     add s = map (s++)     addf ∷ String → (a → String) → [a] → [String]     addf s f = map ((s++) . f)     noPkgs = "-hide-all-packages"     addDep (PackageName pkg, showVersion → ver) = pkg ++ "-" ++ ver +    -- flags sensible for GHCi+    validGHCiFlag "-O" = False+    validGHCiFlag ['-','O',n] | n `elem` ['0'..'9'] = False+    validGHCiFlag "-debug" = False+    validGHCiFlag "-rtsopts" = False+    validGHCiFlag "-threaded" = False+    validGHCiFlag "-ticky" = False+    validGHCiFlag _ = True+ -- | Load the current cabal project file and parse it loadCabal   ∷ FilePath -- ^ usually the current directory@@ -99,7 +119,7 @@   flip (maybe (return NoCabalFile))     mCabalFile $ \cabalFile → do     gdescr ← readPackageDescription normal cabalFile-    mlbi ← loadCabalConfig (takeDirectory cabalFile `combine` "dist" `combine` "setup-config")+    mlbi ← loadCabalConfig (takeDirectory cabalFile </> "dist" </> "setup-config")     case finalizePackageDescription flags (const True)       buildPlatform compiler [] gdescr of         Left deps → return $ MissingDeps deps@@ -110,6 +130,7 @@ maybeNth n (_:xs) = maybeNth (n-1) xs maybeNth _ _ = Nothing +maybeRead ∷ Read a ⇒ String → Maybe a maybeRead s = case reads s of [(a, "")] → Just a; _ → Nothing  -- | Load the 'LocalBuildInfo' from dist/setup-config@@ -134,7 +155,7 @@                         && f /= ".cabal") files   case cabals of     [] → lookForCabalFile (takeDirectory path)-    [a] → return $ Just $ combine path a+    [a] → return $ Just $ path </> a     _ → return Nothing  -- | 'cabalSet' returns a list of ghci commands (seperated by newlines) that :set the 'packageOpts' of the current cabal project@@ -188,6 +209,9 @@ --   :cabalset -fcabal-ghci --   :m - Distribution.Dev.Interactive -- @+-- +-- After you've added those lines into your .ghci file, use the @:cabalset@+-- command to reload your .cabal file.  -- $args -- [@-fflag@] enable flag@@ -195,4 +219,3 @@ -- [@-f-flag@] disable flag --  -- [@exec@] load options for the exec executable-
cabal-ghci.cabal view
@@ -1,26 +1,28 @@ Name:                cabal-ghci-Version:             0.2.1+Version:             0.3 Synopsis:            Set up ghci with options taken from a .cabal file Description: The executable cabal-ghci runs ghci with the paths and extensions needed by a cabal project. The cabalSet function can be added to your .ghci to provide the same functionality at runtime, giving you more control over the options that are set.-Homepage:            http://code.atnnn.com/projects/cabal-ghci/wiki+Homepage:            http://github.com/atnnn/cabal-ghci License:             BSD3 License-file:        LICENSE Author:              Etienne Laurin Maintainer:          etienne@atnnn.com Category:            Development Build-type:          Simple-Cabal-version:       >=1.6+Cabal-version:       >=1.10  Source-repository head-    type: darcs-    location: http://code.atnnn.com/darcs/cabal-ghci/+    type: git+    location: git://github.com/atnnn/cabal-ghci/  Executable cabal-ghci+  default-language:    Haskell2010+  default-extensions: UnicodeSyntax, ViewPatterns   Main-is: CabalGHCI.hs-  extensions: UnicodeSyntax, ViewPatterns-  build-depends: process+  Build-depends: Cabal, base == 4.*, directory, filepath, process  Library+  default-language:    Haskell2010+  default-extensions: UnicodeSyntax, ViewPatterns   Exposed-modules: Distribution.Dev.Interactive   Build-depends: Cabal, base == 4.*, directory, filepath-  extensions: UnicodeSyntax, ViewPatterns