Skip to content

Commit 4e5b762

Browse files
committed
Re #729 Add --haddock-executables flag
Note: This is not yet guarded for Cabal >= 3.8.1.0.
1 parent b454db9 commit 4e5b762

File tree

8 files changed

+27
-0
lines changed

8 files changed

+27
-0
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Other enhancements:
3131
* In YAML configuration files, the `default-init-snapshot` key is introduced to
3232
allow a default snapshot to be specified for use with the `stack init`
3333
command, as if it had been specified at the command line.
34+
* Add flag `--haddock-executables` to Stack's `build` command (including the
35+
`haddock` synonym for `build --haddock`) to enable also building Haddock
36+
documentation for executables. Will fail for GHC versions before 9.4 due to a
37+
bug in Cabal (the library).
3438

3539
Bug fixes:
3640

src/Stack/Build/ExecutePackage.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ realConfigAndBuild
609609
, [ "--haddock-option=--hyperlinked-source"
610610
| ee.buildOpts.haddockHyperlinkSource
611611
]
612+
, [ "--executables" | ee.buildOpts.haddockExecutables ]
612613
, [ "--internal" | ee.buildOpts.haddockInternal ]
613614
, quickjump
614615
]

src/Stack/BuildOpts.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ defaultBuildOpts = BuildOpts
3131
, haddockOpts = defaultHaddockOpts
3232
, openHaddocks = defaultFirstFalse buildMonoid.openHaddocks
3333
, haddockDeps = Nothing
34+
, haddockExecutables = defaultFirstFalse buildMonoid.haddockExecutables
3435
, haddockInternal = defaultFirstFalse buildMonoid.haddockInternal
3536
, haddockHyperlinkSource = defaultFirstTrue buildMonoid.haddockHyperlinkSource
3637
, haddockForHackage = defaultFirstFalse buildMonoid.haddockForHackage

src/Stack/Config/Build.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ buildOptsFromMonoid buildMonoid = BuildOpts
5454
, haddockDeps = if isHaddockFromHackage
5555
then Nothing
5656
else getFirst buildMonoid.haddockDeps
57+
, haddockExecutables =
58+
not isHaddockFromHackage
59+
&& fromFirstFalse buildMonoid.haddockExecutables
5760
, haddockInternal =
5861
not isHaddockFromHackage
5962
&& fromFirstFalse buildMonoid.haddockInternal

src/Stack/Options/BuildMonoidParser.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ buildOptsMonoidParser hide0 = BuildOptsMonoid
4141
<*> haddockOptsParser hideBool
4242
<*> openHaddocks
4343
<*> haddockDeps
44+
<*> haddockExecutables
4445
<*> haddockInternal
4546
<*> haddockHyperlinkSource
4647
<*> haddockForHackage
@@ -133,6 +134,11 @@ buildOptsMonoidParser hide0 = BuildOptsMonoid
133134
"building Haddock documentation for dependencies. (default: if building \
134135
\Haddock documentation, true; otherwise, false)"
135136
hide
137+
haddockExecutables = firstBoolFlagsFalse
138+
"haddock-executables"
139+
"also building Haddock documentation for all executables (like \
140+
\'cabal haddock --executables')."
141+
hide
136142
haddockInternal = firstBoolFlagsFalse
137143
"haddock-internal"
138144
"building Haddock documentation for internal modules (like \

src/Stack/Types/BuildOpts.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ data BuildOpts = BuildOpts
3232
-- ^ Open haddocks in the browser?
3333
, haddockDeps :: !(Maybe Bool)
3434
-- ^ Build haddocks for dependencies?
35+
, haddockExecutables :: !Bool
36+
-- ^ Also build Haddock documentation for all executable components, like
37+
-- @runghc Setup.hs haddock --executables@.
3538
, haddockInternal :: !Bool
3639
-- ^ Build haddocks for all symbols and packages, like
3740
-- @cabal haddock --internal@

src/Stack/Types/BuildOptsMonoid.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ data BuildOptsMonoid = BuildOptsMonoid
4545
, haddockOpts :: !HaddockOptsMonoid
4646
, openHaddocks :: !FirstFalse
4747
, haddockDeps :: !(First Bool)
48+
, haddockExecutables :: !FirstFalse
4849
, haddockInternal :: !FirstFalse
4950
, haddockHyperlinkSource :: !FirstTrue
5051
, haddockForHackage :: !FirstFalse
@@ -81,6 +82,7 @@ instance FromJSON (WithJSONWarnings BuildOptsMonoid) where
8182
haddockOpts <- jsonSubWarnings (o ..:? haddockOptsArgName ..!= mempty)
8283
openHaddocks <- FirstFalse <$> o ..:? openHaddocksArgName
8384
haddockDeps <- First <$> o ..:? haddockDepsArgName
85+
haddockExecutables <- FirstFalse <$> o ..:? haddockExecutablesArgName
8486
haddockInternal <- FirstFalse <$> o ..:? haddockInternalArgName
8587
haddockHyperlinkSource <- FirstTrue <$> o ..:? haddockHyperlinkSourceArgName
8688
haddockForHackage <- FirstFalse <$> o ..:? haddockForHackageArgName
@@ -115,6 +117,7 @@ instance FromJSON (WithJSONWarnings BuildOptsMonoid) where
115117
, haddockOpts
116118
, openHaddocks
117119
, haddockDeps
120+
, haddockExecutables
118121
, haddockInternal
119122
, haddockHyperlinkSource
120123
, haddockForHackage
@@ -161,6 +164,9 @@ openHaddocksArgName = "open-haddocks"
161164
haddockDepsArgName :: Text
162165
haddockDepsArgName = "haddock-deps"
163166

167+
haddockExecutablesArgName :: Text
168+
haddockExecutablesArgName = "haddock-executables"
169+
164170
haddockInternalArgName :: Text
165171
haddockInternalArgName = "haddock-internal"
166172

tests/unit/Stack/ConfigSpec.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ buildOptsConfig =
7171
" - \"--css=/home/user/my-css\"\n" ++
7272
" open-haddocks: true\n" ++
7373
" haddock-deps: true\n" ++
74+
" haddock-executables: true\n" ++
7475
" haddock-internal: true\n" ++
7576
" haddock-hyperlink-source: false\n" ++
7677
" haddock-for-hackage: false\n" ++
@@ -107,6 +108,7 @@ buildOptsHaddockForHackageConfig =
107108
" haddock: true\n" ++
108109
" open-haddocks: true\n" ++
109110
" haddock-deps: true\n" ++
111+
" haddock-executables: true\n" ++
110112
" haddock-internal: true\n" ++
111113
" haddock-hyperlink-source: false\n" ++
112114
" haddock-for-hackage: true\n" ++
@@ -232,6 +234,7 @@ spec = beforeAll setup $ do
232234
}
233235
bopts.openHaddocks `shouldBe` True
234236
bopts.haddockDeps `shouldBe` Just True
237+
bopts.haddockExecutables `shouldBe` True
235238
bopts.haddockInternal `shouldBe` True
236239
bopts.haddockHyperlinkSource `shouldBe` False
237240
bopts.haddockForHackage `shouldBe` False

0 commit comments

Comments
 (0)