-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathBuildReport.hs
More file actions
703 lines (597 loc) · 23.1 KB
/
Copy pathBuildReport.hs
File metadata and controls
703 lines (597 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Client.Reporting
-- Copyright : (c) David Waern 2008
-- License : BSD-like
--
-- Maintainer : david.waern@gmail.com
-- Stability : experimental
-- Portability : portable
--
-- Anonymous build report data structure, printing and parsing
--
-----------------------------------------------------------------------------
module Distribution.Server.Features.BuildReports.BuildReport (
BuildReport(..),
InstallOutcome(..),
Outcome(..),
-- * parsing and pretty printing
read,
parse,
parseList,
show,
showList,
affixTimestamp,
parseCovg,
BuildReport_v0,
BuildFiles(..),
PkgDetails(..),
BuildStatus(..),
BuildCovg(..),
BooleanCovg(..),
) where
import Distribution.Compat.Newtype
import Distribution.Compat.Lens (Lens')
import Distribution.Package
( PackageIdentifier(..) )
import Distribution.Types.Flag
( FlagName, unFlagName, mkFlagName )
import Distribution.System
( OS, Arch )
import Distribution.Compiler
( CompilerId )
import Distribution.CabalSpecVersion
( CabalSpecVersion(CabalSpecV2_4) )
import Distribution.Pretty
( Pretty(..), pretty, prettyShow )
#if MIN_VERSION_Cabal(3,7,0)
import Distribution.Fields.Pretty
( pattern NoComment )
#endif
import qualified Text.PrettyPrint as Disp
import Distribution.Parsec
( Parsec(..), PError(..), parsec )
import qualified Distribution.Parsec as P
import qualified Distribution.Compat.CharParsing as P
import Distribution.FieldGrammar
( FieldGrammar, parseFieldGrammar, prettyFieldGrammar, partitionFields
, uniqueField, uniqueFieldAla, booleanFieldDef, monoidalFieldAla
, List, alaList
, VCat(..), FSep(..) )
import Distribution.Fields.Parser
( readFields )
import Distribution.Fields.Pretty
( showFields )
import Distribution.Fields.ParseResult
(ParseResult, parseFatalFailure, runParseResult )
import Distribution.Server.Framework.Instances ()
import Distribution.Server.Framework.MemSize
import Text.PrettyPrint.HughesPJ
( (<+>) )
import Data.Serialize as Serialize
( Serialize(..) )
import Data.SafeCopy
( SafeCopy(..), deriveSafeCopy, extension, base, Migrate(..), contain )
import Test.QuickCheck
( Arbitrary(..), elements, oneof )
import Text.StringTemplate ()
import Text.StringTemplate.Classes
( SElem(..), ToSElem(..) )
import Data.Aeson
import Data.Functor.Identity (Identity)
import Data.List
( unfoldr, isInfixOf )
import Data.List.NonEmpty (toList)
import Data.Char as Char
( isAlpha, isAlphaNum )
import qualified Data.ByteString.Char8 as BS
import qualified Data.Map as Map
import Data.Time
( UTCTime, getCurrentTime )
import Data.Typeable
( Typeable )
import Control.Applicative
import Control.Monad
import Prelude hiding (show, read)
import Distribution.Version ( Version )
import Data.Maybe
import Data.Scientific
import qualified Distribution.Text as DT
import qualified Prelude
import Data.Attoparsec.Text (Parser, char, decimal, parseOnly, takeTill)
import qualified Data.Text as T
data BuildReport
= BuildReport {
-- | The package this build report is about
package :: PackageIdentifier,
-- | The time at which the report was uploaded
time :: Maybe UTCTime,
-- | Whether the client was generating documentation for upload
docBuilder :: Bool,
-- | The OS and Arch the package was built on
os :: OS,
arch :: Arch,
-- | The Haskell compiler (and hopefully version) used
compiler :: CompilerId,
-- | The uploading client, ie cabal-install-x.y.z
client :: PackageIdentifier,
-- | Which configurations flags we used
flagAssignment :: [(FlagName,Bool)],
-- TODO: this is the pre-Cabal-2.2 'FlagAssignment' type;
-- consider changing this to the new opaque 'FlagAssignment' type at some point
-- (which will have implications for the safecopy serialisation)
-- | Which dependent packages we were using exactly
dependencies :: [PackageIdentifier],
-- | Did installing work ok?
installOutcome :: InstallOutcome,
-- Which version of the Cabal library was used to compile the Setup.hs
-- cabalVersion :: Version,
-- Which build tools we were using (with versions)
-- tools :: [PackageIdentifier],
-- | Configure outcome, did configure work ok?
docsOutcome :: Outcome,
-- | Configure outcome, did configure work ok?
testsOutcome :: Outcome
}
deriving (Eq, Typeable, Show)
packageL :: Lens' BuildReport PackageIdentifier
packageL f s = fmap (\x -> s { package = x }) (f (package s))
timeL :: Lens' BuildReport (Maybe UTCTime)
timeL f s = fmap (\x -> s { time = x }) (f (time s))
docBuilderL :: Lens' BuildReport Bool
docBuilderL f s = fmap (\x -> s { docBuilder = x }) (f (docBuilder s))
osL :: Lens' BuildReport OS
osL f s = fmap (\x -> s { os = x }) (f (os s))
archL :: Lens' BuildReport Arch
archL f s = fmap (\x -> s { arch = x }) (f (arch s))
compilerL :: Lens' BuildReport CompilerId
compilerL f s = fmap (\x -> s { compiler = x }) (f (compiler s))
clientL :: Lens' BuildReport PackageIdentifier
clientL f s = fmap (\x -> s { client = x }) (f (client s))
-- flagAssignmentL :: Lens' BuildReport [(FlagName,Bool)]
-- flagAssignmentL f s = fmap (\x -> s { flagAssignment = x }) (f (flagAssignment s))
flagAssignmentL' :: Lens' BuildReport [FlagAss1]
flagAssignmentL' f s = fmap (\x -> s { flagAssignment = map unpack x })
(f (map pack (flagAssignment s)))
dependenciesL :: Lens' BuildReport [PackageIdentifier]
dependenciesL f s = fmap (\x -> s { dependencies = x }) (f (dependencies s))
installOutcomeL :: Lens' BuildReport InstallOutcome
installOutcomeL f s = fmap (\x -> s { installOutcome = x }) (f (installOutcome s))
docsOutcomeL :: Lens' BuildReport Outcome
docsOutcomeL f s = fmap (\x -> s { docsOutcome = x }) (f (docsOutcome s))
testsOutcomeL :: Lens' BuildReport Outcome
testsOutcomeL f s = fmap (\x -> s { testsOutcome = x }) (f (testsOutcome s))
data InstallOutcome
= PlanningFailed
| DependencyFailed PackageIdentifier
| DownloadFailed
| UnpackFailed
| SetupFailed
| ConfigureFailed
| BuildFailed
| InstallFailed
| InstallOk
deriving (Eq, Ord, Show)
data Outcome = NotTried | Failed | Ok deriving (Eq, Ord, Show)
-- -----------------------------------------------------------------------------
-- Timestamps
-- | If the 'time' field is empty, fill it in with the current time.
affixTimestamp :: BuildReport -> IO BuildReport
affixTimestamp report = case time report of
Nothing -> (\v -> report { time = Just v }) <$> getCurrentTime
Just _ -> return report
-- -----------------------------------------------------------------------------
-- Parsing
read :: BS.ByteString -> BuildReport
read s = case parse s of
Left err -> error $ "error parsing build report: " ++ err
Right rpt -> rpt
parse :: BS.ByteString -> Either String BuildReport
parse s = case snd $ runParseResult $ parseFields s of
Left (_, perrors) -> Left $ unlines [ err | PError _ err <- toList perrors ]
Right report -> Right report
parseFields :: BS.ByteString -> ParseResult BuildReport
parseFields input = do
fields <- either (parseFatalFailure P.zeroPos . Prelude.show) pure $ readFields input
case partitionFields fields of
(fields', []) -> parseFieldGrammar CabalSpecV2_4 fields' fieldDescrs
_otherwise -> parseFatalFailure P.zeroPos "found sections in BuildReport" -- TODO
parseList :: BS.ByteString -> [BuildReport]
parseList str =
[ report | Right report <- map parse (split str) ]
where
split :: BS.ByteString -> [BS.ByteString]
split = filter (not . BS.null) . unfoldr chunk . BS.lines
chunk [] = Nothing
chunk ls = case break BS.null ls of
(r, rs) -> Just (BS.unlines r, dropWhile BS.null rs)
data BooleanCovg = BooleanCovg {
guards :: (Int,Int),
ifConditions :: (Int,Int),
qualifiers :: (Int,Int)
} deriving (Eq, Typeable, Show)
data BuildCovg = BuildCovg {
expressions :: (Int,Int),
boolean :: BooleanCovg,
alternatives :: (Int,Int),
localDeclarations :: (Int,Int),
topLevel :: (Int,Int)
} deriving (Eq, Typeable, Show)
instance Arbitrary BuildCovg where
arbitrary =
BuildCovg
<$> intPair
<*> liftA3 BooleanCovg intPair intPair intPair
<*> intPair
<*> intPair
<*> intPair
where intPair = liftA2 (,) arbitrary arbitrary
instance MemSize BuildCovg where
memSize (BuildCovg a (BooleanCovg b c d) e f g) = memSize7 a b c d e f g
-- -----------------------------------------------------------------------------
-- Parse Coverage Report
parseCovg :: String -> BuildCovg
parseCovg s = do
let ln = lines (s++"\n\n")
let buildC = BuildCovg (0,0) (BooleanCovg (0,0) (0,0) (0,0)) (0,0) (0,0) (0,0)
parseLines ln buildC
-- buildC
parseLines :: [String] -> BuildCovg -> BuildCovg
parseLines (x:y) (BuildCovg a (BooleanCovg b c d) e f g)
| isInfixOf "expressions used" x = parseLines y (BuildCovg (getUsage x) (BooleanCovg b c d) e f g)
| isInfixOf "guards" x = parseLines y (BuildCovg a (BooleanCovg (getUsage x) c d) e f g)
| isInfixOf "conditions" x = parseLines y (BuildCovg a (BooleanCovg b (getUsage x) d) e f g)
| isInfixOf "qualifiers" x = parseLines y (BuildCovg a (BooleanCovg b c (getUsage x)) e f g)
| isInfixOf "alternatives used" x = parseLines y (BuildCovg a (BooleanCovg b c d) (getUsage x) f g)
| isInfixOf "local declarations used" x = parseLines y (BuildCovg a (BooleanCovg b c d) e (getUsage x) g)
| isInfixOf "top-level declarations used" x = parseLines y (BuildCovg a (BooleanCovg b c d) e f (getUsage x))
parseLines (_:y) buildc = parseLines y buildc
parseLines _ buildc = buildc
getUsage :: String -> (Int,Int)
getUsage bs = do
let parsed = parseOnly intPair $ T.pack bs
case parsed of
Left _ -> (0,0)
Right a -> a
intPair :: Parser (Int, Int)
intPair = do
n <- takeTill ('('==) *> char '(' *> decimal
m <- char '/' *> decimal <* char ')'
pure (n, m)
-- -----------------------------------------------------------------------------
-- Pretty-printing
show :: BuildReport -> String
show = showFields noComment . prettyFieldGrammar CabalSpecV2_4 fieldDescrs
where
#if MIN_VERSION_Cabal(3,7,0)
noComment _ = NoComment
#else
noComment _ = []
#endif
-- -----------------------------------------------------------------------------
-- Description of the fields, for parsing/printing
fieldDescrs
:: ( Applicative (g BuildReport), FieldGrammar c g
, c (Identity Arch)
, c (Identity CompilerId)
, c (List FSep (Identity FlagAss1) FlagAss1)
-- , c (Identity FlagAssignment)
, c (Identity InstallOutcome)
, c (Identity OS)
, c (Identity Outcome)
, c (Identity PackageIdentifier)
, c (List VCat (Identity PackageIdentifier) PackageIdentifier)
, c Time
)
=> g BuildReport BuildReport
fieldDescrs =
BuildReport
<$> uniqueField "package" packageL
<*> uniqueFieldAla "time" (pack' Time) timeL
<*> booleanFieldDef "doc-builder" docBuilderL False
<*> uniqueField "os" osL
<*> uniqueField "arch" archL
<*> uniqueField "compiler" compilerL
<*> uniqueField "client" clientL
<*> (map unpack <$>
monoidalFieldAla "flags" (alaList FSep) flagAssignmentL')
<*> monoidalFieldAla "dependencies" (alaList VCat) dependenciesL
<*> uniqueField "install-outcome" installOutcomeL
<*> uniqueField "docs-outcome" docsOutcomeL
<*> uniqueField "tests-outcome" testsOutcomeL
-- local instances for (FlagName,Bool)
newtype FlagAss1 = FlagAss1 (FlagName,Bool)
instance Newtype (FlagName,Bool) FlagAss1
instance Parsec FlagAss1 where
parsec = fmap FlagAss1 (posPolarity <|> negPolarity <|> noPolarity)
where
posPolarity = do
P.char '+'
(,) <$> flagName <*> pure True
negPolarity = do
P.char '-'
(,) <$> flagName <*> pure False
noPolarity =
(,) <$> flagName <*> pure True
-- this is subtly different from Cabal's 'FlagName' parser
flagName = mkFlagName <$> P.munch1 (\c -> Char.isAlphaNum c || c == '_' || c == '-')
instance Pretty FlagAss1 where
pretty (FlagAss1 (fn, True)) = Disp.text (unFlagName fn)
pretty (FlagAss1 (fn, False)) = Disp.char '-' Disp.<> Disp.text (unFlagName fn)
-- local instances for (Maybe UTCTime)
newtype Time = Time (Maybe UTCTime)
instance Newtype (Maybe UTCTime) Time
instance Pretty Time where
pretty (Time Nothing) = mempty
pretty (Time (Just t)) = pretty t -- see Distribution.Server.Framework.Instances
instance Parsec Time where
parsec = Time <$> optional parsec
--
instance Pretty InstallOutcome where
pretty PlanningFailed = Disp.text "PlanningFailed"
pretty (DependencyFailed pkgid) = Disp.text "DependencyFailed" <+> pretty pkgid
pretty DownloadFailed = Disp.text "DownloadFailed"
pretty UnpackFailed = Disp.text "UnpackFailed"
pretty SetupFailed = Disp.text "SetupFailed"
pretty ConfigureFailed = Disp.text "ConfigureFailed"
pretty BuildFailed = Disp.text "BuildFailed"
pretty InstallFailed = Disp.text "InstallFailed"
pretty InstallOk = Disp.text "InstallOk"
instance Parsec InstallOutcome where
parsec = do
name <- P.munch1 Char.isAlphaNum
case name of
"PlanningFailed" -> return PlanningFailed
"DependencyFailed" -> do P.spaces
pkgid <- parsec
return (DependencyFailed pkgid)
"DownloadFailed" -> return DownloadFailed
"UnpackFailed" -> return UnpackFailed
"SetupFailed" -> return SetupFailed
"ConfigureFailed" -> return ConfigureFailed
"BuildFailed" -> return BuildFailed
"InstallFailed" -> return InstallFailed
"InstallOk" -> return InstallOk
_ -> fail "unknown InstallOutcome"
instance Pretty Outcome where
pretty NotTried = Disp.text "NotTried"
pretty Failed = Disp.text "Failed"
pretty Ok = Disp.text "Ok"
instance Parsec Outcome where
parsec = do
name <- P.munch1 Char.isAlpha
case name of
"NotTried" -> return NotTried
"Failed" -> return Failed
"Ok" -> return Ok
_ -> fail "unknown Outcome"
instance MemSize BuildReport where
memSize (BuildReport a b c d e f g h i j k l) = memSize10 a b c d e f g h i j + memSize k + memSize l
instance MemSize InstallOutcome where
memSize (DependencyFailed a) = memSize1 a
memSize _ = memSize0
instance MemSize Outcome where
memSize _ = memSize0
-------------------
-- HStringTemplate instances
--
instance ToSElem BuildReport where
toSElem BuildReport{..} = SM . Map.fromList $
[ ("package", display package)
, ("time", toSElem time)
, ("docBuilder", toSElem docBuilder)
, ("os", display os)
, ("arch", display arch)
, ("compiler", display compiler)
, ("client", display client)
, ("flagAssignment", toSElem $ map (prettyShow . FlagAss1) flagAssignment)
, ("dependencies", toSElem $ map prettyShow dependencies)
, ("installOutcome", display installOutcome)
, ("docsOutcome", display docsOutcome)
, ("testsOutcome", display testsOutcome)
]
where
display value = toSElem (prettyShow value)
-------------------
-- Arbitrary instances
--
instance Arbitrary BuildReport where
arbitrary = BuildReport <$> arbitrary <*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary <*> arbitrary
instance Arbitrary InstallOutcome where
arbitrary = oneof [ pure PlanningFailed
, pure DependencyFailed <*> arbitrary
, pure DownloadFailed
, pure UnpackFailed
, pure SetupFailed
, pure ConfigureFailed
, pure BuildFailed
, pure InstallFailed
, pure InstallOk
]
instance Arbitrary Outcome where
arbitrary = elements [ NotTried, Failed, Ok ]
data BuildStatus = BuildOK | BuildFailCnt Int
deriving (Eq, Ord, Typeable, Show)
instance Arbitrary BuildStatus where
arbitrary = oneof [ pure BuildOK, BuildFailCnt <$> arbitrary ]
instance ToJSON BuildStatus where
toJSON (BuildFailCnt a) = toJSON a
toJSON BuildOK = toJSON ((-1)::Int)
instance FromJSON BuildStatus where
parseJSON (Number (-1)) = return BuildOK
parseJSON (Number a) = return (BuildFailCnt (fromJust (toBoundedInteger a)))
parseJSON _ = error "Unable to parse BuildStatus"
instance MemSize BuildStatus where
memSize (BuildFailCnt a) = memSize1 a
memSize _ = memSize0
instance Pretty BuildStatus where
pretty (BuildFailCnt a) = Disp.text "BuildFailCnt " Disp.<+> pretty a
pretty BuildOK = Disp.text "BuildOK"
-------------------
-- Old SafeCopy versions
--
-- Note this is kind of backwards from a migration pov, but this is because
-- the oldest one used a textual external rep with a parser, and the only
-- version we have with a parser is the latest, but they're sufficiently
-- compatible that we can get away with it for now.
newtype BuildReport_v0 = BuildReport_v0 BuildReport
instance SafeCopy BuildReport_v0 where
getCopy = contain get
putCopy = contain . put
-- use default Serialize instance
instance Serialize BuildReport_v0 where
put (BuildReport_v0 br) = Serialize.put . BS.pack . show $ br
get = (BuildReport_v0 . read) `fmap` Serialize.get
instance Migrate BuildReport_v1 where
type MigrateFrom BuildReport_v1 = BuildReport_v0
migrate (BuildReport_v0 BuildReport{..}) = BuildReport_v1 {
v1_package = package
, v1_os = os
, v1_arch = arch
, v1_compiler = compiler
, v1_client = client
, v1_flagAssignment = flagAssignment
, v1_dependencies = dependencies
, v1_installOutcome = case installOutcome of
PlanningFailed -> error "impossible rev migration"
DependencyFailed pkgid -> V0_DependencyFailed pkgid
DownloadFailed -> V0_DownloadFailed
UnpackFailed -> V0_UnpackFailed
SetupFailed -> V0_SetupFailed
ConfigureFailed -> V0_ConfigureFailed
BuildFailed -> V0_BuildFailed
InstallFailed -> V0_InstallFailed
InstallOk -> V0_InstallOk
, v1_docsOutcome = docsOutcome
, v1_testsOutcome = testsOutcome
}
data BuildReport_v1 = BuildReport_v1 {
v1_package :: PackageIdentifier,
v1_os :: OS,
v1_arch :: Arch,
v1_compiler :: CompilerId,
v1_client :: PackageIdentifier,
v1_flagAssignment :: [(FlagName,Bool)],
v1_dependencies :: [PackageIdentifier],
v1_installOutcome :: InstallOutcome_v0,
v1_docsOutcome :: Outcome,
v1_testsOutcome :: Outcome
}
data InstallOutcome_v0
= V0_DependencyFailed PackageIdentifier
| V0_DownloadFailed
| V0_UnpackFailed
| V0_SetupFailed
| V0_ConfigureFailed
| V0_BuildFailed
| V0_InstallFailed
| V0_InstallOk
deriveSafeCopy 0 'base ''Outcome
deriveSafeCopy 0 'base ''InstallOutcome_v0
deriveSafeCopy 2 'extension ''BuildReport_v1
instance Migrate BuildReport where
type MigrateFrom BuildReport = BuildReport_v1
migrate BuildReport_v1{..} = BuildReport {
package = v1_package
, time = Nothing
, docBuilder = True -- Most old reports come from the doc builder anyway
, os = v1_os
, arch = v1_arch
, compiler = v1_compiler
, client = v1_client
, flagAssignment = v1_flagAssignment
, dependencies = v1_dependencies
, installOutcome = migrate v1_installOutcome
, docsOutcome = v1_docsOutcome
, testsOutcome = v1_testsOutcome
}
instance Migrate InstallOutcome where
type MigrateFrom InstallOutcome = InstallOutcome_v0
migrate outcome = case outcome of
V0_DependencyFailed pkgid -> DependencyFailed pkgid
V0_DownloadFailed -> DownloadFailed
V0_UnpackFailed -> UnpackFailed
V0_SetupFailed -> SetupFailed
V0_ConfigureFailed -> ConfigureFailed
V0_BuildFailed -> BuildFailed
V0_InstallFailed -> InstallFailed
V0_InstallOk -> InstallOk
data BuildFiles = BuildFiles {
reportContent :: Maybe String,
logContent :: Maybe String,
testContent :: Maybe String,
coverageContent :: Maybe String,
testReportContent :: Maybe String,
buildFail :: Bool
} deriving Show
instance Data.Aeson.FromJSON BuildFiles where
parseJSON = withObject "buildFiles" $ \o ->
BuildFiles
<$> o .:? "report"
<*> o .:? "log"
<*> o .:? "test"
<*> o .:? "coverage"
<*> o .:? "testReport"
<*> o .: "buildFail"
instance Data.Aeson.ToJSON BuildFiles where
toJSON p = object [
"report" .= reportContent p,
"log" .= logContent p,
"test" .= testContent p,
"coverage" .= coverageContent p,
"testReport".= testReportContent p,
"buildFail" .= buildFail p ]
data PkgDetails = PkgDetails {
pkid :: PackageIdentifier,
docs :: Bool,
failCnt :: Maybe BuildStatus,
buildTime :: Maybe UTCTime,
ghcId :: Maybe Version,
runTests :: Maybe Bool
} deriving(Show)
instance Data.Aeson.ToJSON PkgDetails where
toJSON p = object [
"pkgid" .= (DT.display $ pkid p::String),
"docs" .= docs p,
"failCnt" .= failCnt p,
"buildTime" .= buildTime p,
"ghcId" .= k (ghcId p),
"runTests" .= runTests p ]
where
k (Just a) = Just $ DT.display a
k Nothing = Nothing
instance Data.Aeson.FromJSON PkgDetails where
parseJSON = withObject "pkgDetails" $ \o ->
PkgDetails
<$> ((\k -> maybe (fail $ "failed to parse "<>k) pure $ P.simpleParsec k) =<< (o .: "pkgid"))
<*> o .: "docs"
<*> o .:? "failCnt"
<*> o .:? "buildTime"
<*> fmap parseVersion (o .:? "ghcId")
<*> o .: "runTests"
where
parseVersion :: Maybe String -> Maybe Version
parseVersion Nothing = Nothing
parseVersion (Just k) = P.simpleParsec k
-------------------
-- SafeCopy instances
--
deriveSafeCopy 1 'extension ''InstallOutcome
deriveSafeCopy 3 'extension ''BuildReport
deriveSafeCopy 1 'base ''BuildStatus
deriveSafeCopy 1 'base ''BooleanCovg
deriveSafeCopy 1 'base ''BuildCovg