Skip to content

Commit 955c736

Browse files
committed
add runTests to acid state
1 parent e2f5f8d commit 955c736

File tree

5 files changed

+93
-22
lines changed

5 files changed

+93
-22
lines changed

exes/BuildClient.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ getDocumentationStats verbosity opts config pkgs = do
457457
(False, Just (BR.BuildFailCnt a))
458458
| a >= bo_buildAttempts opts -> DocsFailed
459459
(False, _) -> DocsNotBuilt
460-
in (pkgId, hasDocs, BR.runTests pkgDetails)
460+
in (pkgId, hasDocs, fromMaybe True $ BR.runTests pkgDetails)
461461

462462
setIsCandidate :: Bool -> (PackageIdentifier, HasDocs, Bool) -> DocInfo
463463
setIsCandidate isCandidate (pId, hasDocs, runTests) = DocInfo {

src/Distribution/Server/Features/BuildReports.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,13 @@ buildReportsFeature name
201201
pkgReportDetails (pkgid, docs) = do
202202
failCnt <- queryState reportsState $ LookupFailCount pkgid
203203
latestRpt <- queryState reportsState $ LookupLatestReport pkgid
204+
runTests <- queryState reportsState $ LookupRunTests pkgid
204205
(time, ghcId) <- case latestRpt of
205206
Nothing -> return (Nothing,Nothing)
206207
Just (_, brp, _, _) -> do
207208
let (CompilerId _ vrsn) = compiler brp
208209
return (time brp, Just vrsn)
209-
return (BuildReport.PkgDetails pkgid docs failCnt time ghcId {- TODO -}True)
210+
return (BuildReport.PkgDetails pkgid docs failCnt time ghcId runTests)
210211

211212
queryLastReportStats :: MonadIO m => PackageIdentifier -> m (Maybe (BuildReportId, BuildReport, Maybe BuildCovg))
212213
queryLastReportStats pkgid = do

src/Distribution/Server/Features/BuildReports/BuildReport.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ data PkgDetails = PkgDetails {
624624
failCnt :: Maybe BuildStatus,
625625
buildTime :: Maybe UTCTime,
626626
ghcId :: Maybe Version,
627-
runTests :: Bool
627+
runTests :: Maybe Bool
628628
} deriving(Show)
629629

630630
instance Data.Aeson.ToJSON PkgDetails where

src/Distribution/Server/Features/BuildReports/BuildReports.hs

Lines changed: 78 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ module Distribution.Server.Features.BuildReports.BuildReports (
2222
setFailStatus,
2323
resetFailCount,
2424
lookupLatestReport,
25-
lookupFailCount
25+
lookupFailCount,
26+
lookupRunTests,
27+
setRunTests
2628
) where
2729

2830
import qualified Distribution.Server.Framework.BlobStorage as BlobStorage
@@ -86,18 +88,21 @@ data PkgBuildReports = PkgBuildReports {
8688
reports :: !(Map BuildReportId (BuildReport, Maybe BuildLog, Maybe BuildCovg )),
8789
-- one more than the maximum report id used
8890
nextReportId :: !BuildReportId,
89-
buildStatus :: !BuildStatus
91+
buildStatus :: !BuildStatus,
92+
runTests :: !Bool
9093
} deriving (Eq, Typeable, Show)
9194

9295
data BuildReports = BuildReports {
9396
reportsIndex :: !(Map.Map PackageId PkgBuildReports)
97+
9498
} deriving (Eq, Typeable, Show)
9599

96100
emptyPkgReports :: PkgBuildReports
97101
emptyPkgReports = PkgBuildReports {
98102
reports = Map.empty,
99103
nextReportId = BuildReportId 1,
100-
buildStatus = BuildFailCnt 0
104+
buildStatus = BuildFailCnt 0,
105+
runTests = True
101106
}
102107

103108
emptyReports :: BuildReports
@@ -126,15 +131,17 @@ addReport pkgid (brpt,blog) buildReports =
126131
reportId = nextReportId pkgReports
127132
pkgReports' = PkgBuildReports { reports = Map.insert reportId (brpt,blog,Nothing) (reports pkgReports)
128133
, nextReportId = incrementReportId reportId
129-
, buildStatus = buildStatus pkgReports }
134+
, buildStatus = buildStatus pkgReports
135+
, runTests = runTests pkgReports }
130136
in (buildReports { reportsIndex = Map.insert pkgid pkgReports' (reportsIndex buildReports) }, reportId)
131137

132138
unsafeSetReport :: PackageId -> BuildReportId -> (BuildReport, Maybe BuildLog) -> BuildReports -> BuildReports
133139
unsafeSetReport pkgid reportId (brpt,blog) buildReports =
134140
let pkgReports = Map.findWithDefault emptyPkgReports pkgid (reportsIndex buildReports)
135141
pkgReports' = PkgBuildReports { reports = Map.insert reportId (brpt,blog,Nothing) (reports pkgReports)
136142
, nextReportId = max (incrementReportId reportId) (nextReportId pkgReports)
137-
, buildStatus = buildStatus pkgReports }
143+
, buildStatus = buildStatus pkgReports
144+
, runTests = runTests pkgReports }
138145
in buildReports { reportsIndex = Map.insert pkgid pkgReports' (reportsIndex buildReports) }
139146

140147
deleteReport :: PackageId -> BuildReportId -> BuildReports -> Maybe BuildReports
@@ -159,7 +166,8 @@ addRptLogCovg pkgid report buildReports =
159166
reportId = nextReportId pkgReports
160167
pkgReports' = PkgBuildReports { reports = Map.insert reportId report (reports pkgReports)
161168
, nextReportId = incrementReportId reportId
162-
, buildStatus = buildStatus pkgReports }
169+
, buildStatus = buildStatus pkgReports
170+
, runTests = runTests pkgReports }
163171
in (buildReports { reportsIndex = Map.insert pkgid pkgReports' (reportsIndex buildReports) }, reportId)
164172

165173
lookupReportCovg :: PackageId -> BuildReportId -> BuildReports -> Maybe (BuildReport, Maybe BuildLog, Maybe BuildCovg )
@@ -170,7 +178,8 @@ setFailStatus pkgid fStatus buildReports =
170178
let pkgReports = Map.findWithDefault emptyPkgReports pkgid (reportsIndex buildReports)
171179
pkgReports' = PkgBuildReports { reports = (reports pkgReports)
172180
, nextReportId = (nextReportId pkgReports)
173-
, buildStatus = (getfst fStatus (buildStatus pkgReports)) }
181+
, buildStatus = (getfst fStatus (buildStatus pkgReports))
182+
, runTests = runTests pkgReports }
174183
in buildReports { reportsIndex = Map.insert pkgid pkgReports' (reportsIndex buildReports) }
175184
where
176185
getfst nfst cfst = do
@@ -185,7 +194,8 @@ resetFailCount pkgid buildReports = case Map.lookup pkgid (reportsIndex buildRep
185194
Just pkgReports -> do
186195
let pkgReports' = PkgBuildReports { reports = (reports pkgReports)
187196
, nextReportId = (nextReportId pkgReports)
188-
, buildStatus = BuildFailCnt 0 }
197+
, buildStatus = BuildFailCnt 0
198+
, runTests = runTests pkgReports }
189199
return buildReports { reportsIndex = Map.insert pkgid pkgReports' (reportsIndex buildReports) }
190200

191201
lookupFailCount :: PackageId -> BuildReports -> Maybe BuildStatus
@@ -203,6 +213,16 @@ lookupLatestReport pkgid buildReports = do
203213
else Just $ Map.findMax rs
204214
Just (maxKey, rep, buildLog, covg)
205215

216+
lookupRunTests :: PackageId -> BuildReports -> Maybe Bool
217+
lookupRunTests pkgid buildReports = do
218+
rp <- Map.lookup pkgid (reportsIndex buildReports)
219+
pure (runTests rp)
220+
221+
setRunTests :: PackageId -> Bool -> BuildReports -> BuildReports
222+
setRunTests pkgid b buildReports =
223+
let rp = Map.findWithDefault emptyPkgReports pkgid (reportsIndex buildReports)
224+
in BuildReports (Map.insert pkgid rp{runTests = b} (reportsIndex buildReports))
225+
206226
-- addPkg::`
207227
-------------------
208228
-- HStringTemplate instances
@@ -247,20 +267,41 @@ deriveSafeCopy 2 'extension ''BuildLog
247267
-- however, upon importing, nextReportId will = 3, one more than the maximum present
248268
-- this is also a problem in ReportsBackup.hs. but it's not a major issue I think.
249269
instance SafeCopy PkgBuildReports where
250-
version = 3
270+
version = 4
251271
kind = extension
252-
putCopy (PkgBuildReports x _ y) = contain $ safePut (x,y)
272+
putCopy (PkgBuildReports x _ y z) = contain $ safePut (x,y,z)
253273
getCopy = contain $ mkReports <$> safeGet
254274
where
255-
mkReports (rs,f) = PkgBuildReports rs
275+
mkReports (rs,f,b) = PkgBuildReports rs
256276
(if Map.null rs
257277
then BuildReportId 1
258278
else incrementReportId (fst $ Map.findMax rs))
259-
f
279+
f b
260280

261281
instance MemSize PkgBuildReports where
262-
memSize (PkgBuildReports a b c) = memSize3 a b c
282+
memSize (PkgBuildReports a b c d) = memSize4 a b c d
283+
284+
285+
data PkgBuildReports_v3 = PkgBuildReports_v3 {
286+
reports_v3 :: !(Map BuildReportId (BuildReport, Maybe BuildLog, Maybe BuildCovg )),
287+
nextReportId_v3 :: !BuildReportId,
288+
buildStatus_v3 :: !BuildStatus
289+
} deriving (Eq, Typeable, Show)
290+
291+
instance SafeCopy PkgBuildReports_v3 where
292+
version = 3
293+
kind = extension
294+
putCopy (PkgBuildReports_v3 x _ y) = contain $ safePut (x,y)
295+
getCopy = contain $ mkReports <$> safeGet
296+
where
297+
mkReports (rs,f) = PkgBuildReports_v3 rs
298+
(if Map.null rs
299+
then BuildReportId 1
300+
else incrementReportId (fst $ Map.findMax rs))
301+
f
263302

303+
instance MemSize PkgBuildReports_v3 where
304+
memSize (PkgBuildReports_v3 a b c) = memSize3 a b c
264305

265306
data PkgBuildReports_v2 = PkgBuildReports_v2 {
266307
reports_v2 :: !(Map BuildReportId (BuildReport, Maybe BuildLog)),
@@ -309,16 +350,20 @@ instance Migrate PkgBuildReports_v2 where
309350
. Map.map (\(br, l) -> (migrate (migrate br),
310351
fmap migrate l))
311352

312-
instance Migrate PkgBuildReports where
313-
type MigrateFrom PkgBuildReports = PkgBuildReports_v2
353+
instance Migrate PkgBuildReports_v3 where
354+
type MigrateFrom PkgBuildReports_v3 = PkgBuildReports_v2
314355
migrate (PkgBuildReports_v2 m n) =
315-
PkgBuildReports (migrateMap m) n BuildOK
356+
PkgBuildReports_v3 (migrateMap m) n BuildOK
316357
where
317358
migrateMap :: Map BuildReportId (BuildReport, Maybe BuildLog)
318359
-> Map BuildReportId (BuildReport, Maybe BuildLog, Maybe BuildCovg)
319360
migrateMap = Map.mapKeys (\x->x)
320361
. Map.map (\(br, l) -> (br, l, Nothing))
321362

363+
instance Migrate PkgBuildReports where
364+
type MigrateFrom PkgBuildReports = PkgBuildReports_v3
365+
migrate (PkgBuildReports_v3 m n c) =
366+
PkgBuildReports m n c True
322367

323368
data BuildReports_v0 = BuildReports_v0
324369
!(Map.Map PackageIdentifier_v0 PkgBuildReports_v0)
@@ -345,12 +390,26 @@ instance MemSize BuildReports_v2 where
345390

346391
deriveSafeCopy 2 'extension ''BuildReports_v2
347392

348-
instance Migrate BuildReports where
349-
type MigrateFrom BuildReports = BuildReports_v2
393+
data BuildReports_v3 = BuildReports_v3
394+
{ reportsIndex_v3 :: !(Map.Map PackageId PkgBuildReports_v3)
395+
} deriving (Eq, Typeable, Show)
396+
397+
instance Migrate BuildReports_v3 where
398+
type MigrateFrom BuildReports_v3 = BuildReports_v2
350399
migrate (BuildReports_v2 m) =
400+
BuildReports_v3 (Map.mapKeys id $ Map.map migrate m)
401+
402+
instance MemSize BuildReports_v3 where
403+
memSize (BuildReports_v3 a) = memSize1 a
404+
405+
deriveSafeCopy 3 'extension ''BuildReports_v3
406+
407+
instance Migrate BuildReports where
408+
type MigrateFrom BuildReports = BuildReports_v3
409+
migrate (BuildReports_v3 m) =
351410
BuildReports (Map.mapKeys id $ Map.map migrate m)
352411

353412
instance MemSize BuildReports where
354413
memSize (BuildReports a) = memSize1 a
355414

356-
deriveSafeCopy 3 'extension ''BuildReports
415+
deriveSafeCopy 4 'extension ''BuildReports

src/Distribution/Server/Features/BuildReports/State.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ lookupFailCount pkgid = asks (BuildReports.lookupFailCount pkgid)
8080
lookupLatestReport :: PackageId -> Query BuildReports (Maybe (BuildReportId, BuildReport, Maybe BuildLog, Maybe BuildCovg))
8181
lookupLatestReport pkgid = asks (BuildReports.lookupLatestReport pkgid)
8282

83+
lookupRunTests :: PackageId -> Query BuildReports (Maybe Bool)
84+
lookupRunTests pkgid = asks (BuildReports.lookupRunTests pkgid)
85+
86+
setRunTests :: PackageId -> Bool -> Update BuildReports ()
87+
setRunTests pkgid b = do
88+
buildReports <- State.get
89+
let reports = BuildReports.setRunTests pkgid b buildReports
90+
State.put reports
91+
8392
makeAcidic ''BuildReports ['addReport
8493
,'setBuildLog
8594
,'deleteReport
@@ -93,5 +102,7 @@ makeAcidic ''BuildReports ['addReport
93102
,'resetFailCount
94103
,'lookupFailCount
95104
,'lookupLatestReport
105+
,'lookupRunTests
106+
,'setRunTests
96107
]
97108

0 commit comments

Comments
 (0)