Skip to content

Commit 72bb687

Browse files
authored
Merge pull request #6282 from commercialhaskell/re6270-1
Re #6270 Step 1, provide `--haddock-for-hackage`
2 parents d5d49f0 + d9139af commit 72bb687

File tree

8 files changed

+107
-37
lines changed

8 files changed

+107
-37
lines changed

ChangeLog.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ Other enhancements:
3131
* Add option of the form `--doctest-option=<argument>` to `stack build`, where
3232
`doctest` is a program recognised by versions of the Cabal library from
3333
`1.24.0.0`.
34+
* Experimental: Add flag `--haddock-for-hackage` to Stack's `build` command
35+
(including the `haddock` synonym for `build --haddock`) to enable building
36+
with flags to generate Haddock documentation suitable for upload to Hackage.
3437

3538
Bug fixes:
3639

@@ -231,8 +234,8 @@ Other enhancements:
231234
`STACK_ROOT` environment variable.
232235
* Add `stack path --global-config`, to yield the full path of Stack's
233236
user-specific global YAML configuration file (`config.yaml`).
234-
* Add an experimental option, `allow-newer-deps`, which allows users to
235-
specify a subset of dependencies for which version bounds should be ignored
237+
* Experimental: Add option `allow-newer-deps`, which allows users to specify a
238+
subset of dependencies for which version bounds should be ignored
236239
(`allow-newer-deps: ['foo', 'bar']`). This field has no effect unless
237240
`allow-newer` is enabled.
238241

@@ -784,7 +787,7 @@ Major changes:
784787
* Remove the `stack image` command. With the advent of Docker multistage
785788
builds, this functionality is no longer useful. For an example, please see
786789
[Building Haskell Apps with Docker](https://www.fpcomplete.com/blog/2017/12/building-haskell-apps-with-docker).
787-
* Support building GHC from source (experimental)
790+
* Experimental: Support building GHC from source
788791
* Stack now supports building and installing GHC from source. The built GHC
789792
is uniquely identified by a commit id and an Hadrian "flavour" (Hadrian is
790793
the newer GHC build system), hence `compiler` can be set to use a GHC
@@ -1667,11 +1670,10 @@ Other enhancements:
16671670
[#3126](https://github.com/commercialhaskell/stack/issues/3126)
16681671
* When using Nix, nix-shell now depends always on git to prevent runtime errors
16691672
while fetching metadata
1670-
* The `stack unpack` command now accepts a form where an explicit
1671-
Hackage revision hash is specified, e.g. `stack unpack
1672-
foo-1.2.3@gitsha1:deadbeef`. Note that this should be considered
1673-
_experimental_, Stack will likely move towards a different hash
1674-
format in the future.
1673+
* Experimental: The `stack unpack` command now accepts a form where an explicit
1674+
Hackage revision hash is specified, e.g.
1675+
`stack unpack foo-1.2.3@gitsha1:deadbeef`. Note that Stack will likely move
1676+
towards a different hash format in the future.
16751677
* Binary "stack upgrade" will now warn if the installed executable is not
16761678
on the PATH or shadowed by another entry.
16771679
* Allow running tests on tarball created by sdist and upload
@@ -2286,7 +2288,7 @@ Other enhancements:
22862288
* Fix too much rebuilding when enabling/disabling profiling flags.
22872289
* `stack build pkg-1.0` will now build `pkg-1.0` even if the snapshot specifies
22882290
a different version (it introduces a temporary extra-dep)
2289-
* Experimental support for `--split-objs` added
2291+
* Experimental: Support for `--split-objs` added
22902292
[#1284](https://github.com/commercialhaskell/stack/issues/1284).
22912293
* `git` packages with submodules are supported by passing the `--recursive`
22922294
flag to `git clone`.
@@ -2765,7 +2767,7 @@ Other enhancements:
27652767
[#1070](https://github.com/commercialhaskell/stack/pull/1070)
27662768
* Use Stack-installed GHCs for `stack init --solver`
27672769
[#1072](https://github.com/commercialhaskell/stack/issues/1072)
2768-
* New experimental `stack query` command
2770+
* Experimental: Add `stack query` command
27692771
[#1087](https://github.com/commercialhaskell/stack/issues/1087)
27702772
* By default, Stack no longer rebuilds a package due to GHC options changes.
27712773
This behavior can be tweaked with the `rebuild-ghc-options` setting.

doc/build_command.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ stack build [TARGET] [--dry-run] [--pedantic] [--fast] [--ghc-options OPTIONS]
1212
[--[no-]library-stripping] [--[no-]executable-stripping]
1313
[--[no-]haddock] [--haddock-arguments HADDOCK_ARGS]
1414
[--[no-]open] [--[no-]haddock-deps] [--[no-]haddock-internal]
15-
[--[no-]haddock-hyperlink-source] [--[no-]copy-bins]
16-
[--[no-]copy-compiler-tool] [--[no-]prefetch] [--[no-]keep-going]
17-
[--[no-]keep-tmp-files] [--[no-]force-dirty] [--[no-]test]
18-
[--[no-]rerun-tests] [--ta|--test-arguments TEST_ARGS] [--coverage]
19-
[--no-run-tests] [--test-suite-timeout ARG]
15+
[--[no-]haddock-hyperlink-source] [--[no-]haddock-for-hackage]
16+
[--[no-]copy-bins] [--[no-]copy-compiler-tool] [--[no-]prefetch]
17+
[--[no-]keep-going] [--[no-]keep-tmp-files] [--[no-]force-dirty]
18+
[--[no-]test] [--[no-]rerun-tests] [--ta|--test-arguments TEST_ARGS]
19+
[--coverage] [--no-run-tests] [--test-suite-timeout ARG]
2020
[--[no-]tests-allow-stdin] [--[no-]bench]
2121
[--ba|--benchmark-arguments BENCH_ARGS] [--no-run-benchmarks]
2222
[--[no-]reconfigure] [--cabal-verbosity VERBOSITY |
@@ -234,18 +234,58 @@ Default: Enabled (if building Haddock documnentation)
234234

235235
Unset the flag to disable building Haddock documentation for dependencies.
236236

237+
### `--[no-]haddock-for-haddock` flag
238+
239+
:octicons-beaker-24: Experimental
240+
241+
:octicons-tag-24: UNRELEASED
242+
243+
Default: Disabled
244+
245+
Set the flag to build with flags to generate Haddock documentation suitable for
246+
upload to Hackage.
247+
248+
For each local package, the generated Haddock documentation files are in
249+
directory `doc\html\<package_version>-docs\`, relative to Stack's dist work
250+
directory (see `stack path --dist-dir`).
251+
252+
If the flag is set:
253+
254+
* the [`--[no-]haddock-hyperlink-source`](#no-haddock-hyperlink-source-flag)
255+
flag is ignored and `--haddock-hyperlink-source` is implied; and
256+
* the [`--[no-]haddock-internal`](#no-haddock-hyperlink-internal-flag) flag is
257+
ignored and `--no-haddock-internal` is implied.
258+
259+
!!! note
260+
261+
If set, Haddock will warn that `-source-*` options are ignored when
262+
`--hyperlinked-source` is enabled. That is due to a known bug in Cabal
263+
(the libiary).
264+
265+
!!! note
266+
267+
If set, Cabal (the library) will report that documentation has been created
268+
in `index.html` and `<package_name>.txt` files. Those files do not exist.
269+
That false report is due to a known bug in Cabal (the library).
270+
237271
### `--[no-]haddock-hyperlink-source` flag
238272

239273
Default: Enabled
240274

241275
Unset the flag to disable building building hyperlinked source for Haddock.
242276

277+
If the [`--haddock-for-hackage`](#no-haddock-for-haddock-flag) flag is passed,
278+
this flag is ignored.
279+
243280
### `--[no-]haddock-internal` flag
244281

245282
Default: Disabled
246283

247284
Set the flag to enable building Haddock documentation for internal modules.
248285

286+
If the [`--haddock-for-hackage`](#no-haddock-for-haddock-flag) flag is passed,
287+
this flag is ignored.
288+
249289
### `--[no-]keep-going` flag
250290

251291
Default (`stack build`): Disabled

doc/path_command.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Pass the following flags for information about specific files or locations:
2323
|--compiler-exe |The GHC executable. |
2424
|--compiler-tools-bin |The directory containing binaries specific to a particular compiler.|
2525
|--config-location |Stack's project-level YAML configuration file (`stack.yaml`).|
26-
|--dist-dir |The dist working directory, relative to the package directory.|
26+
|--dist-dir |The dist work directory, relative to the package directory.|
2727
|--extra-include-dirs |Extra include directories. |
2828
|--extra-library-dirs |Extra library directories. |
2929
|--ghc-package-path |The `GHC_PACKAGE_PATH` environment variable. |

doc/yaml_configuration.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,10 @@ build:
439439
# - "--css=/home/user/my-css"
440440
open-haddocks: false # --open
441441
haddock-deps: false # if unspecified, defaults to true if haddock is set
442-
haddock-internal: false
442+
haddock-for-hackage: false # if specified, implies haddock-internal: false and
443+
# haddock-hyperlink-source: true
444+
haddock-internal: false # ignored, if haddock-for-hackage: true
445+
haddock-hyperlink-source: true # ignored, if haddock-for-hackage: true
443446

444447
# These are inadvisable to use in your global configuration, as they make the
445448
# Stack build command line behave quite differently.

src/Stack/Build/Execute.hs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,7 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap
16731673
&& maybe True (Set.notMember pname . curatorSkipHaddock) mcurator
16741674
expectHaddockFailure =
16751675
maybe False (Set.member pname . curatorExpectHaddockFailure)
1676+
isHaddockForHackage = boptsHaddockForHackage eeBuildOpts
16761677
fulfillHaddockExpectations mcurator action
16771678
| expectHaddockFailure mcurator = do
16781679
eres <- tryAny $ action KeepOpen
@@ -1956,11 +1957,9 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap
19561957

19571958
mcurator <- view $ buildConfigL.to bcCurator
19581959
when (doHaddock mcurator package) $ do
1959-
announce "haddock"
1960-
let sourceFlag =
1961-
[ "--haddock-option=--hyperlinked-source"
1962-
| boptsHaddockHyperlinkSource eeBuildOpts
1963-
]
1960+
announce $ if isHaddockForHackage
1961+
then "haddock for Hackage"
1962+
else "haddock"
19641963

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

1973-
fulfillHaddockExpectations mcurator $ \keep ->
1974-
cabal0 keep KeepTHLoading $ concat
1975-
[ [ "haddock"
1976-
, "--html"
1977-
, "--hoogle"
1978-
, "--html-location=../$pkg-$version/"
1979-
]
1980-
, sourceFlag
1981-
, ["--internal" | boptsHaddockInternal eeBuildOpts]
1982-
, [ "--haddock-option=" <> opt
1983-
| opt <- hoAdditionalArgs (boptsHaddockOpts eeBuildOpts) ]
1984-
, quickjump
1985-
]
1972+
fulfillHaddockExpectations mcurator $ \keep -> do
1973+
let args = concat
1974+
( if isHaddockForHackage
1975+
then
1976+
[ [ "--for-hackage" ] ]
1977+
else
1978+
[ [ "--html"
1979+
, "--hoogle"
1980+
, "--html-location=../$pkg-$version/"
1981+
]
1982+
, [ "--haddock-option=--hyperlinked-source"
1983+
| boptsHaddockHyperlinkSource eeBuildOpts
1984+
]
1985+
, [ "--internal" | boptsHaddockInternal eeBuildOpts ]
1986+
, quickjump
1987+
]
1988+
<> [ [ "--haddock-option=" <> opt
1989+
| opt <- hoAdditionalArgs (boptsHaddockOpts eeBuildOpts)
1990+
]
1991+
]
1992+
)
1993+
1994+
cabal0 keep KeepTHLoading $ "haddock" : args
19861995

19871996
let hasLibrary =
19881997
case packageLibraries package of

src/Stack/Config/Build.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ buildOptsFromMonoid BuildOptsMonoid{..} = BuildOpts
4141
, boptsHaddockInternal = fromFirstFalse buildMonoidHaddockInternal
4242
, boptsHaddockHyperlinkSource =
4343
fromFirstTrue buildMonoidHaddockHyperlinkSource
44+
, boptsHaddockForHackage = fromFirstFalse buildMonoidHaddockForHackage
4445
, boptsInstallExes = fromFirstFalse buildMonoidInstallExes
4546
, boptsInstallCompilerTool = fromFirstFalse buildMonoidInstallCompilerTool
4647
, boptsPreFetch = fromFirstFalse buildMonoidPreFetch

src/Stack/Options/BuildMonoidParser.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ buildOptsMonoidParser hide0 = BuildOptsMonoid
4343
<*> haddockDeps
4444
<*> haddockInternal
4545
<*> haddockHyperlinkSource
46+
<*> haddockForHackage
4647
<*> copyBins
4748
<*> copyCompilerTool
4849
<*> preFetch
@@ -142,6 +143,11 @@ buildOptsMonoidParser hide0 = BuildOptsMonoid
142143
"building hyperlinked source for Haddock documentation (like \
143144
\'haddock --hyperlinked-source')."
144145
hide
146+
haddockForHackage = firstBoolFlagsFalse
147+
"haddock-for-hackage"
148+
"building with flags to generate Haddock documentation suitable for upload \
149+
\to Hackage."
150+
hide
145151
copyBins = firstBoolFlagsFalse
146152
"copy-bins"
147153
"copying binaries to local-bin (see 'stack path')."

src/Stack/Types/BuildOpts.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ data BuildOpts = BuildOpts
6767
-- ^ Build haddocks for all symbols and packages, like
6868
-- @cabal haddock --internal@
6969
, boptsHaddockHyperlinkSource :: !Bool
70-
-- ^ Build hyperlinked source if possible. Fallback to @hscolour@. Disable
71-
-- for no sources.
70+
-- ^ Build hyperlinked source. Disable for no sources.
71+
, boptsHaddockForHackage :: !Bool
72+
-- ^ Build with flags to generate Haddock documentation suitable to upload
73+
-- to Hackage.
7274
, boptsInstallExes :: !Bool
7375
-- ^ Install executables to user path after building?
7476
, boptsInstallCompilerTool :: !Bool
@@ -122,6 +124,7 @@ defaultBuildOpts = BuildOpts
122124
, boptsHaddockInternal = defaultFirstFalse buildMonoidHaddockInternal
123125
, boptsHaddockHyperlinkSource =
124126
defaultFirstTrue buildMonoidHaddockHyperlinkSource
127+
, boptsHaddockForHackage = defaultFirstFalse buildMonoidHaddockForHackage
125128
, boptsInstallExes = defaultFirstFalse buildMonoidInstallExes
126129
, boptsInstallCompilerTool = defaultFirstFalse buildMonoidInstallCompilerTool
127130
, boptsPreFetch = defaultFirstFalse buildMonoidPreFetch
@@ -236,6 +239,7 @@ data BuildOptsMonoid = BuildOptsMonoid
236239
, buildMonoidHaddockDeps :: !(First Bool)
237240
, buildMonoidHaddockInternal :: !FirstFalse
238241
, buildMonoidHaddockHyperlinkSource :: !FirstTrue
242+
, buildMonoidHaddockForHackage :: !FirstFalse
239243
, buildMonoidInstallExes :: !FirstFalse
240244
, buildMonoidInstallCompilerTool :: !FirstFalse
241245
, buildMonoidPreFetch :: !FirstFalse
@@ -275,6 +279,8 @@ instance FromJSON (WithJSONWarnings BuildOptsMonoid) where
275279
FirstFalse <$> o ..:? buildMonoidHaddockInternalArgName
276280
buildMonoidHaddockHyperlinkSource <-
277281
FirstTrue <$> o ..:? buildMonoidHaddockHyperlinkSourceArgName
282+
buildMonoidHaddockForHackage <-
283+
FirstFalse <$> o ..:? buildMonoidHaddockForHackageArgName
278284
buildMonoidInstallExes <-
279285
FirstFalse <$> o ..:? buildMonoidInstallExesArgName
280286
buildMonoidInstallCompilerTool <-
@@ -336,6 +342,9 @@ buildMonoidHaddockInternalArgName = "haddock-internal"
336342
buildMonoidHaddockHyperlinkSourceArgName :: Text
337343
buildMonoidHaddockHyperlinkSourceArgName = "haddock-hyperlink-source"
338344

345+
buildMonoidHaddockForHackageArgName :: Text
346+
buildMonoidHaddockForHackageArgName = "haddock-for-hackage"
347+
339348
buildMonoidInstallExesArgName :: Text
340349
buildMonoidInstallExesArgName = "copy-bins"
341350

0 commit comments

Comments
 (0)