Skip to content

Instantly share code, notes, and snippets.

@hvr
Last active December 15, 2016 21:23
Show Gist options
  • Save hvr/68b2268b804684f21baa to your computer and use it in GitHub Desktop.
Save hvr/68b2268b804684f21baa to your computer and use it in GitHub Desktop.
#!/usr/bin/env runghc
import Data.Char
import Data.List
import Control.Monad
import Control.Applicative
import Data.Monoid
import Data.Version
import Text.ParserCombinators.ReadP (readP_to_S)
parseVer :: String -> Either Version String
parseVer "HEAD" = Right "HEAD"
parseVer s = case [ v | (v,"") <- readP_to_S parseVersion s ] of
(v:_) -> Left v
[] -> error ("parseVer: " ++ show s)
showVer :: Either Version String -> String
showVer (Right s) = s
showVer (Left v) = showVersion v
main :: IO ()
main = do
ls <- map words . normalizeLines . lines <$> getContents
let entries = sort [ ((parseVer gv,pn),pv) | gv:pnvs <- ls, pnv <- pnvs, let (pn,pv) = fmap tail $ break (=='/') pnv ]
allpns = sort $ nub [ pn | ((_,pn),_) <- entries ]
allgvs = reverse $ sort $ nub [ gv | ((gv,_),_) <- entries ]
let hdr = intercalate "||" $ ("" : " " : [ "= '''" <> showVer v <> "''' =" | v <- allgvs ]) ++ [""]
putStrLn $ hdr
forM_ allpns $ \pn -> do
let pghcvers = [ (showVer gv,pv) | ((gv,pn'),pv) <- entries, pn' == pn ]
let tmp = intercalate "||" $ do
(v,v_next) <- zip (map showVer allgvs) (tail (map showVer allgvs) ++ [""])
let pver = lookup v pghcvers
pver_next = lookup v_next pghcvers
return $case pver of
_ | v_next /= "" && pver == pver_next -> "" -- collapse
Nothing -> " ''none'' "
Just pver' -> " " <> pver' <> " "
-- print (pn, pghcvers)
putStrLn $ "||=`" <> pn <> "` =||" <> tmp <> "||"
-- repeat header
putStrLn $ hdr
return ()
where
normalizeLines = filter (not . null) . map normLine
normLine = dropWhile isSpace . fst . span (/='#')
#! /usr/bin/env runghc
import Control.Applicative
import Control.Monad
import Data.Char
import Data.List
import Data.Monoid
import System.Environment
import System.Exit
import System.IO
main :: IO ()
main = do
fns <- getArgs
when (null fns) $ do
hPutStrLn stderr "usage: ./pack_pkg_list.hs <files with 'ghc-pkg list --global' output>..."
exitFailure
forM_ fns $ \fn -> do
c <- (words . map normWS) <$> readFile fn
unless (not (null c)
&& (("package.conf.d:" `isSuffixOf` head c) || ("package.conf.d" `isSuffixOf` head c))
&& not (any ("package.conf.d" `isInfixOf`) (tail c))) $
fail ("invalid file " ++ show fn)
let c' = sort (map parsePkgName $ tail c)
Just ghcver = lookup "ghc" (map fst c')
let ln = ghcver <> "\t" <> unwords [ n<>"/"<>v<>(if h then "*" else "") | ((n,v),h) <- c' ]
putStrLn ln
return ()
where
normWS c | isSpace c = ' '
| otherwise = c
parsePkgName n | "(" `isPrefixOf` n
, ")" `isSuffixOf` n = (splitPkg (init (tail n)), True)
| otherwise = (splitPkg n, False)
splitPkg pn | head n == '-' = (reverse $ tail n,reverse v)
| otherwise = error "splitPkg: internal error"
where
(v,n) = break (=='-') . reverse $ pn
# packed versions file -- generate with ./pack_pkg_list.hs
#
# We extract the Win32 pkg version information manually here
7.0.1 Win32/2.2.0.2
7.0.2 Win32/2.2.0.2
7.0.3 Win32/2.2.0.2
7.0.4 Win32/2.2.0.2
7.2.1 Win32/2.2.1.0
7.2.2 Win32/2.2.1.0
7.4.1 Win32/2.2.2.0
7.4.2 Win32/2.2.2.0
7.6.1 Win32/2.3.0.0
7.6.2 Win32/2.3.0.0
7.6.3 Win32/2.3.0.0
7.8.1 Win32/2.3.0.2
7.8.2 Win32/2.3.0.2
7.8.3 Win32/2.3.0.2
7.8.4 Win32/2.3.0.2
7.10.1 Win32/2.3.1.0
7.10.2 Win32/2.3.1.0
7.10.3 Win32/2.3.1.0
8.0.1 Win32/2.3.1.1
############################################
# GHC 7.0 - GHC 7.6
7.0.1 Cabal/1.10.0.0 array/0.3.0.2 base/4.3.0.0 bin-package-db/0.0.0.0 bytestring/0.9.1.8 containers/0.4.0.0 directory/1.1.0.0 extensible-exceptions/0.1.1.2 ffi/1.0 filepath/1.2.0.0 ghc/7.0.1* ghc-binary/0.5.0.2* ghc-prim/0.2.0.0 haskell2010/1.0.0.0* haskell98/1.1.0.0 hpc/0.5.0.6 integer-gmp/0.2.0.2 old-locale/1.0.0.2 old-time/1.0.0.6 pretty/1.0.1.2 process/1.0.1.4 random/1.0.0.3 rts/1.0 template-haskell/2.5.0.0 time/1.2.0.3 unix/2.4.1.0
7.0.2 Cabal/1.10.1.0 array/0.3.0.2 base/4.3.1.0 bin-package-db/0.0.0.0 bytestring/0.9.1.10 containers/0.4.0.0 directory/1.1.0.0 extensible-exceptions/0.1.1.2 ffi/1.0 filepath/1.2.0.0 ghc/7.0.2* ghc-binary/0.5.0.2* ghc-prim/0.2.0.0 haskell2010/1.0.0.0* haskell98/1.1.0.1 hpc/0.5.0.6 integer-gmp/0.2.0.3 old-locale/1.0.0.2 old-time/1.0.0.6 pretty/1.0.1.2 process/1.0.1.5 random/1.0.0.3 rts/1.0 template-haskell/2.5.0.0 time/1.2.0.3 unix/2.4.2.0
7.0.3 Cabal/1.10.1.0 array/0.3.0.2 base/4.3.1.0 bin-package-db/0.0.0.0 bytestring/0.9.1.10 containers/0.4.0.0 directory/1.1.0.0 extensible-exceptions/0.1.1.2 ffi/1.0 filepath/1.2.0.0 ghc/7.0.3* ghc-binary/0.5.0.2* ghc-prim/0.2.0.0 haskell2010/1.0.0.0* haskell98/1.1.0.1 hpc/0.5.0.6 integer-gmp/0.2.0.3 old-locale/1.0.0.2 old-time/1.0.0.6 pretty/1.0.1.2 process/1.0.1.5 random/1.0.0.3 rts/1.0 template-haskell/2.5.0.0 time/1.2.0.3 unix/2.4.2.0
7.0.4 Cabal/1.10.2.0 array/0.3.0.2 base/4.3.1.0 bin-package-db/0.0.0.0 bytestring/0.9.1.10 containers/0.4.0.0 directory/1.1.0.0 extensible-exceptions/0.1.1.2 ffi/1.0 filepath/1.2.0.0 ghc/7.0.4* ghc-binary/0.5.0.2* ghc-prim/0.2.0.0 haskell2010/1.0.0.0* haskell98/1.1.0.1 hpc/0.5.0.6 integer-gmp/0.2.0.3 old-locale/1.0.0.2 old-time/1.0.0.6 pretty/1.0.1.2 process/1.0.1.5 random/1.0.0.3 rts/1.0 template-haskell/2.5.0.0 time/1.2.0.3 unix/2.4.2.0
7.2.1 Cabal/1.12.0 array/0.3.0.3 base/4.4.0.0 bin-package-db/0.0.0.0 binary/0.5.0.2* bytestring/0.9.2.0 containers/0.4.1.0 directory/1.1.0.1 extensible-exceptions/0.1.1.3 ffi/1.0 filepath/1.2.0.1 ghc/7.2.1* ghc-prim/0.2.0.0 haskell2010/1.1.0.0* haskell98/2.0.0.0* hoopl/3.8.7.1 hpc/0.5.1.0 integer-gmp/0.3.0.0 old-locale/1.0.0.3 old-time/1.0.0.7 pretty/1.1.0.0 process/1.1.0.0 rts/1.0 template-haskell/2.6.0.0 time/1.2.0.5 unix/2.5.0.0
7.2.2 Cabal/1.12.0 array/0.3.0.3 base/4.4.1.0 bin-package-db/0.0.0.0 binary/0.5.0.2* bytestring/0.9.2.0 containers/0.4.1.0 directory/1.1.0.1 extensible-exceptions/0.1.1.3 ffi/1.0 filepath/1.2.0.1 ghc/7.2.2* ghc-prim/0.2.0.0 haskell2010/1.1.0.0* haskell98/2.0.0.0* hoopl/3.8.7.1 hpc/0.5.1.0 integer-gmp/0.3.0.0 old-locale/1.0.0.3 old-time/1.0.0.7 pretty/1.1.0.0 process/1.1.0.0 rts/1.0 template-haskell/2.6.0.0 time/1.2.0.5 unix/2.5.0.0
7.4.1 Cabal/1.14.0 array/0.4.0.0 base/4.5.0.0 bin-package-db/0.0.0.0 binary/0.5.1.0 bytestring/0.9.2.1 containers/0.4.2.1 deepseq/1.3.0.0 directory/1.1.0.2 extensible-exceptions/0.1.1.4 filepath/1.3.0.0 ghc/7.4.1* ghc-prim/0.2.0.0 haskell2010/1.1.0.1* haskell98/2.0.0.1* hoopl/3.8.7.3 hpc/0.5.1.1 integer-gmp/0.4.0.0 old-locale/1.0.0.4 old-time/1.1.0.0 pretty/1.1.1.0 process/1.1.0.1 rts/1.0 template-haskell/2.7.0.0 time/1.4 unix/2.5.1.0
7.4.2 Cabal/1.14.0 array/0.4.0.0 base/4.5.1.0 bin-package-db/0.0.0.0 binary/0.5.1.0 bytestring/0.9.2.1 containers/0.4.2.1 deepseq/1.3.0.0 directory/1.1.0.2 extensible-exceptions/0.1.1.4 filepath/1.3.0.0 ghc/7.4.2* ghc-prim/0.2.0.0 haskell2010/1.1.0.1* haskell98/2.0.0.1* hoopl/3.8.7.3 hpc/0.5.1.1 integer-gmp/0.4.0.0 old-locale/1.0.0.4 old-time/1.1.0.0 pretty/1.1.1.0 process/1.1.0.1 rts/1.0 template-haskell/2.7.0.0 time/1.4 unix/2.5.1.1
7.6.1 Cabal/1.16.0 array/0.4.0.1 base/4.6.0.0 bin-package-db/0.0.0.0 binary/0.5.1.1 bytestring/0.10.0.0 containers/0.5.0.0 deepseq/1.3.0.1 directory/1.2.0.0 filepath/1.3.0.1 ghc/7.6.1* ghc-prim/0.3.0.0 haskell2010/1.1.1.0* haskell98/2.0.0.2* hoopl/3.9.0.0 hpc/0.6.0.0 integer-gmp/0.5.0.0 old-locale/1.0.0.5 old-time/1.1.0.1 pretty/1.1.1.0 process/1.1.0.2 rts/1.0 template-haskell/2.8.0.0 time/1.4.0.1 unix/2.6.0.0
7.6.2 Cabal/1.16.0 array/0.4.0.1 base/4.6.0.1 bin-package-db/0.0.0.0 binary/0.5.1.1 bytestring/0.10.0.2 containers/0.5.0.0 deepseq/1.3.0.1 directory/1.2.0.1 filepath/1.3.0.1 ghc/7.6.2* ghc-prim/0.3.0.0 haskell2010/1.1.1.0* haskell98/2.0.0.2* hoopl/3.9.0.0 hpc/0.6.0.0 integer-gmp/0.5.0.0 old-locale/1.0.0.5 old-time/1.1.0.1 pretty/1.1.1.0 process/1.1.0.2 rts/1.0 template-haskell/2.8.0.0 time/1.4.0.1 unix/2.6.0.1
7.6.3 Cabal/1.16.0 array/0.4.0.1 base/4.6.0.1 bin-package-db/0.0.0.0 binary/0.5.1.1 bytestring/0.10.0.2 containers/0.5.0.0 deepseq/1.3.0.1 directory/1.2.0.1 filepath/1.3.0.1 ghc/7.6.3* ghc-prim/0.3.0.0 haskell2010/1.1.1.0* haskell98/2.0.0.2* hoopl/3.9.0.0 hpc/0.6.0.0 integer-gmp/0.5.0.0 old-locale/1.0.0.5 old-time/1.1.0.1 pretty/1.1.1.0 process/1.1.0.2 rts/1.0 template-haskell/2.8.0.0 time/1.4.0.1 unix/2.6.0.1
############################################
# GHC 7.8.x
7.8.1 Cabal/1.18.1.3 array/0.5.0.0 base/4.7.0.0 bin-package-db/0.0.0.0 binary/0.7.1.0 bytestring/0.10.4.0 containers/0.5.5.1 deepseq/1.3.0.2 directory/1.2.1.0 filepath/1.3.0.2 ghc/7.8.1* ghc-prim/0.3.1.0 haskell2010/1.1.2.0* haskell98/2.0.0.3* hoopl/3.10.0.1 hpc/0.6.0.1 integer-gmp/0.5.1.0 old-locale/1.0.0.6 old-time/1.1.0.2 pretty/1.1.1.1 process/1.2.0.0 rts/1.0 template-haskell/2.9.0.0 time/1.4.2 transformers/0.3.0.0 unix/2.7.0.1
7.8.2 Cabal/1.18.1.3 array/0.5.0.0 base/4.7.0.0 bin-package-db/0.0.0.0 binary/0.7.1.0 bytestring/0.10.4.0 containers/0.5.5.1 deepseq/1.3.0.2 directory/1.2.1.0 filepath/1.3.0.2 ghc/7.8.2* ghc-prim/0.3.1.0 haskell2010/1.1.2.0* haskell98/2.0.0.3* hoopl/3.10.0.1 hpc/0.6.0.1 integer-gmp/0.5.1.0 old-locale/1.0.0.6 old-time/1.1.0.2 pretty/1.1.1.1 process/1.2.0.0 rts/1.0 template-haskell/2.9.0.0 time/1.4.2 transformers/0.3.0.0 unix/2.7.0.1
7.8.3 Cabal/1.18.1.3 array/0.5.0.0 base/4.7.0.1 bin-package-db/0.0.0.0 binary/0.7.1.0 bytestring/0.10.4.0 containers/0.5.5.1 deepseq/1.3.0.2 directory/1.2.1.0 filepath/1.3.0.2 ghc/7.8.3* ghc-prim/0.3.1.0 haskeline/0.7.1.2 haskell2010/1.1.2.0* haskell98/2.0.0.3* hoopl/3.10.0.1 hpc/0.6.0.1 integer-gmp/0.5.1.0 old-locale/1.0.0.6 old-time/1.1.0.2 pretty/1.1.1.1 process/1.2.0.0 rts/1.0 template-haskell/2.9.0.0 terminfo/0.4.0.0 time/1.4.2 transformers/0.3.0.0 unix/2.7.0.1 xhtml/3000.2.1
7.8.4 Cabal/1.18.1.5 array/0.5.0.0 base/4.7.0.2 bin-package-db/0.0.0.0 binary/0.7.1.0 bytestring/0.10.4.0 containers/0.5.5.1 deepseq/1.3.0.2 directory/1.2.1.0 filepath/1.3.0.2 ghc/7.8.4* ghc-prim/0.3.1.0 haskeline/0.7.1.2 haskell2010/1.1.2.0* haskell98/2.0.0.3* hoopl/3.10.0.1 hpc/0.6.0.1 integer-gmp/0.5.1.0 old-locale/1.0.0.6 old-time/1.1.0.2 pretty/1.1.1.1 process/1.2.0.0 rts/1.0 template-haskell/2.9.0.0 terminfo/0.4.0.0 time/1.4.2 transformers/0.3.0.0 unix/2.7.0.1 xhtml/3000.2.1
############################################
# GHC 7.10.x
7.10.1 Cabal/1.22.2.0 array/0.5.1.0 base/4.8.0.0 bin-package-db/0.0.0.0 binary/0.7.3.0 bytestring/0.10.6.0 containers/0.5.6.2 deepseq/1.4.1.1 directory/1.2.2.0 filepath/1.4.0.0 ghc/7.10.1* ghc-prim/0.4.0.0 haskeline/0.7.2.1 hoopl/3.10.0.2 hpc/0.6.0.2 integer-gmp/1.0.0.0 pretty/1.1.2.0 process/1.2.3.0 rts/1.0 template-haskell/2.10.0.0 terminfo/0.4.0.1 time/1.5.0.1 transformers/0.4.2.0 unix/2.7.1.0 xhtml/3000.2.1
7.10.2 Cabal/1.22.4.0 array/0.5.1.0 base/4.8.1.0 bin-package-db/0.0.0.0 binary/0.7.5.0 bytestring/0.10.6.0 containers/0.5.6.2 deepseq/1.4.1.1 directory/1.2.2.0 filepath/1.4.0.0 ghc/7.10.2* ghc-prim/0.4.0.0 haskeline/0.7.2.1 hoopl/3.10.0.2 hpc/0.6.0.2 integer-gmp/1.0.0.0 pretty/1.1.2.0 process/1.2.3.0 rts/1.0 template-haskell/2.10.0.0 terminfo/0.4.0.1 time/1.5.0.1 transformers/0.4.2.0 unix/2.7.1.0 xhtml/3000.2.1
7.10.3 Cabal/1.22.5.0 array/0.5.1.0 base/4.8.2.0 bin-package-db/0.0.0.0 binary/0.7.5.0 bytestring/0.10.6.0 containers/0.5.6.2 deepseq/1.4.1.1 directory/1.2.2.0 filepath/1.4.0.0 ghc/7.10.3* ghc-prim/0.4.0.0 haskeline/0.7.2.1 hoopl/3.10.0.2 hpc/0.6.0.2 integer-gmp/1.0.0.0 pretty/1.1.2.0 process/1.2.3.0 rts/1.0 template-haskell/2.10.0.0 terminfo/0.4.0.1 time/1.5.0.1 transformers/0.4.2.0 unix/2.7.1.0 xhtml/3000.2.1
# GHC 8.0.1
8.0.1 Cabal/1.24.0.0 array/0.5.1.1 base/4.9.0.0 binary/0.8.3.0 bytestring/0.10.8.1 containers/0.5.7.1 deepseq/1.4.2.0 directory/1.2.6.2 filepath/1.4.1.0 ghc/8.0.1* ghc-boot/8.0.1 ghc-boot-th/8.0.1 ghc-prim/0.5.0.0 ghci/8.0.1 haskeline/0.7.2.3 hoopl/3.10.2.1 hpc/0.6.0.3 integer-gmp/1.0.0.1 pretty/1.1.3.3 process/1.4.2.0 rts/1.0 template-haskell/2.11.0.0 terminfo/0.4.0.2 time/1.6.0.1 transformers/0.5.2.0 unix/2.7.2.0 xhtml/3000.2.1
############################################
# GHC HEAD
HEAD Win32/2.3.1.1
HEAD Cabal/1.25.0.0 array/0.5.1.1 base/4.9.0.0 binary/0.8.3.0 bytestring/0.10.8.1 containers/0.5.7.1 deepseq/1.4.2.0 directory/1.2.6.2 filepath/1.4.1.0 ghc/8.1* ghc-boot/8.1 ghc-boot-th/8.1 ghc-prim/0.5.0.0 ghci/8.1 haskeline/0.7.2.3 hoopl/3.10.2.1 hpc/0.6.0.3 integer-gmp/1.0.0.1 pretty/1.1.3.3 process/1.4.2.0 rts/1.0 template-haskell/2.11.0.0 terminfo/0.4.0.2 time/1.6.0.1 transformers/0.5.2.0 unix/2.7.2.0 xhtml/3000.2.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment