1module Stackage.GhcPkg where
5import Distribution.Text (simpleParse)
6import Distribution.Version (Version (Version))
7import Data.Char (isSpace)
8import qualified Data.Set as Set
10getPackages :: [String] -> GhcMajorVersion -> IO (Set PackageIdentifier)
11getPackages extraArgs version = do
12 output <- readProcess "ghc-pkg" (extraArgs ++ [arg, "list"]) ""
13 fmap Set.unions $ mapM parse $ drop 1 $ lines output
15 -- Account for a change in command line option name
17 | version >= GhcMajorVersion 7 6 = "--no-user-package-db"
18 | otherwise = "--no-user-package-conf"
21 "" -> return Set.empty
23 case simpleParse s' of
24 Just x -> return $ Set.singleton x
25 Nothing -> error $ "Could not parse ghc-pkg output: " ++ show s
26 clean = stripParens . dropWhile isSpace . reverse . dropWhile isSpace . reverse
27 stripParens x@('(':_:_)
28 | last x == ')' = tail $ init $ x
31getGlobalPackages :: GhcMajorVersion -> IO (Set PackageIdentifier)
32getGlobalPackages version = getPackages [] version
34getDBPackages :: [FilePath] -> GhcMajorVersion -> IO (Set PackageIdentifier)
35getDBPackages [] _ = return Set.empty
36getDBPackages packageDirs version =
37 getPackages (map packageDbArg packageDirs) version
40 | version >= GhcMajorVersion 7 6 = "--package-db=" ++ db
41 | otherwise = "--package-conf" ++ db
43getGhcVersion :: IO GhcMajorVersion
45 versionOutput <- readProcess "ghc-pkg" ["--version"] ""
46 maybe (error $ "Invalid version output: " ++ show versionOutput) return $ do
47 verS:_ <- Just $ reverse $ words versionOutput
48 Version (x:y:_) _ <- simpleParse verS
49 return $ GhcMajorVersion x y
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list