@@ -68,16 +68,19 @@ module Development.Benchmark.Rules
68
68
69
69
import Control.Applicative
70
70
import Control.Monad
71
+ import Control.Lens ((^.) )
71
72
import Data.Aeson (FromJSON (.. ),
72
73
ToJSON (.. ),
73
- Value (.. ), (.!=) ,
74
- (.:?) )
74
+ Value (.. ), object , (.!=) ,
75
+ (.:?) , (.=) )
76
+ import Data.Aeson.Lens (_Object )
75
77
import Data.Char (isDigit )
76
78
import Data.List (find , isInfixOf ,
77
79
stripPrefix ,
78
80
transpose )
79
81
import Data.List.Extra (lower )
80
82
import Data.Maybe (fromMaybe )
83
+ import Data.String (fromString )
81
84
import Data.Text (Text )
82
85
import qualified Data.Text as T
83
86
import Development.Shake
@@ -88,7 +91,6 @@ import GHC.Exts (IsList (toList),
88
91
import GHC.Generics (Generic )
89
92
import GHC.Stack (HasCallStack )
90
93
import qualified Graphics.Rendering.Chart.Backend.Diagrams as E
91
- import Graphics.Rendering.Chart.Easy ((.=) )
92
94
import qualified Graphics.Rendering.Chart.Easy as E
93
95
import System.Directory (createDirectoryIfMissing ,
94
96
findExecutable ,
@@ -498,21 +500,24 @@ data GitCommit = GitCommit
498
500
499
501
instance FromJSON GitCommit where
500
502
parseJSON (String s) = pure $ GitCommit s Nothing Nothing True
501
- parseJSON (Object (toList -> [(name, String gitName)])) =
502
- pure $ GitCommit gitName (Just name) Nothing True
503
- parseJSON (Object (toList -> [(name, Object props)])) =
504
- GitCommit
505
- <$> props .:? " git" .!= name
506
- <*> pure (Just name)
507
- <*> props .:? " parent"
508
- <*> props .:? " include" .!= True
503
+ parseJSON o@ (Object _) = do
504
+ let keymap = o ^. _Object
505
+ case toList keymap of
506
+ [(name, String gitName)] -> pure $ GitCommit gitName (Just (fromString $ show name)) Nothing True
507
+ [(name, Object props)] ->
508
+ GitCommit
509
+ <$> props .:? " git" .!= name
510
+ <*> pure (Just (fromString $ show name))
511
+ <*> props .:? " parent"
512
+ <*> props .:? " include" .!= True
513
+ _ -> empty
509
514
parseJSON _ = empty
510
515
511
516
instance ToJSON GitCommit where
512
517
toJSON GitCommit {.. } =
513
518
case name of
514
519
Nothing -> String gitName
515
- Just n -> Object $ fromList [(n, String gitName) ]
520
+ Just n -> object [fromString ( T. unpack n) .= String gitName]
516
521
517
522
humanName :: GitCommit -> Text
518
523
humanName GitCommit {.. } = fromMaybe gitName name
@@ -607,7 +612,7 @@ plotDiagram :: Bool -> Diagram -> FilePath -> Action ()
607
612
plotDiagram includeFailed t@ Diagram {traceMetric, runLogs} out = do
608
613
let extract = frameMetric traceMetric
609
614
liftIO $ E. toFile E. def out $ do
610
- E. layout_title .= title t
615
+ E. layout_title E. .= title t
611
616
E. setColors myColors
612
617
forM_ runLogs $ \ rl ->
613
618
when (includeFailed || runSuccess rl) $ E. plot $ do
0 commit comments