Skip to content

Commit f8e96e0

Browse files
committed
Merge 'cabal-2.0' branch
This upgrades hackage-server from Cabal-1.24 to Cabal-2.0. A nice consequence is a signficant reduction of list-constructor heap objects as well as a reduction of overall heap allocation. See #600 (comment) for a qualitative comparison of heap profiles before/after this merge. Closes #600
2 parents 31f98e3 + 5d73b63 commit f8e96e0

35 files changed

+373
-193
lines changed

.gitignore

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
build-cache
2-
mirror-cache
3-
state
4-
dist
5-
dist-newstyle
1+
# hackage-server
2+
build-cache/
3+
mirror-cache/
4+
state/
5+
backups/
6+
# cabal
7+
.ghc.environment.*
8+
dist/
9+
dist-newstyle/
10+
.cabal-sandbox/
11+
cabal.sandbox.config
12+
cabal.project.local
13+
# editor
614
tags
715
*.swp
8-
.cabal-sandbox
9-
.stack-work
10-
cabal.sandbox.config
1116
TAGS
17+
*~

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "vendor/cabal"]
2+
path = vendor/cabal
3+
url = ../cabal
4+
branch = 2.0

.travis.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ language: c
88
sudo: false
99

1010
git:
11-
submodules: false # whether to recursively clone submodules
11+
submodules: true # whether to recursively clone submodules
1212

1313
cache:
1414
directories:
@@ -55,7 +55,8 @@ before_install:
5555
- HC=${CC}
5656
- unset CC
5757
- PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$PATH
58-
- PKGNAME='hackage-server'
58+
- PKGNAME="hackage-server"
59+
- TARGET=":pkg:$PKGNAME"
5960

6061
install:
6162
- cabal --version
@@ -64,12 +65,10 @@ install:
6465
- TEST=${TEST---enable-tests}
6566
- travis_retry cabal update -v
6667
- sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
67-
- rm -fv cabal.project.local
68-
- "echo 'packages: .' > cabal.project"
6968
- if [ -e "cabal.project.local-${HC}" ]; then cp -v "cabal.project.local-${HC}" cabal.project.local; fi
7069
- rm -f cabal.project.freeze
71-
- cabal new-build -w ${HC} ${TEST} ${BENCH} --dep -j2 all
72-
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --dep -j2 all
70+
- cabal new-build -w ${HC} ${TEST} ${BENCH} --dep -j2 ${TARGET}
71+
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --dep -j2 ${TARGET}
7372

7473
# Here starts the actual work to be performed for the package under test;
7574
# any command which exits with a non-zero exit code causes the build to fail.
@@ -85,14 +84,16 @@ script:
8584
## from here on, CWD is inside the extracted source-tarball
8685
- rm -fv cabal.project.local
8786
- "echo 'packages: .' > cabal.project"
87+
- if [ -e "../../cabal.project" ]; then cp -v "../../cabal.project" cabal.project; fi
88+
- ln -vs ../../vendor
8889
- if [ -e "../../cabal.project.local-${HC}" ]; then cp -v "../../cabal.project.local-${HC}" cabal.project.local; fi
8990
- rm -f cabal.project.freeze
9091
# this builds all libraries and executables (without tests/benchmarks)
9192
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks all
9293
# this builds all libraries and executables (including tests/benchmarks)
9394
# - rm -rf ./dist-newstyle
94-
- cabal new-build -w ${HC} ${TEST} ${BENCH} all
95+
- cabal new-build -w ${HC} ${TEST} ${BENCH} ${TARGET}
9596

96-
- cabal new-test -w ${HC} -j1 all
97+
- cabal new-test -w ${HC} -j1 ${TARGET}
9798

9899
# EOF

Distribution/Client.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ import Distribution.Server.Users.Types (UserId(..), UserName(UserName))
3737
import Distribution.Server.Util.Merge
3838
import Distribution.Server.Util.Parse (unpackUTF8)
3939
import Distribution.Package
40-
import Distribution.Version
4140
import Distribution.Verbosity
4241
import Distribution.Simple.Utils
4342
import Distribution.Text
4443

44+
import Data.Version
4545
import Data.List
4646
import Data.Maybe
4747
import Control.Applicative

Distribution/Client/Index.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ read mkPackage includeFile indexFileContent = collect [] entries
5353
entry e
5454
| [pkgname,versionStr,_] <- splitDirectories (normalise (Tar.entryPath e))
5555
, Just version <- simpleParse versionStr
56-
, [] <- versionTags version
5756
, True <- includeFile (Tar.entryPath e)
58-
= let pkgid = PackageIdentifier (PackageName pkgname) version
57+
= let pkgid = PackageIdentifier (mkPackageName pkgname) version
5958
in Just (mkPackage pkgid e)
6059
entry _ = Nothing

Distribution/Client/UploadLog.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Distribution.Package
2525
( PackageId, PackageName, packageName, PackageIdentifier(..))
2626
import Distribution.Text
2727
( Text(..), simpleParse )
28-
import Distribution.ParseUtils ( parsePackageNameQ )
28+
import Distribution.ParseUtils ( parseMaybeQuoted )
2929
import qualified Distribution.Compat.ReadP as Parse
3030
import qualified Text.PrettyPrint as Disp
3131
import Text.PrettyPrint
@@ -58,7 +58,7 @@ instance Text Entry where
5858
Parse.skipSpaces
5959
user <- parse
6060
Parse.skipSpaces
61-
pkg <- parsePackageNameQ
61+
pkg <- parseMaybeQuoted parse
6262
Parse.skipSpaces
6363
ver <- parse
6464
let pkgid = PackageIdentifier pkg ver

Distribution/Server/Features/BuildReports.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import qualified Distribution.Server.Framework.BlobStorage as BlobStorage
2424

2525
import Distribution.Text
2626
import Distribution.Package
27-
import Distribution.Version (Version(..))
27+
import Distribution.Version (nullVersion)
2828

2929
import Control.Arrow (second)
3030
import Data.ByteString.Lazy.Char8 (unpack) -- Build reports are ASCII
@@ -150,13 +150,13 @@ buildReportsFeature name
150150
packageReports :: DynamicPath -> ([(BuildReportId, BuildReport)] -> ServerPartE Response) -> ServerPartE Response
151151
packageReports dpath continue = do
152152
pkgid <- packageInPath dpath
153-
case pkgVersion pkgid of
154-
Version [] [] -> do
153+
if pkgVersion pkgid == nullVersion
154+
then do
155155
-- Redirect to the latest version
156156
pkginfo <- lookupPackageId pkgid
157157
seeOther (reportsListUri reportsResource "" (pkgInfoId pkginfo)) $
158158
toResponse ()
159-
_ -> do
159+
else do
160160
guardValidPackageId pkgid
161161
queryPackageReports pkgid >>= continue
162162

Distribution/Server/Features/BuildReports/Backup.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ insertLog buildReps ((pkgId, reportId), buildLog) =
6464
Nothing -> fail $ "Build log #" ++ display reportId ++ " exists for " ++ display pkgId ++ " but report itself does not"
6565

6666
checkPackageVersion :: String -> PackageIdentifier -> Restore ()
67-
checkPackageVersion pkgStr pkgId =
68-
case packageVersion pkgId of
69-
Version [] [] -> fail $ "Build report package id " ++ show pkgStr ++ " must specify a version"
70-
_ -> return ()
67+
checkPackageVersion pkgStr pkgId
68+
| packageVersion pkgId == nullVersion
69+
= fail $ "Build report package id " ++ show pkgStr ++ " must specify a version"
70+
| otherwise
71+
= return ()
7172

7273
importReport :: PackageId -> String -> ByteString -> BuildReports -> PartialLogs -> Restore (BuildReports, PartialLogs)
7374
importReport pkgId repIdStr contents buildReps partialLogs = do

Distribution/Server/Features/BuildReports/BuildReport.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ module Distribution.Server.Features.BuildReports.BuildReport (
3232

3333
import Distribution.Package
3434
( PackageIdentifier(..) )
35+
import Distribution.Types.GenericPackageDescription
36+
( FlagName, mkFlagName, unFlagName )
3537
import Distribution.PackageDescription
36-
( FlagName(..), FlagAssignment )
38+
( FlagAssignment )
3739
--import Distribution.Version
3840
-- ( Version )
3941
import Distribution.System
@@ -271,15 +273,15 @@ sortedFieldDescrs :: [FieldDescr BuildReport]
271273
sortedFieldDescrs = sortBy (comparing fieldName) fieldDescrs
272274

273275
dispFlag :: (FlagName, Bool) -> Disp.Doc
274-
dispFlag (FlagName name, True) = Disp.text name
275-
dispFlag (FlagName name, False) = Disp.char '-' <> Disp.text name
276+
dispFlag (fn, True) = Disp.text (unFlagName fn)
277+
dispFlag (fn, False) = Disp.char '-' <> Disp.text (unFlagName fn)
276278

277279
parseFlag :: Parse.ReadP r (FlagName, Bool)
278280
parseFlag = do
279281
name <- Parse.munch1 (\c -> Char.isAlphaNum c || c == '_' || c == '-')
280282
case name of
281-
('-':flag) -> return (FlagName flag, False)
282-
flag -> return (FlagName flag, True)
283+
('-':flag) -> return (mkFlagName flag, False)
284+
flag -> return (mkFlagName flag, True)
283285

284286
instance Text.Text InstallOutcome where
285287
disp PlanningFailed = Disp.text "PlanningFailed"

Distribution/Server/Features/Core.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import qualified Distribution.Server.Packages.PackageIndex as PackageIn
4949
-- Cabal
5050
import Distribution.Text (display)
5151
import Distribution.Package
52-
import Distribution.Version (Version(..))
52+
import Distribution.Version (Version, nullVersion)
5353

5454
-- | The core feature, responsible for the main package index and all access
5555
-- and modifications of it.
@@ -457,11 +457,11 @@ coreFeature ServerEnv{serverBlobStore = store} UserFeature{..}
457457
-- * the package name and tarball name must be the same
458458
-- * the tarball must specify a version
459459
-- * the package must either have no version or the same version as the tarball
460-
guard $ name == name' && version' /= Version [] [] && (version == version' || version == Version [] [])
460+
guard $ name == name' && version' /= nullVersion && (version == version' || version == nullVersion)
461461
return pkgid
462462

463463
guardValidPackageId pkgid = do
464-
guard (pkgVersion pkgid /= Version [] [])
464+
guard (pkgVersion pkgid /= nullVersion)
465465
void $ lookupPackageId pkgid
466466

467467
guardValidPackageName pkgname =
@@ -603,7 +603,7 @@ coreFeature ServerEnv{serverBlobStore = store} UserFeature{..}
603603
pkgs -> return pkgs
604604

605605
lookupPackageId :: PackageId -> ServerPartE PkgInfo
606-
lookupPackageId (PackageIdentifier name (Version [] [])) = do
606+
lookupPackageId (PackageIdentifier name v) | nullVersion == v = do
607607
pkgs <- lookupPackageName name
608608
-- pkgs is sorted by version number and non-empty
609609
return (last pkgs)
@@ -660,7 +660,7 @@ coreFeature ServerEnv{serverBlobStore = store} UserFeature{..}
660660
servePackageTarball :: DynamicPath -> ServerPartE Response
661661
servePackageTarball dpath = do
662662
pkgid <- packageTarballInPath dpath
663-
guard (pkgVersion pkgid /= Version [] [])
663+
guard (pkgVersion pkgid /= nullVersion)
664664
pkg <- lookupPackageId pkgid
665665
case pkgLatestTarball pkg of
666666
Nothing -> errNotFound "Tarball not found"

Distribution/Server/Features/Distro.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import Distribution.Package
2121

2222
import Data.List (intercalate)
2323
import Text.CSV (parseCSV)
24-
import Data.Version (showVersion)
2524

2625
-- TODO:
2726
-- 1. write an HTML view for this module, and delete the text
@@ -252,7 +251,7 @@ lookCSVFile func = do
252251

253252
packageListToCSV :: [(PackageName, DistroPackageInfo)] -> CSVFile
254253
packageListToCSV entries
255-
= CSVFile $ map (\(pn,DistroPackageInfo version url) -> [display pn, showVersion version, url]) entries
254+
= CSVFile $ map (\(pn,DistroPackageInfo version url) -> [display pn, display version, url]) entries
256255

257256
csvToPackageList :: CSVFile -> Either String [(PackageName, DistroPackageInfo)]
258257
csvToPackageList (CSVFile records)

Distribution/Server/Features/Distro/Backup.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import Distribution.Server.Framework.BackupDump
1818
import Distribution.Server.Framework.BackupRestore
1919

2020
import Distribution.Text
21-
import Data.Version
2221
import Text.CSV (CSV, Record)
2322

23+
import Data.Version
2424
import qualified Data.Map as Map
2525
import Data.Map (Map)
2626
import Data.List (foldl')
@@ -117,7 +117,7 @@ distroToCSV distro distInfo
117117
(distrosCSVKey:) $
118118
flip map stats . uncurry $
119119
\name (DistroPackageInfo version url) ->
120-
[display name, showVersion version, url]
120+
[display name, display version, url]
121121
where
122122
distrosCSVKey = ["package", "version", "url"]
123123
distrosCSVVer = Version [0,1] ["unstable"]

Distribution/Server/Features/Documentation.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import qualified Codec.Archive.Tar.Check as Tar
2424

2525
import Distribution.Text
2626
import Distribution.Package
27-
import Distribution.Version (Version(..))
27+
import Distribution.Version (nullVersion)
2828

2929
import qualified Data.ByteString.Lazy as BSL
3030
import qualified Data.Map as Map
@@ -314,9 +314,9 @@ documentationFeature name
314314
-- See https://support.google.com/webmasters/answer/139066?hl=en#6
315315
setHeaderM "Link" canonicalHeader
316316

317-
case pkgVersion pkgid of
317+
case pkgVersion pkgid == nullVersion of
318318
-- if no version is given we want to redirect to the latest version
319-
Version [] _ -> tempRedirect latestPkgPath (toResponse "")
319+
True -> tempRedirect latestPkgPath (toResponse "")
320320
where
321321
latest = packageId pkginfo
322322
dpath' = [ if var == "package"
@@ -325,7 +325,7 @@ documentationFeature name
325325
| e@(var, _) <- dpath ]
326326
latestPkgPath = (renderResource' self dpath')
327327

328-
_ -> do
328+
False -> do
329329
mdocs <- queryState documentationState $ LookupDocumentation pkgid
330330
case mdocs of
331331
Nothing ->

Distribution/Server/Features/DownloadCount/Backup.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Distribution.Server.Framework.BackupDump
1010
import Distribution.Server.Features.DownloadCount.State
1111
import Distribution.Server.Util.CountingMap
1212
import Distribution.Text (display, simpleParse)
13-
import Distribution.Version
13+
import Data.Version
1414
import Text.CSV (CSV)
1515

1616
onDiskBackup :: OnDiskStats -> [BackupEntry]

Distribution/Server/Features/DownloadCount/State.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
module Distribution.Server.Features.DownloadCount.State where
55

66
import Data.Time.Calendar (Day(..))
7-
import Data.Version (Version)
87
import Data.Typeable (Typeable)
98
import Data.Foldable (forM_)
109
import Control.Arrow (first)
@@ -31,6 +30,7 @@ import Data.SafeCopy (base, deriveSafeCopy, safeGet, safePut)
3130
import Data.Serialize.Get (runGetLazy)
3231
import Data.Serialize.Put (runPutLazy)
3332

33+
import Distribution.Version (Version)
3434
import Distribution.Package (
3535
PackageId
3636
, PackageName

Distribution/Server/Features/Html.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ mkHtmlPreferred HtmlUtilities{..}
13181318
, h4 << "Versions affected"
13191319
, paragraph << "Orange versions are normal versions. Green are those out of any preferred version ranges. Gray are deprecated."
13201320
, paragraph << (snd $ Pages.renderVersion
1321-
(PackageIdentifier pkgname $ Version [] [])
1321+
(PackageIdentifier pkgname $ nullVersion)
13221322
(classifyVersions prefInfo $ map packageVersion pkgs) Nothing)
13231323
]
13241324

Distribution/Server/Features/LegacyRedirects.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Distribution.Package
1212
import Distribution.Text
1313
( display, simpleParse )
1414

15-
import Data.Version ( Version (..) )
15+
import Distribution.Version ( Version, nullVersion )
1616

1717
import qualified System.FilePath.Posix as Posix (joinPath, splitExtension)
1818

@@ -104,7 +104,7 @@ instance FromReqURI VersionOrLatest where
104104
fromReqURI str = V <$> fromReqURI str
105105

106106
volToVersion :: VersionOrLatest -> Version
107-
volToVersion Latest = Version [] []
107+
volToVersion Latest = nullVersion
108108
volToVersion (V v) = v
109109

110110
serveArchiveTree :: ServerPartE Response

Distribution/Server/Features/PackageCandidates.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import Distribution.Server.Pages.Template (hackagePage)
3636

3737
import Distribution.Text
3838
import Distribution.Package
39+
import Distribution.Version
40+
import Distribution.Types.Dependency
3941

4042
import qualified Cheapskate as Markdown (markdown, Options(..))
4143
import qualified Cheapskate.Html as Markdown (renderDoc)
@@ -279,7 +281,7 @@ candidatesFeature ServerEnv{serverBlobStore = store}
279281
putPackageCandidate :: DynamicPath -> ServerPartE Response
280282
putPackageCandidate dpath = do
281283
pkgid <- packageInPath dpath
282-
guard (packageVersion pkgid /= Version [] [])
284+
guard (packageVersion pkgid /= nullVersion)
283285
pkgInfo <- uploadCandidate (==pkgid)
284286
seeOther (corePackageIdUri candidatesCoreResource "" $ packageId pkgInfo) (toResponse ())
285287

@@ -294,7 +296,7 @@ candidatesFeature ServerEnv{serverBlobStore = store}
294296
serveCandidateTarball :: DynamicPath -> ServerPartE Response
295297
serveCandidateTarball dpath = do
296298
pkgid <- packageTarballInPath dpath
297-
guard (pkgVersion pkgid /= Version [] [])
299+
guard (pkgVersion pkgid /= nullVersion)
298300
pkg <- lookupCandidateId pkgid
299301
case pkgLatestTarball (candPkgInfo pkg) of
300302
Nothing -> errNotFound "Tarball not found"
@@ -434,7 +436,7 @@ candidatesFeature ServerEnv{serverBlobStore = store}
434436
-- (If we change that, we should move the 'guard' to 'guardValidPackageId')
435437
lookupCandidateId :: PackageId -> ServerPartE CandPkgInfo
436438
lookupCandidateId pkgid = do
437-
guard (pkgVersion pkgid /= Version [] [])
439+
guard (pkgVersion pkgid /= nullVersion)
438440
state <- queryState candidatesState GetCandidatePackages
439441
case PackageIndex.lookupPackageId (candidateList state) pkgid of
440442
Just pkg -> return pkg

0 commit comments

Comments
 (0)