Skip to content

Commit 15b241c

Browse files
authored
Merge pull request #63 from michaelpj/mpj/shake-bench-aeson
Fixup shake-bench
2 parents 61e8d7f + 478203c commit 15b241c

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

shake-bench/shake-bench.cabal

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ library
2727
directory,
2828
extra >= 1.7.2,
2929
filepath,
30+
lens,
31+
lens-aeson,
3032
shake,
3133
text
3234
default-language: Haskell2010

shake-bench/src/Development/Benchmark/Rules.hs

+18-13
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,19 @@ module Development.Benchmark.Rules
6868

6969
import Control.Applicative
7070
import Control.Monad
71+
import Control.Lens ((^.))
7172
import Data.Aeson (FromJSON (..),
7273
ToJSON (..),
73-
Value (..), (.!=),
74-
(.:?))
74+
Value (..), object, (.!=),
75+
(.:?), (.=))
76+
import Data.Aeson.Lens (_Object)
7577
import Data.Char (isDigit)
7678
import Data.List (find, isInfixOf,
7779
stripPrefix,
7880
transpose)
7981
import Data.List.Extra (lower)
8082
import Data.Maybe (fromMaybe)
83+
import Data.String (fromString)
8184
import Data.Text (Text)
8285
import qualified Data.Text as T
8386
import Development.Shake
@@ -88,7 +91,6 @@ import GHC.Exts (IsList (toList),
8891
import GHC.Generics (Generic)
8992
import GHC.Stack (HasCallStack)
9093
import qualified Graphics.Rendering.Chart.Backend.Diagrams as E
91-
import Graphics.Rendering.Chart.Easy ((.=))
9294
import qualified Graphics.Rendering.Chart.Easy as E
9395
import System.Directory (createDirectoryIfMissing,
9496
findExecutable,
@@ -498,21 +500,24 @@ data GitCommit = GitCommit
498500

499501
instance FromJSON GitCommit where
500502
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
509514
parseJSON _ = empty
510515

511516
instance ToJSON GitCommit where
512517
toJSON GitCommit {..} =
513518
case name of
514519
Nothing -> String gitName
515-
Just n -> Object $ fromList [(n, String gitName)]
520+
Just n -> object [fromString (T.unpack n) .= String gitName]
516521

517522
humanName :: GitCommit -> Text
518523
humanName GitCommit {..} = fromMaybe gitName name
@@ -607,7 +612,7 @@ plotDiagram :: Bool -> Diagram -> FilePath -> Action ()
607612
plotDiagram includeFailed t@Diagram {traceMetric, runLogs} out = do
608613
let extract = frameMetric traceMetric
609614
liftIO $ E.toFile E.def out $ do
610-
E.layout_title .= title t
615+
E.layout_title E..= title t
611616
E.setColors myColors
612617
forM_ runLogs $ \rl ->
613618
when (includeFailed || runSuccess rl) $ E.plot $ do

0 commit comments

Comments
 (0)