cabal-ghci (empty) → 0.1
raw patch · 5 files changed
+193/−0 lines, 5 filesdep +Cabaldep +basedep +directorysetup-changed
Dependencies added: Cabal, base, directory, filepath, process
Files
- CabalGHCI.hs +13/−0
- Distribution/Dev/Interactive.hs +106/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- cabal-ghci.cabal +42/−0
+ CabalGHCI.hs view
@@ -0,0 +1,13 @@+module Main where++import Distribution.Dev.Interactive++import System.Environment+import System.Process++main = do+ args ← getArgs+ withOpts args putStrLn $ + \opts → do+ putStrLn $ "Executing ghci with the following options: " ++ unwords opts+ rawSystem "ghci" opts >> return ()
+ Distribution/Dev/Interactive.hs view
@@ -0,0 +1,106 @@+module Distribution.Dev.Interactive ( + cabalSet, packageOpts, loadCabal, lookForCabalFile, withOpts+ ) 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 System.FilePath+import System.Directory+import System.Info+import Data.Maybe++data LoadCabalRet =+ NoCabalFile |+ MissingDeps [Dependency] |+ Pkg FilePath PackageDescription+ deriving Show++pkgDescr (Pkg _ p) = p++compiler = CompilerId buildCompilerFlavor compilerVersion++packageOpts ∷ FilePath → PackageDescription → String → Maybe [String]+packageOpts path pkg executable =+ maybe Nothing (\bi → Just $ includeOpts path bi ++ extensionOpts bi ++ customOpts bi) $+ listToMaybe $+ if executable == ""+ then allBuildInfo pkg+ else+ fmap buildInfo .+ filter (\x → exeName x == executable) .+ executables $ pkg++customOpts bi = + hcOptions buildCompilerFlavor bi++extensionOpts bi =+ map (\x → "-X" ++ display x) $ allExtensions bi++includeOpts path bi =+ ["-i" ++ dir ++ "/dist/build/autogen"] +++ map (("-i"++) . combine dir) (hsSourceDirs bi)+ where dir = takeDirectory path++loadCabal ∷ FilePath → FlagAssignment → IO LoadCabalRet+loadCabal path flags = do+ mCabalFile ← lookForCabalFile =<< canonicalizePath path+ flip (maybe (return NoCabalFile))+ mCabalFile $ \cabalFile → do+ gdescr ← readPackageDescription normal cabalFile+ case finalizePackageDescription flags (const True)+ buildPlatform compiler [] gdescr of+ Left deps → return $ MissingDeps deps+ Right (descr, _) → return $ Pkg cabalFile descr++ifM ∷ Monad m ⇒ m Bool → m a → m a → m a+ifM a b c = a >>= \x → if x then b else c+ +lookForCabalFile "/" = return Nothing+lookForCabalFile path = do+ files ← getDirectoryContents path+ let cabals = filter (\f →+ takeExtension f == ".cabal"+ && f /= ".cabal") files+ case cabals of+ [] → lookForCabalFile (takeDirectory path)+ [a] → return $ Just $ combine path a+ _ → return Nothing++cabalSet ∷ String → IO String+cabalSet args =+ withOpts (words args)+ (\x → putStrLn x >> return "")+ ((\x → putStrLn x >> return x) .+ unlines . (map (":set "++)) . map show )++withOpts args err go = do+ let (flags, executable) = parseArgs args+ here ← getCurrentDirectory+ ret ← loadCabal here flags+ case ret of+ NoCabalFile → err "Current directory is not a cabal project"+ MissingDeps deps → err $ "Missing dependencies: " ++ unwords (map show deps)+ Pkg path descr → do+ let mopts = packageOpts path descr executable+ case mopts of+ Nothing → err (+ if executable /= ""+ then "No such executable in cabal file"+ else "No library defined in cabal file")+ Just opts → go opts++parseArgs args =+ (map (makeFlag . drop 2) . filter flag $ args, + fromMaybe "" . listToMaybe . filter (not . flag) $ args)+ where+ flag x = take 2 x == "-f"+ +makeFlag ('-':f) = (FlagName f, False)+makeFlag f = (FlagName f, True)
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2011, Etienne Laurin++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Etienne Laurin nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cabal-ghci.cabal view
@@ -0,0 +1,42 @@+Name: cabal-ghci+Version: 0.1+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:++ :m + Distribution.Dev.Interactive+ :def cabalset cabalSet+ :cabalset++ Both cabal-ghci and cabalset can take cabal flags and an executable name as arguments. For example:++ Prelude> :cabalset -fdevel up1+ :set "-i/home/atnnn/up1/src/dist/build/autogen"+ :set "-i/home/atnnn/up1/src/web"+ :set "-XTypeFamilies"+ :set "-XQuasiQuotes"++Homepage: http://code.atnnn.com/projects/cabal-ghci/wiki+License: BSD3+License-file: LICENSE+Author: Etienne Laurin+Maintainer: etienne@atnnn.com+Category: Development+Build-type: Simple+Cabal-version: >=1.6++Source-repository head+ type: darcs+ location: http://code.atnnn.com/darcs/cabal-ghci/++Executable cabal-ghci+ Main-is: CabalGHCI.hs+ extensions: UnicodeSyntax+ build-depends: process++Library+ Exposed-modules: Distribution.Dev.Interactive+ Build-depends: Cabal, base == 4.*, directory, filepath+ extensions: UnicodeSyntax