InstalledPackageInfo.hs 12.4 KB
Newer Older
1
2
3
4
-----------------------------------------------------------------------------
-- |
-- Module      :  Distribution.InstalledPackageInfo
-- Copyright   :  (c) The University of Glasgow 2004
5
--
6
7
8
-- Maintainer  :  libraries@haskell.org
-- Portability :  portable
--
9
-- This is the information about an /installed/ package that
10
-- is communicated to the @ghc-pkg@ program in order to register
11
-- a package.  @ghc-pkg@ now consumes this package format (as of version
ekarttun's avatar
ekarttun committed
12
-- 6.4). This is specific to GHC at the moment.
Duncan Coutts's avatar
Duncan Coutts committed
13
14
--
-- The @.cabal@ file format is for describing a package that is not yet
15
16
17
-- installed. It has a lot of flexibility, like conditionals and dependency
-- ranges. As such, that format is not at all suitable for describing a package
-- that has already been built and installed. By the time we get to that stage,
Duncan Coutts's avatar
Duncan Coutts committed
18
-- we have resolved all conditionals and resolved dependency version
19
-- constraints to exact versions of dependent packages. So, this module defines
Duncan Coutts's avatar
Duncan Coutts committed
20
21
-- the 'InstalledPackageInfo' data structure that contains all the info we keep
-- about an installed package. There is a parser and pretty printer. The
22
23
-- textual format is rather simpler than the @.cabal@ format: there are no
-- sections, for example.
24

ijones's avatar
ijones committed
25
{- All rights reserved.
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

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.

    * Neither the name of the University nor the names of other
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}

ijones's avatar
ijones committed
55
56
-- This module is meant to be local-only to Distribution...

57
module Distribution.InstalledPackageInfo (
58
59
60
61
62
63
        InstalledPackageInfo_(..), InstalledPackageInfo,
        ParseResult(..), PError(..), PWarning,
        emptyInstalledPackageInfo,
        parseInstalledPackageInfo,
        showInstalledPackageInfo,
        showInstalledPackageInfoField,
64
        fieldsInstalledPackageInfo,
65
  ) where
66

67
import Distribution.ParseUtils
68
69
         ( FieldDescr(..), ParseResult(..), PError(..), PWarning
         , simpleField, listField, parseLicenseQ
70
         , showFields, showSingleNamedField, parseFieldsFlat
71
         , parseFilePathQ, parseTokenQ, parseModuleNameQ, parsePackageNameQ
72
         , showFilePath, showToken, boolField, parseOptVersion
73
         , parseFreeText, showFreeText )
74
import Distribution.License     ( License(..) )
75
import Distribution.Package
76
         ( PackageName(..), PackageIdentifier(..), PackageId, InstalledPackageId(..)
Duncan Coutts's avatar
Duncan Coutts committed
77
         , packageName, packageVersion )
78
import qualified Distribution.Package as Package
79
         ( Package(..) )
80
81
import Distribution.ModuleName
         ( ModuleName )
82
83
84
import Distribution.Version
         ( Version(..) )
import Distribution.Text
85
         ( Text(disp, parse) )
simonmar's avatar
simonmar committed
86
87
88

-- -----------------------------------------------------------------------------
-- The InstalledPackageInfo type
ijones's avatar
ijones committed
89

90
data InstalledPackageInfo_ m
91
   = InstalledPackageInfo {
92
        -- these parts are exactly the same as PackageDescription
93
        installedPackageId :: InstalledPackageId,
94
        sourcePackageId    :: PackageId,
simonmar's avatar
simonmar committed
95
96
97
        license           :: License,
        copyright         :: String,
        maintainer        :: String,
98
        author            :: String,
simonmar's avatar
simonmar committed
99
        stability         :: String,
100
101
        homepage          :: String,
        pkgUrl            :: String,
102
        synopsis          :: String,
103
104
105
        description       :: String,
        category          :: String,
        -- these parts are required by an installed package only:
simonmar's avatar
simonmar committed
106
        exposed           :: Bool,
107
108
        exposedModules    :: [m],
        hiddenModules     :: [m],
simonmar's avatar
simonmar committed
109
110
111
112
        importDirs        :: [FilePath],  -- contain sources in case of Hugs
        libraryDirs       :: [FilePath],
        hsLibraries       :: [String],
        extraLibraries    :: [String],
113
        extraGHCiLibraries:: [String],    -- overrides extraLibraries for GHCi
simonmar's avatar
simonmar committed
114
115
        includeDirs       :: [FilePath],
        includes          :: [String],
116
        depends           :: [InstalledPackageId],
117
118
119
        hugsOptions       :: [String],
        ccOptions         :: [String],
        ldOptions         :: [String],
simonmar's avatar
simonmar committed
120
        frameworkDirs     :: [FilePath],
121
122
123
        frameworks        :: [String],
        haddockInterfaces :: [FilePath],
        haddockHTMLs      :: [FilePath]
simonmar's avatar
simonmar committed
124
    }
ijones's avatar
ijones committed
125
    deriving (Read, Show)
ijones's avatar
ijones committed
126

127
instance Package.Package          (InstalledPackageInfo_ str) where
128
   packageId = sourcePackageId
129

130
type InstalledPackageInfo = InstalledPackageInfo_ ModuleName
131
132

emptyInstalledPackageInfo :: InstalledPackageInfo_ m
simonmar's avatar
simonmar committed
133
emptyInstalledPackageInfo
134
   = InstalledPackageInfo {
135
        installedPackageId = InstalledPackageId "",
136
        sourcePackageId    = PackageIdentifier (PackageName "") noVersion,
ijones's avatar
ijones committed
137
138
139
        license           = AllRightsReserved,
        copyright         = "",
        maintainer        = "",
140
        author            = "",
ijones's avatar
ijones committed
141
        stability         = "",
142
143
        homepage          = "",
        pkgUrl            = "",
144
        synopsis          = "",
145
146
        description       = "",
        category          = "",
ijones's avatar
ijones committed
147
        exposed           = False,
148
149
        exposedModules    = [],
        hiddenModules     = [],
ijones's avatar
ijones committed
150
151
152
153
        importDirs        = [],
        libraryDirs       = [],
        hsLibraries       = [],
        extraLibraries    = [],
154
        extraGHCiLibraries= [],
ijones's avatar
ijones committed
155
        includeDirs       = [],
156
        includes          = [],
ijones's avatar
ijones committed
157
158
159
160
161
162
        depends           = [],
        hugsOptions       = [],
        ccOptions         = [],
        ldOptions         = [],
        frameworkDirs     = [],
        frameworks        = [],
163
164
        haddockInterfaces = [],
        haddockHTMLs      = []
simonmar's avatar
simonmar committed
165
166
    }

ijones's avatar
ijones committed
167
noVersion :: Version
simonmar's avatar
simonmar committed
168
169
170
171
172
noVersion = Version{ versionBranch=[], versionTags=[] }

-- -----------------------------------------------------------------------------
-- Parsing

173
parseInstalledPackageInfo :: String -> ParseResult InstalledPackageInfo
174
175
parseInstalledPackageInfo =
    parseFieldsFlat fieldsInstalledPackageInfo emptyInstalledPackageInfo
simonmar's avatar
simonmar committed
176
177
178
179
180

-- -----------------------------------------------------------------------------
-- Pretty-printing

showInstalledPackageInfo :: InstalledPackageInfo -> String
181
showInstalledPackageInfo = showFields fieldsInstalledPackageInfo
182
183

showInstalledPackageInfoField :: String -> Maybe (InstalledPackageInfo -> String)
184
showInstalledPackageInfoField = showSingleNamedField fieldsInstalledPackageInfo
simonmar's avatar
simonmar committed
185
186
187
188

-- -----------------------------------------------------------------------------
-- Description of the fields, for parsing/printing

189
190
fieldsInstalledPackageInfo :: [FieldDescr InstalledPackageInfo]
fieldsInstalledPackageInfo = basicFieldDescrs ++ installedFieldDescrs
simonmar's avatar
simonmar committed
191

Simon Marlow's avatar
Simon Marlow committed
192
193
basicFieldDescrs :: [FieldDescr InstalledPackageInfo]
basicFieldDescrs =
simonmar's avatar
simonmar committed
194
 [ simpleField "name"
Duncan Coutts's avatar
Duncan Coutts committed
195
                           disp                   parsePackageNameQ
196
                           packageName            (\name pkg -> pkg{sourcePackageId=(sourcePackageId pkg){pkgName=name}})
simonmar's avatar
simonmar committed
197
 , simpleField "version"
198
                           disp                   parseOptVersion
199
                           packageVersion         (\ver pkg -> pkg{sourcePackageId=(sourcePackageId pkg){pkgVersion=ver}})
200
201
202
 , simpleField "id"
                           disp                   parse
                           installedPackageId     (\ipid pkg -> pkg{installedPackageId=ipid})
ijones's avatar
ijones committed
203
 , simpleField "license"
Duncan Coutts's avatar
Duncan Coutts committed
204
                           disp                   parseLicenseQ
simonmar's avatar
simonmar committed
205
206
                           license                (\l pkg -> pkg{license=l})
 , simpleField "copyright"
207
                           showFreeText           parseFreeText
simonmar's avatar
simonmar committed
208
209
                           copyright              (\val pkg -> pkg{copyright=val})
 , simpleField "maintainer"
210
                           showFreeText           parseFreeText
simonmar's avatar
simonmar committed
211
212
                           maintainer             (\val pkg -> pkg{maintainer=val})
 , simpleField "stability"
213
                           showFreeText           parseFreeText
simonmar's avatar
simonmar committed
214
215
                           stability              (\val pkg -> pkg{stability=val})
 , simpleField "homepage"
216
                           showFreeText           parseFreeText
simonmar's avatar
simonmar committed
217
218
                           homepage               (\val pkg -> pkg{homepage=val})
 , simpleField "package-url"
219
                           showFreeText           parseFreeText
simonmar's avatar
simonmar committed
220
                           pkgUrl                 (\val pkg -> pkg{pkgUrl=val})
221
222
223
 , simpleField "synopsis"
                           showFreeText           parseFreeText
                           synopsis               (\val pkg -> pkg{synopsis=val})
simonmar's avatar
simonmar committed
224
 , simpleField "description"
225
                           showFreeText           parseFreeText
simonmar's avatar
simonmar committed
226
227
                           description            (\val pkg -> pkg{description=val})
 , simpleField "category"
228
                           showFreeText           parseFreeText
simonmar's avatar
simonmar committed
229
230
                           category               (\val pkg -> pkg{category=val})
 , simpleField "author"
231
                           showFreeText           parseFreeText
simonmar's avatar
simonmar committed
232
233
234
                           author                 (\val pkg -> pkg{author=val})
 ]

Simon Marlow's avatar
Simon Marlow committed
235
236
installedFieldDescrs :: [FieldDescr InstalledPackageInfo]
installedFieldDescrs = [
237
   boolField "exposed"
238
        exposed            (\val pkg -> pkg{exposed=val})
simonmar's avatar
simonmar committed
239
 , listField   "exposed-modules"
240
241
        disp               parseModuleNameQ
        exposedModules     (\xs    pkg -> pkg{exposedModules=xs})
simonmar's avatar
simonmar committed
242
 , listField   "hidden-modules"
243
244
        disp               parseModuleNameQ
        hiddenModules      (\xs    pkg -> pkg{hiddenModules=xs})
simonmar's avatar
simonmar committed
245
 , listField   "import-dirs"
246
247
        showFilePath       parseFilePathQ
        importDirs         (\xs pkg -> pkg{importDirs=xs})
simonmar's avatar
simonmar committed
248
 , listField   "library-dirs"
249
250
        showFilePath       parseFilePathQ
        libraryDirs        (\xs pkg -> pkg{libraryDirs=xs})
simonmar's avatar
simonmar committed
251
 , listField   "hs-libraries"
252
253
        showFilePath       parseTokenQ
        hsLibraries        (\xs pkg -> pkg{hsLibraries=xs})
ijones's avatar
ijones committed
254
 , listField   "extra-libraries"
255
256
        showToken          parseTokenQ
        extraLibraries     (\xs pkg -> pkg{extraLibraries=xs})
257
 , listField   "extra-ghci-libraries"
258
259
        showToken          parseTokenQ
        extraGHCiLibraries (\xs pkg -> pkg{extraGHCiLibraries=xs})
simonmar's avatar
simonmar committed
260
 , listField   "include-dirs"
261
262
        showFilePath       parseFilePathQ
        includeDirs        (\xs pkg -> pkg{includeDirs=xs})
simonmar's avatar
simonmar committed
263
 , listField   "includes"
264
265
        showFilePath       parseFilePathQ
        includes           (\xs pkg -> pkg{includes=xs})
simonmar's avatar
simonmar committed
266
 , listField   "depends"
267
        disp               parse
268
        depends            (\xs pkg -> pkg{depends=xs})
ijones's avatar
ijones committed
269
 , listField   "hugs-options"
270
271
        showToken          parseTokenQ
        hugsOptions        (\path  pkg -> pkg{hugsOptions=path})
ijones's avatar
ijones committed
272
 , listField   "cc-options"
273
274
        showToken          parseTokenQ
        ccOptions          (\path  pkg -> pkg{ccOptions=path})
ijones's avatar
ijones committed
275
 , listField   "ld-options"
276
277
        showToken          parseTokenQ
        ldOptions          (\path  pkg -> pkg{ldOptions=path})
simonmar's avatar
simonmar committed
278
 , listField   "framework-dirs"
279
280
        showFilePath       parseFilePathQ
        frameworkDirs      (\xs pkg -> pkg{frameworkDirs=xs})
ijones's avatar
ijones committed
281
 , listField   "frameworks"
282
283
        showToken          parseTokenQ
        frameworks         (\xs pkg -> pkg{frameworks=xs})
simonmar's avatar
simonmar committed
284
 , listField   "haddock-interfaces"
285
286
        showFilePath       parseFilePathQ
        haddockInterfaces  (\xs pkg -> pkg{haddockInterfaces=xs})
simonmar's avatar
simonmar committed
287
 , listField   "haddock-html"
288
289
        showFilePath       parseFilePathQ
        haddockHTMLs       (\xs pkg -> pkg{haddockHTMLs=xs})
simonmar's avatar
simonmar committed
290
 ]