Commit 0ecb2835 authored by Benno Fünfstück's avatar Benno Fünfstück
Browse files

cabal haddock: add --for-hackage flag

This is the first step to implement #2080. It adds a new flag
to `cabal haddock`, called `--for-hackage`, which will generate
documentation suitable for upload to hackage. It's only a collection
of flags, and matches the flags used by the hackage doc builder.
parent 40b28559
......@@ -192,12 +192,12 @@ haddock pkg_descr lbi suffixes flags = do
when (flag haddockHscolour) $
hscolour' (warn verbosity) pkg_descr lbi suffixes
(defaultHscolourFlags `mappend` haddockToHscolour flags)
(defaultHscolourFlags `mappend` haddockToHscolour hackageFlags)
libdirArgs <- getGhcLibDir verbosity lbi
let commonArgs = mconcat
[ libdirArgs
, fromFlags (haddockTemplateEnv lbi (packageId pkg_descr)) flags
, fromFlags (haddockTemplateEnv lbi (packageId pkg_descr)) hackageFlags
, fromPackageDescription pkg_descr ]
let pre c = preprocessComponent pkg_descr c lbi False verbosity suffixes
......@@ -213,7 +213,7 @@ haddock pkg_descr lbi suffixes flags = do
let exeArgs' = commonArgs `mappend` exeArgs
runHaddock verbosity tmpFileOpts comp confHaddock exeArgs'
Nothing -> do
warn (fromFlag $ haddockVerbosity flags)
warn (fromFlag $ haddockVerbosity hackageFlags)
"Unsupported component, skipping..."
return ()
case component of
......@@ -236,9 +236,19 @@ haddock pkg_descr lbi suffixes flags = do
keepTempFiles = flag haddockKeepTempFiles
comp = compiler lbi
tmpFileOpts = defaultTempFileOptions { optKeepTempFiles = keepTempFiles }
flag f = fromFlag $ f flags
flag f = fromFlag $ f hackageFlags
hackageFlags
| fromFlag (haddockForHackage flags) = flags
{ haddockHoogle = Flag True
, haddockHtml = Flag True
, haddockHtmlLocation = Flag (pkg_url ++ "/docs")
, haddockContents = Flag (toPathTemplate pkg_url)
, haddockHscolour = Flag True
}
| otherwise = flags
pkg_url = "/package/$pkg-$version"
htmlTemplate = fmap toPathTemplate . flagToMaybe . haddockHtmlLocation
$ flags
$ hackageFlags
-- ------------------------------------------------------------------------------
-- Contributions to HaddockArgs.
......
......@@ -1303,6 +1303,7 @@ data HaddockFlags = HaddockFlags {
haddockHoogle :: Flag Bool,
haddockHtml :: Flag Bool,
haddockHtmlLocation :: Flag String,
haddockForHackage :: Flag Bool,
haddockExecutables :: Flag Bool,
haddockTestSuites :: Flag Bool,
haddockBenchmarks :: Flag Bool,
......@@ -1324,6 +1325,7 @@ defaultHaddockFlags = HaddockFlags {
haddockHoogle = Flag False,
haddockHtml = Flag False,
haddockHtmlLocation = NoFlag,
haddockForHackage = Flag False,
haddockExecutables = Flag False,
haddockTestSuites = Flag False,
haddockBenchmarks = Flag False,
......@@ -1389,6 +1391,11 @@ haddockOptions showOrParseArgs =
haddockHtmlLocation (\v flags -> flags { haddockHtmlLocation = v })
(reqArgFlag "URL")
,option "" ["for-hackage"]
"Collection of flags to generate documentation suitable for upload to hackage"
haddockForHackage (\v flags -> flags { haddockForHackage = v })
trueArg
,option "" ["executables"]
"Run haddock for Executables targets"
haddockExecutables (\v flags -> flags { haddockExecutables = v })
......@@ -1452,6 +1459,7 @@ instance Monoid HaddockFlags where
haddockHoogle = mempty,
haddockHtml = mempty,
haddockHtmlLocation = mempty,
haddockForHackage = mempty,
haddockExecutables = mempty,
haddockTestSuites = mempty,
haddockBenchmarks = mempty,
......@@ -1470,6 +1478,7 @@ instance Monoid HaddockFlags where
haddockHoogle = combine haddockHoogle,
haddockHtml = combine haddockHtml,
haddockHtmlLocation = combine haddockHtmlLocation,
haddockForHackage = combine haddockForHackage,
haddockExecutables = combine haddockExecutables,
haddockTestSuites = combine haddockTestSuites,
haddockBenchmarks = combine haddockBenchmarks,
......
......@@ -369,6 +369,7 @@ instance Monoid SavedConfig where
haddockHoogle = combine haddockHoogle,
haddockHtml = combine haddockHtml,
haddockHtmlLocation = combine haddockHtmlLocation,
haddockForHackage = combine haddockForHackage,
haddockExecutables = combine haddockExecutables,
haddockTestSuites = combine haddockTestSuites,
haddockBenchmarks = combine haddockBenchmarks,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment