Skip to content

Commit

Permalink
Added --haddock-internal command line argument (commercialhaskell#2229
Browse files Browse the repository at this point in the history
)

This is a boolean argument which causes haddocks to be generated in the
same manner as `cabal haddock --internal`, implemented by simply passing
`--internal` to the `cabal haddock` invocation used to build the docs.

It defaults to False.
  • Loading branch information
Rick Owens committed Aug 23, 2016
1 parent 8619824 commit 31b0ab8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +1141,11 @@ singleBuild runInBase ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} in
("Warning: haddock not generating hyperlinked sources because 'HsColour' not\n" <>
"found on PATH (use 'stack install hscolour' to install).")
return ["--hyperlink-source" | hscolourExists]
let internalDocs = if shouldHaddockInternal eeBuildOpts
then ["--internal"]
else []
cabal False (concat [["haddock", "--html", "--hoogle", "--html-location=../$pkg-$version/"]
,sourceFlag])
,sourceFlag, internalDocs])

unless isFinalBuild $ withMVar eeInstallLock $ \() -> do
announce "copy/register"
Expand Down
5 changes: 5 additions & 0 deletions src/Stack/Build/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Stack.Build.Haddock
, openHaddocksInBrowser
, shouldHaddockPackage
, shouldHaddockDeps
, shouldHaddockInternal
) where

import Control.Exception (tryJust, onException)
Expand Down Expand Up @@ -114,6 +115,10 @@ shouldHaddockPackage bopts wanted name =
shouldHaddockDeps :: BuildOpts -> Bool
shouldHaddockDeps bopts = fromMaybe (boptsHaddock bopts) (boptsHaddockDeps bopts)

-- | Determine whether to build haddocks for non-exported modules, like @cabal haddock --intenral@.
shouldHaddockInternal :: BuildOpts -> Bool
shouldHaddockInternal bopts = boptsHaddockInternal bopts

-- | Generate Haddock index and contents for local packages.
generateLocalHaddockIndex
:: (MonadIO m, MonadCatch m, MonadLogger m, MonadBaseControl IO m)
Expand Down
3 changes: 3 additions & 0 deletions src/Stack/Config/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ buildOptsFromMonoid BuildOptsMonoid{..} = BuildOpts
(boptsOpenHaddocks defaultBuildOpts)
buildMonoidOpenHaddocks
, boptsHaddockDeps = getFirst buildMonoidHaddockDeps
, boptsHaddockInternal = fromFirst
(boptsHaddockInternal defaultBuildOpts)
buildMonoidHaddockInternal
, boptsInstallExes = fromFirst
(boptsInstallExes defaultBuildOpts)
buildMonoidInstallExes
Expand Down
7 changes: 6 additions & 1 deletion src/Stack/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ buildOptsMonoidParser hide0 =
options =
BuildOptsMonoid <$> libProfiling <*> exeProfiling <*> haddock <*>
haddockOptsParser hide0 <*> openHaddocks <*>
haddockDeps <*> copyBins <*> preFetch <*> keepGoing <*> forceDirty <*>
haddockDeps <*> haddockInternal <*> copyBins <*> preFetch <*> keepGoing <*> forceDirty <*>
tests <*> testOptsParser hide0 <*> benches <*> benchOptsParser hide0 <*> reconfigure <*>
cabalVerbose <*> splitObjs
libProfiling =
Expand All @@ -403,6 +403,11 @@ buildOptsMonoidParser hide0 =
hide
haddockDeps =
firstBoolFlags "haddock-deps" "building Haddocks for dependencies" hide
haddockInternal =
firstBoolFlags
"haddock-internal"
"building Haddocks for internal modules (like cabal haddock --internal)"
hide
copyBins =
firstBoolFlags
"copy-bins"
Expand Down
8 changes: 8 additions & 0 deletions src/Stack/Types/Config/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ data BuildOpts =
-- ^ Open haddocks in the browser?
,boptsHaddockDeps :: !(Maybe Bool)
-- ^ Build haddocks for dependencies?
,boptsHaddockInternal :: !Bool
-- ^ Build haddocks for all symbols and packages, like @cabal haddock --internal@
,boptsInstallExes :: !Bool
-- ^ Install executables to user path after building?
,boptsPreFetch :: !Bool
Expand Down Expand Up @@ -90,6 +92,7 @@ defaultBuildOpts = BuildOpts
, boptsHaddockOpts = defaultHaddockOpts
, boptsOpenHaddocks = False
, boptsHaddockDeps = Nothing
, boptsHaddockInternal = False
, boptsInstallExes = False
, boptsPreFetch = False
, boptsKeepGoing = Nothing
Expand Down Expand Up @@ -146,6 +149,7 @@ data BuildOptsMonoid = BuildOptsMonoid
, buildMonoidHaddockOpts :: !HaddockOptsMonoid
, buildMonoidOpenHaddocks :: !(First Bool)
, buildMonoidHaddockDeps :: !(First Bool)
, buildMonoidHaddockInternal :: !(First Bool)
, buildMonoidInstallExes :: !(First Bool)
, buildMonoidPreFetch :: !(First Bool)
, buildMonoidKeepGoing :: !(First Bool)
Expand All @@ -167,6 +171,7 @@ instance FromJSON (WithJSONWarnings BuildOptsMonoid) where
buildMonoidHaddockOpts <- jsonSubWarnings (o ..:? buildMonoidHaddockOptsArgName ..!= mempty)
buildMonoidOpenHaddocks <- First <$> o ..:? buildMonoidOpenHaddocksArgName
buildMonoidHaddockDeps <- First <$> o ..:? buildMonoidHaddockDepsArgName
buildMonoidHaddockInternal <- First <$> o ..:? buildMonoidHaddockInternalArgName
buildMonoidInstallExes <- First <$> o ..:? buildMonoidInstallExesArgName
buildMonoidPreFetch <- First <$> o ..:? buildMonoidPreFetchArgName
buildMonoidKeepGoing <- First <$> o ..:? buildMonoidKeepGoingArgName
Expand Down Expand Up @@ -198,6 +203,9 @@ buildMonoidOpenHaddocksArgName = "open-haddocks"
buildMonoidHaddockDepsArgName :: Text
buildMonoidHaddockDepsArgName = "haddock-deps"

buildMonoidHaddockInternalArgName :: Text
buildMonoidHaddockInternalArgName = "haddock-internal"

buildMonoidInstallExesArgName :: Text
buildMonoidInstallExesArgName = "copy-bins"

Expand Down

0 comments on commit 31b0ab8

Please sign in to comment.