1module Stackage.Util where
3import qualified Codec.Archive.Tar as Tar
4import qualified Codec.Archive.Tar.Entry as TarEntry
5import Control.Monad (guard, when)
6import Data.List (stripPrefix)
7import qualified Data.Map as Map
8import qualified Data.Set as Set
9import Data.Version (showVersion)
10import Distribution.Text (simpleParse)
11import Distribution.Version (thisVersion)
13import System.Directory (doesDirectoryExist,
14 removeDirectoryRecursive)
15import System.Directory (getAppUserDataDirectory)
16import System.FilePath ((</>))
18identsToRanges :: Set PackageIdentifier -> Map PackageName (VersionRange, Maintainer)
20 Map.unions . map go . Set.toList
22 go (PackageIdentifier package version) = Map.singleton package (thisVersion version, Maintainer "Haskell Platform")
24packageVersionString :: (PackageName, Version) -> String
25packageVersionString (PackageName p, v) = concat [p, "-", showVersion v]
27rm_r :: FilePath -> IO ()
29 exists <- doesDirectoryExist fp
30 when exists $ removeDirectoryRecursive fp
32getCabalRoot :: IO FilePath
33getCabalRoot = getAppUserDataDirectory "cabal"
35-- | Name of the 00-index.tar downloaded from Hackage.
36getTarballName :: IO FilePath
39 return $ c </> "packages" </> "hackage.haskell.org" </> "00-index.tar"
41stableRepoName, extraRepoName :: String
42stableRepoName = "stackage"
43extraRepoName = "stackage-extra"
45-- | Locations for the stackage and stackage-extra tarballs
46getStackageTarballNames :: IO (FilePath, FilePath)
47getStackageTarballNames = do
49 let f x = c </> "packages" </> x </> "00-index.tar"
50 return (f stableRepoName, f extraRepoName)
52getPackageVersion :: Tar.Entry -> Maybe (PackageName, Version)
53getPackageVersion e = do
54 let (package', s1) = break (== '/') fp
55 package = PackageName package'
56 s2 <- stripPrefix "/" s1
57 let (version', s3) = break (== '/') s2
58 version <- simpleParse version'
59 s4 <- stripPrefix "/" s3
60 guard $ s4 == package' ++ ".cabal"
61 Just (package, version)
63 fp = TarEntry.fromTarPathToPosixPath $ TarEntry.entryTarPath e
65-- | If a package cannot be parsed or is not found, the default value for
66-- whether it has a test suite. We default to @True@ since, worst case
67-- scenario, this just means a little extra time trying to run a suite that's
68-- not there. Defaulting to @False@ would result in silent failures.
69defaultHasTestSuites :: Bool
70defaultHasTestSuites = True
72packageDir = (</> "package-db") . sandboxRoot
73libDir = (</> "lib") . sandboxRoot
74binDir = (</> "bin") . sandboxRoot
75dataDir = (</> "share") . sandboxRoot
76docDir x = sandboxRoot x </> "share" </> "doc" </> "$pkgid"
78addCabalArgs settings rest
79 = "--package-db=clear"
80 : "--package-db=global"
81 : ("--package-db=" ++ packageDir settings)
82 : ("--libdir=" ++ libDir settings)
83 : ("--bindir=" ++ binDir settings)
84 : ("--datadir=" ++ dataDir settings)
85 : ("--docdir=" ++ docDir settings)
86 : extraArgs settings ++ rest
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