ghc-pkg-autofix (empty) → 0.1
raw patch · 4 files changed
+160/−0 lines, 4 filesdep +Cabaldep +basedep +filepathsetup-changed
Dependencies added: Cabal, base, filepath, parsec, process, split
Files
- LICENSE +30/−0
- Main.hs +68/−0
- Setup.hs +2/−0
- ghc-pkg-autofix.cabal +60/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2011, 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.
+ Main.hs view
@@ -0,0 +1,68 @@+{-# LANGUAGE NamedFieldPuns, RecordWildCards #-}+{-# OPTIONS_GHC -Wall #-}+module Main where+import Distribution.InstalledPackageInfo+import Distribution.Package hiding (depends)+import System.Process+import System.IO+import Data.List+import Control.Applicative+import System.FilePath+import Data.Maybe+import Data.List.Split++import PkgCheckParser++main :: IO ()+main = do+ (_, _, hErr, _) <- runInteractiveProcess "ghc-pkg" ["check"] Nothing Nothing+ src <- hGetContents hErr+ if null src+ then putStrLn "Nothing to fix. exit."+ else case parseCheck src of+ Left err -> hPrint stderr err+ Right ps -> do+ print ps+ mapM_ procPackage ps+ _ <- readProcess "ghc-pkg" ["recache", "--user"] ""+ return ()++procPackage :: BrokenPackage -> IO ()+procPackage P{packageID, brokenDeps} = do+ Just packID <- getPackageID packageID+ newPIDs <- mapM (getPackageID . getPackageName) brokenDeps+ let table = catMaybes $ zipWith (fmap.(,)) brokenDeps newPIDs+ infoPath <- getPackageInfoPath packID+ rslt <- parseInstalledPackageInfo <$> readFile infoPath+ case rslt of+ ParseFailed err -> hPrint stderr err+ ParseOk _ pack -> do+ let pack' = pack{depends=foldr (uncurry replace) (depends pack) table}+ writeFile (snd $ splitFileName infoPath) $ showInstalledPackageInfo pack+ writeFile infoPath $ showInstalledPackageInfo pack'++getPackageName :: String -> String+getPackageName pid = intercalate "-" $ take 2 $ splitOn "-" pid++getPackageID :: String -> IO (Maybe String)+getPackageID pName = do+ rsl <- parseInstalledPackageInfo <$> readProcess "ghc-pkg" ["describe", pName] ""+ case rsl of+ ParseFailed _ -> return Nothing+ ParseOk _ pack -> do+ let InstalledPackageId pid = installedPackageId pack+ return (Just pid)++replace :: String -> String -> [InstalledPackageId] -> [InstalledPackageId]+replace old new = intercalate [ InstalledPackageId new ] .+ splitOn [InstalledPackageId old]++getPackageInfoPath :: String -> IO FilePath+getPackageInfoPath pid = do+ dir <- getConfDir+ return $ dir </> (pid++".conf")++getConfDir :: IO FilePath+getConfDir = do+ src <- readProcess "ghc-pkg" ["list", "--user"] ""+ return $ init $ head $ filter ((=='/').head) $ lines src
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ ghc-pkg-autofix.cabal view
@@ -0,0 +1,60 @@+-- ghc-pkg-autofix.cabal auto-generated by cabal init. For additional+-- options, see+-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.+-- The name of the package.+Name: ghc-pkg-autofix++-- The package version. See the Haskell package versioning policy+-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for+-- standards guiding when and how versions should be incremented.+Version: 0.1++-- A short (one-line) description of the package.+Synopsis: Simple utility to fix BROKEN package dependencies++-- A longer description of the package.+Description: The cabal-install sometimes reinstall existing library and break some package dependencies. This utility fixes such situations by replacing old package id in "broken" package with new id.++-- The license under which the package is released.+License: BSD3++-- The file containing the license text.+License-file: LICENSE++-- The package author(s).+Author: Hiromi ISHII++-- An email address to which users can send suggestions, bug reports,+-- and patches.+Maintainer: konn.jinro_at_gmail.com++-- A copyright notice.+-- Copyright: ++Category: Development++Build-type: Simple++-- Extra files to be distributed with the package, such as examples or+-- a README.+-- Extra-source-files: ++-- Constraint on the version of Cabal needed to build this package.+Cabal-version: >=1.2+++Executable ghc-pkg-autofix+ -- .hs or .lhs file containing the Main module.+ Main-is: Main.hs + + -- Packages needed in order to build this package.+ Build-depends: base >= 3 && < 4, parsec >= 2 && < 4, split >= 0.1 && < 0.2,+ filepath >= 1 && < 2, process >= 1.0 && < 1.1,+ Cabal >= 1.8 && <2+ + -- Modules not exported by this package.+ -- Other-modules: + + -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.+ -- Build-tools: +