packages feed

cabal2ghci (empty) → 0.0.1.0

raw patch · 4 files changed

+139/−0 lines, 4 filesdep +Cabaldep +basedep +cmdargssetup-changed

Dependencies added: Cabal, base, cmdargs, stylish-haskell, system-fileio, system-filepath, text, unordered-containers, yaml

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2012, Hiromi ISHII++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 Hiromi ISHII 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
+ cabal2ghci.cabal view
@@ -0,0 +1,26 @@+-- Initial cabal2ghci.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++name:                cabal2ghci+version:             0.0.1.0+synopsis:            A tool to generate .ghci file from .cabal+description:         This is the tool to automatically generate `.ghci` file and `.stylish-haskell.yaml` file from `.cabal`. It currently supports to handle Language Pragmas and hs-src-dirs.++license:             BSD3+license-file:        LICENSE+author:              Hiromi ISHII+maintainer:          konn.jinro_at_gmail.com+copyright:           Hiromi ISHII (c) 2012-2013+category:            Development+build-type:          Simple+cabal-version:       >=1.8++executable cabal2ghci+  main-is:             cabal2ghci.hs+  -- other-modules:       +  build-depends:       base ==4.5.*, Cabal == 1.14.*, system-filepath, system-fileio, text, cmdargs, stylish-haskell, yaml, unordered-containers+  extensions: DeriveDataTypeable, ExtendedDefaultRules, RecordWildCards, OverloadedStrings, RecordWildCards++source-repository head+  type: git+  location: https://github.com/konn/cabal2ghci
+ cabal2ghci.hs view
@@ -0,0 +1,81 @@+{-# OPTIONS_GHC -fno-warn-type-defaults -fno-warn-orphans #-}+module Main where+import            Control.Applicative+import           Control.Monad+import qualified Data.HashMap.Strict                   as HM+import           Data.List+import           Data.Maybe+import qualified Data.Text                             as T+import           Data.Typeable+import           Data.Yaml+import           Distribution.PackageDescription+import           Distribution.PackageDescription.Parse+import           Filesystem+import           Filesystem.Path.CurrentOS             hiding (encode)+import           Language.Haskell.Extension+import           Language.Haskell.Stylish+import           Prelude                               hiding (FilePath,+                                                        readFile, writeFile)+import           System.Console.CmdArgs++default (T.Text)++data Option = Option { cabal :: Maybe String , noStylish :: Bool }+              deriving (Show, Eq, Ord, Typeable, Data)++defOption :: Option+defOption = Option { cabal = def &= help "cabal file" &= opt Nothing+                   , noStylish = def+                   }++main :: IO ()+main = do+  Option{..} <- cmdArgs defOption+  cabp <- case cabal of+    Nothing -> do+         cabs <- filter ((== Just "cabal") . extension) <$> listDirectory "."+         case cabs of+           []  -> error "no cabal file here."+           [f] -> return f+           _  -> error $ "There are more than two  cabal files: " ++ unwords (map encodeString cabs)+    Just fp -> do+      ext <- isFile $ decodeString fp+      if ext then return (decodeString fp) else error $ "no such file: " ++ fp+  result <- parsePackageDescription . T.unpack <$> readTextFile cabp+  case result of+    ParseFailed pe -> error $ show pe+    ParseOk _ gpack -> do+      let pack = packageDescription gpack+          bInfos = allBuildInfo pack ++ gpackBuildInfos gpack+          exts = nub $ concatMap allExtensions bInfos+          dirs = nub $ concatMap hsSourceDirs bInfos+          srcLines = map ((":set -X" ++) . showExt) exts+          dirLines = map (":set -i" ++) dirs+          ghci = T.pack $ unlines srcLines ++ unlines dirLines+      unless (T.null ghci) $ writeTextFile ".ghci" ghci+      unless noStylish $ do+        mfp <- configFilePath (const $ return ()) Nothing+        Object obj <-+            case mfp of+              Just fp -> do+                fromMaybe (object []) <$> decodeFile fp+              Nothing -> return $ object []+        let obj' = HM.insert "language_extensions" (toJSON $ map showExt exts) obj+        encodeFile ".stylish-haskell.yaml" $ Object obj'++showExt :: Extension -> String+showExt (EnableExtension kext)  = show kext+showExt (DisableExtension kext) = "No" ++ show kext+showExt (UnknownExtension ext)  = ext++getChildren :: CondTree v c a -> [a]+getChildren (CondNode a _ cs) = a : concatMap (\(_, b, mc) -> getChildren b ++ maybe [] getChildren mc) cs++gpackLib :: GenericPackageDescription -> [Library]+gpackLib = maybe [] getChildren . condLibrary++gpackExes :: GenericPackageDescription -> [Executable]+gpackExes = concatMap (getChildren . snd) . condExecutables++gpackBuildInfos :: GenericPackageDescription -> [BuildInfo]+gpackBuildInfos gp = map libBuildInfo (gpackLib gp) ++ map buildInfo (gpackExes gp)