1
+ {-# LANGUAGE DeriveGeneric #-}
2
+ {-# LANGUAGE GeneralizedNewtypeDeriving #-}
1
3
{-# LANGUAGE OverloadedStrings #-}
2
4
{-# OPTIONS_GHC -Wno-orphans #-}
3
5
-- | Utilities for understanding @plan.json@.
4
6
module Test.Cabal.Plan (
5
- Plan ,
7
+ Plan ( .. ) ,
6
8
DistDirOrBinFile (.. ),
9
+ InstallItem (.. ),
10
+ ConfiguredGlobal (.. ),
11
+ Revision (.. ),
12
+ PkgSrc (.. ),
13
+ Repo (.. ),
7
14
planDistDir ,
8
15
buildInfoFile ,
9
16
) where
@@ -16,6 +23,7 @@ import qualified Data.Text as Text
16
23
import Data.Aeson
17
24
import Data.Aeson.Types
18
25
import Control.Monad
26
+ import GHC.Generics (Generic )
19
27
20
28
-- TODO: index this
21
29
data Plan = Plan { planInstallPlan :: [InstallItem ] }
@@ -32,15 +40,33 @@ data ConfiguredInplace = ConfiguredInplace
32
40
{ configuredInplaceDistDir :: FilePath
33
41
, configuredInplaceBuildInfo :: Maybe FilePath
34
42
, configuredInplacePackageName :: PackageName
35
- , configuredInplaceComponentName :: Maybe ComponentName }
43
+ , configuredInplaceComponentName :: Maybe ComponentName
44
+ , configuredInplacePkgSrc :: PkgSrc }
36
45
deriving Show
37
46
38
47
data ConfiguredGlobal = ConfiguredGlobal
39
48
{ configuredGlobalBinFile :: Maybe FilePath
40
49
, configuredGlobalPackageName :: PackageName
41
- , configuredGlobalComponentName :: Maybe ComponentName }
50
+ , configuredGlobalComponentName :: Maybe ComponentName
51
+ , configuredGlobalPkgSrc :: PkgSrc }
42
52
deriving Show
43
53
54
+ newtype Revision = Revision Int
55
+ deriving (Show , Eq , FromJSON )
56
+
57
+ -- | A stripped-down 'Distribution.Client.Types.PackageLocation.PackageLocation'
58
+ data PkgSrc
59
+ = RepoTar { repo :: Repo }
60
+ | PkgSrcOther
61
+ deriving (Show , Generic )
62
+
63
+ -- | A stripped-down 'Distribution.Client.Types.Repo.Repo', plus revision information
64
+ data Repo
65
+ = LocalRepoNoIndex
66
+ | RemoteRepo { pkgRevision :: Revision }
67
+ | SecureRepo { pkgRevision :: Revision }
68
+ deriving (Show , Generic )
69
+
44
70
instance FromJSON Plan where
45
71
parseJSON (Object v) = fmap Plan (v .: " install-plan" )
46
72
parseJSON invalid = typeMismatch " Plan" invalid
@@ -66,15 +92,17 @@ instance FromJSON ConfiguredInplace where
66
92
build_info <- v .:? " build-info"
67
93
pkg_name <- v .: " pkg-name"
68
94
component_name <- v .:? " component-name"
69
- return (ConfiguredInplace dist_dir build_info pkg_name component_name)
95
+ pkg_src <- v .: " pkg-src"
96
+ return (ConfiguredInplace dist_dir build_info pkg_name component_name pkg_src)
70
97
parseJSON invalid = typeMismatch " ConfiguredInplace" invalid
71
98
72
99
instance FromJSON ConfiguredGlobal where
73
100
parseJSON (Object v) = do
74
101
bin_file <- v .:? " bin-file"
75
102
pkg_name <- v .: " pkg-name"
76
103
component_name <- v .:? " component-name"
77
- return (ConfiguredGlobal bin_file pkg_name component_name)
104
+ pkg_src <- v .: " pkg-src"
105
+ return (ConfiguredGlobal bin_file pkg_name component_name pkg_src)
78
106
parseJSON invalid = typeMismatch " ConfiguredGlobal" invalid
79
107
80
108
instance FromJSON PackageName where
@@ -89,6 +117,21 @@ instance FromJSON ComponentName where
89
117
where s = Text. unpack t
90
118
parseJSON invalid = typeMismatch " ComponentName" invalid
91
119
120
+ instance FromJSON PkgSrc where
121
+ parseJSON (Object v) = do
122
+ t <- v .: " type"
123
+ case t :: String of
124
+ " repo-tar" -> RepoTar <$> v .: " repo"
125
+ _ -> return PkgSrcOther
126
+ parseJSON invalid = typeMismatch " PkgSrc" invalid
127
+
128
+ instance FromJSON Repo where
129
+ parseJSON = genericParseJSON defaultOptions
130
+ { constructorTagModifier = camelTo2 ' -'
131
+ , fieldLabelModifier = camelTo2 ' -'
132
+ , sumEncoding = TaggedObject " type" " "
133
+ }
134
+
92
135
data DistDirOrBinFile = DistDir FilePath | BinFile FilePath
93
136
94
137
planDistDir :: Plan -> PackageName -> ComponentName -> DistDirOrBinFile
0 commit comments