Skip to content

Commit a3ad794

Browse files
authored
Merge pull request commercialhaskell#6522 from commercialhaskell/fix6520
Fix commercialhaskell#6520 Avoid archiving Haddock for Hackage when inappropriate
2 parents 23ae8c2 + 3228519 commit a3ad794

File tree

3 files changed

+55
-29
lines changed

3 files changed

+55
-29
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Behaviour changes:
2323
`latest-snapshot: https://stackage-haddock.haskell.org/snapshots.json`.
2424
* Remove hidden flag `--skip-intermediate-deps`, effectively deprecated since
2525
Stack 1.3.0, from `ghci` and `repl` commands.
26+
* The `haddock --haddock-for-hackage` command only seeks to create an archive of
27+
the `<package_version>-docs` directory for build targets and if flags
28+
excluding the building of project packages are not set.
2629

2730
Other enhancements:
2831

doc/build_command.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,17 @@ Set the flag to build project packages with flags to generate Haddock
315315
documentation suitable for upload to Hackage. The form of the Haddock
316316
documentation generated for other packages is unaffected.
317317

318-
For each project package:
319-
320-
* the generated Haddock documentation files are in directory
321-
`doc\html\<package_version>-docs\`, relative to Stack's dist work directory
322-
(see [`stack path --dist-dir`](path_command.md)); and
323-
* an archive of the `<package_version>-docs` directory and its contents is in
324-
Stack's dist work directory.
318+
For each project package, the generated Haddock documentation files are in
319+
directory `doc\html\<package_version>-docs\`, relative to Stack's dist work
320+
directory (see [`stack path --dist-dir`](path_command.md)).
321+
322+
Unless flags are set to exclude the building of project packages, for each
323+
targetted project package with generated documentation, an archive of the
324+
`<package_version>-docs` directory and its contents is in Stack's dist work
325+
directory. (The flags that exclude project packages are
326+
[`--only-dependencies`](#-only-dependencies-flag),
327+
[`--dependencies-only`](#-dependencies-only-flag), or
328+
[`--only-snapshot`](#-only-snapshot-flag).)
325329

326330
If the flag is set:
327331

src/Stack/Build/Haddock.hs

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ import Stack.Types.CompilerPaths
4747
( CompilerPaths (..), HasCompiler (..) )
4848
import Stack.Types.ConfigureOpts ( BaseConfigOpts (..) )
4949
import Stack.Types.BuildOpts ( BuildOpts (..), HaddockOpts (..) )
50-
import Stack.Types.BuildOptsCLI ( BuildOptsCLI (..) )
50+
import Stack.Types.BuildOptsCLI ( BuildOptsCLI (..), BuildSubset (BSOnlyDependencies, BSOnlySnapshot) )
5151
import Stack.Types.DumpPackage ( DumpPackage (..) )
52-
import Stack.Types.EnvConfig ( HasEnvConfig (..) )
52+
import Stack.Types.EnvConfig ( EnvConfig (..), HasEnvConfig (..) )
5353
import Stack.Types.GhcPkgId ( GhcPkgId )
5454
import Stack.Types.InterfaceOpt ( InterfaceOpt (..) )
5555
import Stack.Types.Package
@@ -397,14 +397,17 @@ generateLocalHaddockForHackageArchives ::
397397
(HasEnvConfig env, HasTerm env)
398398
=> [LocalPackage]
399399
-> RIO env ()
400-
generateLocalHaddockForHackageArchives =
401-
mapM_
402-
( \lp ->
403-
let pkg = lp.package
404-
pkgId = PackageIdentifier pkg.name pkg.version
405-
pkgDir = parent lp.cabalFP
406-
in generateLocalHaddockForHackageArchive pkgDir pkgId
407-
)
400+
generateLocalHaddockForHackageArchives lps = do
401+
buildSubset <- view $ envConfigL . to (.buildOptsCLI.buildSubset)
402+
let localsExcluded =
403+
buildSubset == BSOnlyDependencies || buildSubset == BSOnlySnapshot
404+
unless localsExcluded $
405+
forM_ lps $ \lp ->
406+
let pkg = lp.package
407+
pkgId = PackageIdentifier pkg.name pkg.version
408+
pkgDir = parent lp.cabalFP
409+
in when lp.wanted $
410+
generateLocalHaddockForHackageArchive pkgDir pkgId
408411

409412
-- | Generate an archive file containing local Haddock documentation for
410413
-- Hackage, in a form accepted by Hackage.
@@ -428,15 +431,22 @@ generateLocalHaddockForHackageArchive pkgDir pkgId = do
428431
)
429432
tarGzFile = distDir </> tarGzFileName
430433
docDir = distDir </> docDirSuffix </> htmlDirSuffix
431-
createTarGzFile tarGzFile docDir nameRelDir
432-
prettyInfo $
433-
fillSep
434-
[ flow "Archive of Haddock documentation for Hackage for"
435-
, style Current (fromString pkgIdName)
436-
, flow "created at:"
437-
]
438-
<> line
439-
<> pretty tarGzFile
434+
tarGzFileCreated <- createTarGzFile tarGzFile docDir nameRelDir
435+
if tarGzFileCreated
436+
then
437+
prettyInfo $
438+
fillSep
439+
[ flow "Archive of Haddock documentation for Hackage for"
440+
, style Current (fromString pkgIdName)
441+
, flow "created at:"
442+
]
443+
<> line
444+
<> pretty tarGzFile
445+
else
446+
prettyWarnL
447+
[ flow "No Haddock documentation for Hackage available for"
448+
, style Error (fromString pkgIdName) <> "."
449+
]
440450

441451
createTarGzFile ::
442452
Path Abs File
@@ -445,10 +455,19 @@ createTarGzFile ::
445455
-- ^ Base directory
446456
-> Path Rel Dir
447457
-- ^ Directory to archive, relative to base directory
448-
-> RIO env ()
458+
-> RIO env Bool
449459
createTarGzFile tar base dir = do
450-
entries <- liftIO $ Tar.pack base' [dir']
451-
BL.writeFile tar' $ GZip.compress $ Tar.write entries
460+
dirExists <- doesDirExist $ base </> dir
461+
if dirExists
462+
then do
463+
entries <- liftIO $ Tar.pack base' [dir']
464+
if null entries
465+
then pure False
466+
else do
467+
ensureDir $ parent tar
468+
BL.writeFile tar' $ GZip.compress $ Tar.write entries
469+
pure True
470+
else pure False
452471
where
453472
base' = fromAbsDir base
454473
dir' = fromRelDir dir

0 commit comments

Comments
 (0)