git.iko.soy/typeable/cabal2nix
on master help sign in
PackageList.hs: filter all packages that are not registered in Hackage
commit3b6f64f422759095237592c15f29f5988013cfa9 authorPeter Simons <simons@cryp.to> dateSun 21 Aug 2011, 21:02 (15 years ago) parentbdfde6a
1 file changed+11−1
src/PackageList.hs+11−1
src/PackageList.hs+11−1
@@ -1,12 +1,15 @@
11module Main ( main ) where
22
33import Control.Exception ( assert )
4+import Control.Monad ( when, filterM )
45import Data.Char ( toLower )
56import Data.List ( nubBy, sortBy )
67import Data.Ord ( comparing )
78import Data.Version ( Version(..) )
89import Distribution.Package ( PackageIdentifier(..), PackageName(..) )
910import Distribution.Text ( simpleParse, display )
11+import System.Directory ( doesDirectoryExist, doesFileExist )
12+import System.FilePath ( (</>), (<.>) )
1013import System.Process ( readProcess )
1114import Text.Regex.Posix ( (=~), match, makeRegexOpts, compExtended, execBlank )
1215
@@ -47,6 +50,10 @@ stripGhc721Versions pkgs = [ p | p@(_,_,attr) <- pkgs , not (attr =~ "ghc721") ]
4750selectLatestVersions :: Pkgset -> Pkgset
4851selectLatestVersions = nubBy (\x y -> comparePkgByName x y == EQ) . sortBy comparePkgByVersion
4952
53+isHackagePackage :: Pkg -> IO Bool
54+isHackagePackage (name,version,_) = doesFileExist path
55+ where path = "/dev/shm/hackage/" </> name </> display version </> name <.> "cabal"
56+
5057formatPackageLine :: Pkg -> String
5158formatPackageLine (name,version,attr) = show (name, display version, Just url)
5259 where
@@ -59,5 +66,8 @@ regsubmatch buf patt = let (_,_,_,x) = f in x
5966
6067main :: IO ()
6168main = do
62− pkgset <- fmap (selectLatestVersions . stripGhc721Versions . stripProfilingVersions) getHaskellPackageList
69+ haveHackage <- doesDirectoryExist "/dev/shm/hackage"
70+ when (not haveHackage) (fail "cannot find hackage database at /dev/shm/hackage")
71+ pkgset' <- fmap (selectLatestVersions . stripGhc721Versions . stripProfilingVersions) getHaskellPackageList
72+ pkgset <- filterM isHackagePackage pkgset'
6373 mapM_ (putStrLn . formatPackageLine) (sortBy comparePkgByName pkgset)