Skip to content

Commit

Permalink
Re #6270 Step 1, provide --haddock-for-hackage
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Oct 8, 2023
1 parent 3eed62b commit 48f8ad6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
45 changes: 27 additions & 18 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,7 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap
&& maybe True (Set.notMember pname . curatorSkipHaddock) mcurator
expectHaddockFailure =
maybe False (Set.member pname . curatorExpectHaddockFailure)
isHaddockForHackage = boptsHaddockForHackage eeBuildOpts
fulfillHaddockExpectations mcurator action
| expectHaddockFailure mcurator = do
eres <- tryAny $ action KeepOpen
Expand Down Expand Up @@ -1957,11 +1958,9 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap

mcurator <- view $ buildConfigL.to bcCurator
when (doHaddock mcurator package) $ do
announce "haddock"
let sourceFlag =
[ "--haddock-option=--hyperlinked-source"
| boptsHaddockHyperlinkSource eeBuildOpts
]
announce $ if isHaddockForHackage
then "haddock for Hackage"
else "haddock"

-- For GHC 8.4 and later, provide the --quickjump option.
actualCompiler <- view actualCompilerVersionL
Expand All @@ -1971,19 +1970,29 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap
| ghcVer >= mkVersion [8, 4] -> ["--haddock-option=--quickjump"]
_ -> []

fulfillHaddockExpectations mcurator $ \keep ->
cabal0 keep KeepTHLoading $ concat
[ [ "haddock"
, "--html"
, "--hoogle"
, "--html-location=../$pkg-$version/"
]
, sourceFlag
, ["--internal" | boptsHaddockInternal eeBuildOpts]
, [ "--haddock-option=" <> opt
| opt <- hoAdditionalArgs (boptsHaddockOpts eeBuildOpts) ]
, quickjump
]
fulfillHaddockExpectations mcurator $ \keep -> do
let args = concat
( if isHaddockForHackage
then
[ [ "--for-hackage" ] ]
else
[ [ "--html"
, "--hoogle"
, "--html-location=../$pkg-$version/"
]
, [ "--haddock-option=--hyperlinked-source"
| boptsHaddockHyperlinkSource eeBuildOpts
]
, [ "--internal" | boptsHaddockInternal eeBuildOpts ]
, quickjump
]
<> [ [ "--haddock-option=" <> opt
| opt <- hoAdditionalArgs (boptsHaddockOpts eeBuildOpts)
]
]
)

cabal0 keep KeepTHLoading $ "haddock" : args

let hasLibrary =
case packageLibraries package of
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Config/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ buildOptsFromMonoid BuildOptsMonoid{..} = BuildOpts
, boptsHaddockInternal = fromFirstFalse buildMonoidHaddockInternal
, boptsHaddockHyperlinkSource =
fromFirstTrue buildMonoidHaddockHyperlinkSource
, boptsHaddockForHackage = fromFirstFalse buildMonoidHaddockForHackage
, boptsInstallExes = fromFirstFalse buildMonoidInstallExes
, boptsInstallCompilerTool = fromFirstFalse buildMonoidInstallCompilerTool
, boptsPreFetch = fromFirstFalse buildMonoidPreFetch
Expand Down
6 changes: 6 additions & 0 deletions src/Stack/Options/BuildMonoidParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ buildOptsMonoidParser hide0 = BuildOptsMonoid
<*> haddockDeps
<*> haddockInternal
<*> haddockHyperlinkSource
<*> haddockForHackage
<*> copyBins
<*> copyCompilerTool
<*> preFetch
Expand Down Expand Up @@ -142,6 +143,11 @@ buildOptsMonoidParser hide0 = BuildOptsMonoid
"building hyperlinked source for Haddock documentation (like \
\'haddock --hyperlinked-source')."
hide
haddockForHackage = firstBoolFlagsFalse
"haddock-for-hackage"
"building with flags to generate Haddock documentation suitable for upload \
\to Hackage."
hide
copyBins = firstBoolFlagsFalse
"copy-bins"
"copying binaries to local-bin (see 'stack path')."
Expand Down
13 changes: 11 additions & 2 deletions src/Stack/Types/BuildOpts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ data BuildOpts = BuildOpts
-- ^ Build haddocks for all symbols and packages, like
-- @cabal haddock --internal@
, boptsHaddockHyperlinkSource :: !Bool
-- ^ Build hyperlinked source if possible. Fallback to @hscolour@. Disable
-- for no sources.
-- ^ Build hyperlinked source. Disable for no sources.
, boptsHaddockForHackage :: !Bool
-- ^ Build with flags to generate Haddock documentation suitable to upload
-- to Hackage.
, boptsInstallExes :: !Bool
-- ^ Install executables to user path after building?
, boptsInstallCompilerTool :: !Bool
Expand Down Expand Up @@ -122,6 +124,7 @@ defaultBuildOpts = BuildOpts
, boptsHaddockInternal = defaultFirstFalse buildMonoidHaddockInternal
, boptsHaddockHyperlinkSource =
defaultFirstTrue buildMonoidHaddockHyperlinkSource
, boptsHaddockForHackage = defaultFirstFalse buildMonoidHaddockForHackage
, boptsInstallExes = defaultFirstFalse buildMonoidInstallExes
, boptsInstallCompilerTool = defaultFirstFalse buildMonoidInstallCompilerTool
, boptsPreFetch = defaultFirstFalse buildMonoidPreFetch
Expand Down Expand Up @@ -236,6 +239,7 @@ data BuildOptsMonoid = BuildOptsMonoid
, buildMonoidHaddockDeps :: !(First Bool)
, buildMonoidHaddockInternal :: !FirstFalse
, buildMonoidHaddockHyperlinkSource :: !FirstTrue
, buildMonoidHaddockForHackage :: !FirstFalse
, buildMonoidInstallExes :: !FirstFalse
, buildMonoidInstallCompilerTool :: !FirstFalse
, buildMonoidPreFetch :: !FirstFalse
Expand Down Expand Up @@ -275,6 +279,8 @@ instance FromJSON (WithJSONWarnings BuildOptsMonoid) where
FirstFalse <$> o ..:? buildMonoidHaddockInternalArgName
buildMonoidHaddockHyperlinkSource <-
FirstTrue <$> o ..:? buildMonoidHaddockHyperlinkSourceArgName
buildMonoidHaddockForHackage <-
FirstFalse <$> o ..:? buildMonoidHaddockForHackageArgName
buildMonoidInstallExes <-
FirstFalse <$> o ..:? buildMonoidInstallExesArgName
buildMonoidInstallCompilerTool <-
Expand Down Expand Up @@ -336,6 +342,9 @@ buildMonoidHaddockInternalArgName = "haddock-internal"
buildMonoidHaddockHyperlinkSourceArgName :: Text
buildMonoidHaddockHyperlinkSourceArgName = "haddock-hyperlink-source"

buildMonoidHaddockForHackageArgName :: Text
buildMonoidHaddockForHackageArgName = "haddock-for-hackage"

buildMonoidInstallExesArgName :: Text
buildMonoidInstallExesArgName = "copy-bins"

Expand Down

0 comments on commit 48f8ad6

Please sign in to comment.