2 {-# LANGUAGE DeriveDataTypeable #-}
3 {-# LANGUAGE DeriveGeneric #-}
4 {-# LANGUAGE FlexibleContexts #-}
5 {-# LANGUAGE RankNTypes #-}
7 -----------------------------------------------------------------------------
10 -- Module : Distribution.Simple.Setup.Haddock
11 -- Copyright : Isaac Jones 2003-2004
15 -- Maintainer : cabal-devel@haskell.org
16 -- Portability : portable
18 -- Definition of the haddock command-line options.
19 -- See: @Distribution.Simple.Setup@
20 module Distribution
.Simple
.Setup
.Haddock
27 , HaddockProjectFlags
(..)
28 , emptyHaddockProjectFlags
29 , defaultHaddockProjectFlags
30 , haddockProjectCommand
32 , haddockProjectOptions
35 import Distribution
.Compat
.Prelude
hiding (get
)
38 import qualified Distribution
.Compat
.CharParsing
as P
39 import Distribution
.Parsec
40 import Distribution
.Pretty
41 import Distribution
.Simple
.Command
hiding (boolOpt
, boolOpt
')
42 import Distribution
.Simple
.Flag
43 import Distribution
.Simple
.InstallDirs
44 import Distribution
.Simple
.Program
45 import Distribution
.Verbosity
46 import qualified Text
.PrettyPrint
as Disp
48 import Distribution
.Simple
.Setup
.Common
50 -- ------------------------------------------------------------
54 -- ------------------------------------------------------------
56 -- | When we build haddock documentation, there are two cases:
58 -- 1. We build haddocks only for the current development version,
59 -- intended for local use and not for distribution. In this case,
60 -- we store the generated documentation in @<dist>/doc/html/<package name>@.
62 -- 2. We build haddocks for intended for uploading them to hackage.
63 -- In this case, we need to follow the layout that hackage expects
64 -- from documentation tarballs, and we might also want to use different
65 -- flags than for development builds, so in this case we store the generated
66 -- documentation in @<dist>/doc/html/<package id>-docs@.
67 data HaddockTarget
= ForHackage | ForDevelopment
deriving (Eq
, Show, Generic
, Typeable
)
69 instance Binary HaddockTarget
70 instance Structured HaddockTarget
72 instance Pretty HaddockTarget
where
73 pretty ForHackage
= Disp
.text
"for-hackage"
74 pretty ForDevelopment
= Disp
.text
"for-development"
76 instance Parsec HaddockTarget
where
79 [ P
.try $ P
.string "for-hackage" >> return ForHackage
80 , P
.string "for-development" >> return ForDevelopment
83 data HaddockFlags
= HaddockFlags
84 { haddockProgramPaths
:: [(String, FilePath)]
85 , haddockProgramArgs
:: [(String, [String])]
86 , haddockHoogle
:: Flag
Bool
87 , haddockHtml
:: Flag
Bool
88 , haddockHtmlLocation
:: Flag
String
89 , haddockForHackage
:: Flag HaddockTarget
90 , haddockExecutables
:: Flag
Bool
91 , haddockTestSuites
:: Flag
Bool
92 , haddockBenchmarks
:: Flag
Bool
93 , haddockForeignLibs
:: Flag
Bool
94 , haddockInternal
:: Flag
Bool
95 , haddockCss
:: Flag
FilePath
96 , haddockLinkedSource
:: Flag
Bool
97 , haddockQuickJump
:: Flag
Bool
98 , haddockHscolourCss
:: Flag
FilePath
99 , haddockContents
:: Flag PathTemplate
100 , haddockIndex
:: Flag PathTemplate
101 , haddockDistPref
:: Flag
FilePath
102 , haddockKeepTempFiles
:: Flag
Bool
103 , haddockVerbosity
:: Flag Verbosity
104 , haddockCabalFilePath
:: Flag
FilePath
105 , haddockBaseUrl
:: Flag
String
106 , haddockLib
:: Flag
String
107 , haddockOutputDir
:: Flag
FilePath
108 , haddockArgs
:: [String]
110 deriving (Show, Generic
, Typeable
)
112 defaultHaddockFlags
:: HaddockFlags
113 defaultHaddockFlags
=
115 { haddockProgramPaths
= mempty
116 , haddockProgramArgs
= []
117 , haddockHoogle
= Flag
False
118 , haddockHtml
= Flag
False
119 , haddockHtmlLocation
= NoFlag
120 , haddockForHackage
= NoFlag
121 , haddockExecutables
= Flag
False
122 , haddockTestSuites
= Flag
False
123 , haddockBenchmarks
= Flag
False
124 , haddockForeignLibs
= Flag
False
125 , haddockInternal
= Flag
False
126 , haddockCss
= NoFlag
127 , haddockLinkedSource
= Flag
False
128 , haddockQuickJump
= Flag
False
129 , haddockHscolourCss
= NoFlag
130 , haddockContents
= NoFlag
131 , haddockDistPref
= NoFlag
132 , haddockKeepTempFiles
= Flag
False
133 , haddockVerbosity
= Flag normal
134 , haddockCabalFilePath
= mempty
135 , haddockIndex
= NoFlag
136 , haddockBaseUrl
= NoFlag
137 , haddockLib
= NoFlag
138 , haddockOutputDir
= NoFlag
139 , haddockArgs
= mempty
142 haddockCommand
:: CommandUI HaddockFlags
145 { commandName
= "haddock"
146 , commandSynopsis
= "Generate Haddock HTML documentation."
147 , commandDescription
= Just
$ \_
->
148 "Requires the program haddock, version 2.x.\n"
149 , commandNotes
= Nothing
151 usageAlternatives
"haddock" $
153 , "COMPONENTS [FLAGS]"
155 , commandDefaultFlags
= defaultHaddockFlags
156 , commandOptions
= \showOrParseArgs
->
157 haddockOptions showOrParseArgs
162 (\v flags
-> flags
{haddockProgramPaths
= v
})
167 (\v fs
-> fs
{haddockProgramArgs
= v
})
172 (\v flags
-> flags
{haddockProgramArgs
= v
})
176 addKnownProgram haddockProgram
$
177 addKnownProgram ghcProgram
$
180 haddockOptions
:: ShowOrParseArgs
-> [OptionField HaddockFlags
]
181 haddockOptions showOrParseArgs
=
184 (\v flags
-> flags
{haddockVerbosity
= v
})
187 (\d flags
-> flags
{haddockDistPref
= d
})
192 "Keep temporary files"
194 (\b flags
-> flags
{haddockKeepTempFiles
= b
})
199 "Generate a hoogle database"
201 (\v flags
-> flags
{haddockHoogle
= v
})
206 "Generate HTML documentation (the default)"
208 (\v flags
-> flags
{haddockHtml
= v
})
213 "Location of HTML documentation for pre-requisite packages"
215 (\v flags
-> flags
{haddockHtmlLocation
= v
})
220 "Collection of flags to generate documentation suitable for upload to hackage"
222 (\v flags
-> flags
{haddockForHackage
= v
})
223 (noArg
(Flag ForHackage
))
227 "Run haddock for Executables targets"
229 (\v flags
-> flags
{haddockExecutables
= v
})
234 "Run haddock for Test Suite targets"
236 (\v flags
-> flags
{haddockTestSuites
= v
})
241 "Run haddock for Benchmark targets"
243 (\v flags
-> flags
{haddockBenchmarks
= v
})
247 ["foreign-libraries"]
248 "Run haddock for Foreign Library targets"
250 (\v flags
-> flags
{haddockForeignLibs
= v
})
255 "Run haddock for all targets"
258 [ haddockExecutables f
259 , haddockTestSuites f
260 , haddockBenchmarks f
261 , haddockForeignLibs f
266 { haddockExecutables
= v
267 , haddockTestSuites
= v
268 , haddockBenchmarks
= v
269 , haddockForeignLibs
= v
276 "Run haddock for internal modules and include all symbols"
278 (\v flags
-> flags
{haddockInternal
= v
})
283 "Use PATH as the haddock stylesheet"
285 (\v flags
-> flags
{haddockCss
= v
})
289 ["hyperlink-source", "hyperlink-sources", "hyperlinked-source"]
290 "Hyperlink the documentation to the source code"
292 (\v flags
-> flags
{haddockLinkedSource
= v
})
297 "Generate an index for interactive documentation navigation"
299 (\v flags
-> flags
{haddockQuickJump
= v
})
304 "Use PATH as the HsColour stylesheet"
306 (\v flags
-> flags
{haddockHscolourCss
= v
})
310 ["contents-location"]
311 "Bake URL in as the location for the contents page"
313 (\v flags
-> flags
{haddockContents
= v
})
316 (toFlag
. toPathTemplate
)
317 (flagToList
. fmap fromPathTemplate
)
322 "Use a separately-generated HTML index"
324 (\v flags
-> flags
{haddockIndex
= v
})
327 (toFlag
. toPathTemplate
)
328 (flagToList
. fmap fromPathTemplate
)
333 "Base URL for static files."
335 (\v flags
-> flags
{haddockBaseUrl
= v
})
340 "location of Haddocks static / auxiliary files"
342 (\v flags
-> flags
{haddockLib
= v
})
347 "Generate haddock documentation into this directory. This flag is provided as a technology preview and is subject to change in the next releases."
349 (\v flags
-> flags
{haddockOutputDir
= v
})
353 emptyHaddockFlags
:: HaddockFlags
354 emptyHaddockFlags
= mempty
356 instance Monoid HaddockFlags
where
360 instance Semigroup HaddockFlags
where
363 -- ------------------------------------------------------------
365 -- * HaddocksFlags flags
367 -- ------------------------------------------------------------
369 -- | Governs whether modules from a given interface should be visible or
370 -- hidden in the Haddock generated content page. We don't expose this
371 -- functionality to the user, but simply use 'Visible' for only local packages.
372 -- Visibility of modules is available since @haddock-2.26.1@.
373 data Visibility
= Visible | Hidden
376 data HaddockProjectFlags
= HaddockProjectFlags
377 { haddockProjectHackage
:: Flag
Bool
378 -- ^ a shortcut option which builds documentation linked to hackage. It implies:
379 -- * `--html-location='https://hackage.haskell.org/package/$prg-$version/docs'
382 -- * `--gen-contents`
383 -- * `--hyperlinked-source`
384 , -- options passed to @haddock@ via 'createHaddockIndex'
385 haddockProjectDir
:: Flag
String
386 -- ^ output directory of combined haddocks, the default is './haddocks'
387 , haddockProjectPrologue
:: Flag
String
388 , haddockProjectInterfaces
:: Flag
[(FilePath, Maybe FilePath, Maybe FilePath, Visibility
)]
389 -- ^ 'haddocksInterfaces' is inferred by the 'haddocksAction'; currently not
390 -- exposed to the user.
391 , -- options passed to @haddock@ via 'HaddockFlags' when building
394 haddockProjectProgramPaths
:: [(String, FilePath)]
395 , haddockProjectProgramArgs
:: [(String, [String])]
396 , haddockProjectHoogle
:: Flag
Bool
397 , -- haddockHtml is not supported
398 haddockProjectHtmlLocation
:: Flag
String
399 , -- haddockForHackage is not supported
400 haddockProjectExecutables
:: Flag
Bool
401 , haddockProjectTestSuites
:: Flag
Bool
402 , haddockProjectBenchmarks
:: Flag
Bool
403 , haddockProjectForeignLibs
:: Flag
Bool
404 , haddockProjectInternal
:: Flag
Bool
405 , haddockProjectCss
:: Flag
FilePath
406 , haddockProjectHscolourCss
:: Flag
FilePath
407 , -- haddockContent is not supported, a fixed value is provided
408 -- haddockIndex is not supported, a fixed value is provided
409 -- haddockDistPerf is not supported, note: it changes location of the haddocks
410 haddockProjectKeepTempFiles
:: Flag
Bool
411 , haddockProjectVerbosity
:: Flag Verbosity
412 , -- haddockBaseUrl is not supported, a fixed value is provided
413 haddockProjectLib
:: Flag
String
414 , haddockProjectOutputDir
:: Flag
FilePath
416 deriving (Show, Generic
, Typeable
)
418 defaultHaddockProjectFlags
:: HaddockProjectFlags
419 defaultHaddockProjectFlags
=
421 { haddockProjectHackage
= Flag
False
422 , haddockProjectDir
= Flag
"./haddocks"
423 , haddockProjectPrologue
= NoFlag
424 , haddockProjectTestSuites
= Flag
False
425 , haddockProjectProgramPaths
= mempty
426 , haddockProjectProgramArgs
= mempty
427 , haddockProjectHoogle
= Flag
False
428 , haddockProjectHtmlLocation
= NoFlag
429 , haddockProjectExecutables
= Flag
False
430 , haddockProjectBenchmarks
= Flag
False
431 , haddockProjectForeignLibs
= Flag
False
432 , haddockProjectInternal
= Flag
False
433 , haddockProjectCss
= NoFlag
434 , haddockProjectHscolourCss
= NoFlag
435 , haddockProjectKeepTempFiles
= Flag
False
436 , haddockProjectVerbosity
= Flag normal
437 , haddockProjectLib
= NoFlag
438 , haddockProjectOutputDir
= NoFlag
439 , haddockProjectInterfaces
= NoFlag
442 haddockProjectCommand
:: CommandUI HaddockProjectFlags
443 haddockProjectCommand
=
445 { commandName
= "v2-haddock-project"
446 , commandSynopsis
= "Generate Haddocks HTML documentation for the cabal project."
447 , commandDescription
= Just
$ \_
->
448 "Require the programm haddock, version 2.26.\n"
449 , commandNotes
= Nothing
451 usageAlternatives
"haddocks" $
453 , "COMPONENTS [FLAGS]"
455 , commandDefaultFlags
= defaultHaddockProjectFlags
456 , commandOptions
= \showOrParseArgs
->
457 haddockProjectOptions showOrParseArgs
461 haddockProjectProgramPaths
462 (\v flags
-> flags
{haddockProjectProgramPaths
= v
})
466 haddockProjectProgramArgs
467 (\v fs
-> fs
{haddockProjectProgramArgs
= v
})
471 haddockProjectProgramArgs
472 (\v flags
-> flags
{haddockProjectProgramArgs
= v
})
476 addKnownProgram haddockProgram
$
477 addKnownProgram ghcProgram
$
480 haddockProjectOptions
:: ShowOrParseArgs
-> [OptionField HaddockProjectFlags
]
481 haddockProjectOptions _showOrParseArgs
=
486 [ "A short-cut option to build documentation linked to hackage."
489 haddockProjectHackage
490 (\v flags
-> flags
{haddockProjectHackage
= v
})
497 (\v flags
-> flags
{haddockProjectDir
= v
})
498 (optArg
' "DIRECTORY" maybeToFlag
(fmap Just
. flagToList
))
502 "File path to a prologue file in haddock format"
503 haddockProjectPrologue
504 (\v flags
-> flags
{haddockProjectPrologue
= v
})
505 (optArg
' "PATH" maybeToFlag
(fmap Just
. flagToList
))
509 "Generate a hoogle database"
511 (\v flags
-> flags
{haddockProjectHoogle
= v
})
516 "Location of HTML documentation for pre-requisite packages"
517 haddockProjectHtmlLocation
518 (\v flags
-> flags
{haddockProjectHtmlLocation
= v
})
523 "Run haddock for Executables targets"
524 haddockProjectExecutables
525 (\v flags
-> flags
{haddockProjectExecutables
= v
})
530 "Run haddock for Test Suite targets"
531 haddockProjectTestSuites
532 (\v flags
-> flags
{haddockProjectTestSuites
= v
})
537 "Run haddock for Benchmark targets"
538 haddockProjectBenchmarks
539 (\v flags
-> flags
{haddockProjectBenchmarks
= v
})
543 ["foreign-libraries"]
544 "Run haddock for Foreign Library targets"
545 haddockProjectForeignLibs
546 (\v flags
-> flags
{haddockProjectForeignLibs
= v
})
551 "Run haddock for internal modules and include all symbols"
552 haddockProjectInternal
553 (\v flags
-> flags
{haddockProjectInternal
= v
})
558 "Use PATH as the haddock stylesheet"
560 (\v flags
-> flags
{haddockProjectCss
= v
})
565 "Use PATH as the HsColour stylesheet"
566 haddockProjectHscolourCss
567 (\v flags
-> flags
{haddockProjectHscolourCss
= v
})
572 "Keep temporary files"
573 haddockProjectKeepTempFiles
574 (\b flags
-> flags
{haddockProjectKeepTempFiles
= b
})
577 haddockProjectVerbosity
578 (\v flags
-> flags
{haddockProjectVerbosity
= v
})
582 "location of Haddocks static / auxiliary files"
584 (\v flags
-> flags
{haddockProjectLib
= v
})
589 "Generate haddock documentation into this directory. This flag is provided as a technology preview and is subject to change in the next releases."
590 haddockProjectOutputDir
591 (\v flags
-> flags
{haddockProjectOutputDir
= v
})
595 emptyHaddockProjectFlags
:: HaddockProjectFlags
596 emptyHaddockProjectFlags
= mempty
598 instance Monoid HaddockProjectFlags
where
602 instance Semigroup HaddockProjectFlags
where