Skip to content

Commit 20694de

Browse files
committed
Re #729 Warning about --haddock-executables for Cabal < 3.8.1.0
1 parent 4e5b762 commit 20694de

File tree

4 files changed

+62
-27
lines changed

4 files changed

+62
-27
lines changed

.stan.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,25 +190,25 @@
190190

191191
# Anti-pattern: unsafe functions
192192
[[ignore]]
193-
id = "OBS-STAN-0212-FNS1cF-56:17"
193+
id = "OBS-STAN-0212-FNS1cF-57:17"
194194
# ✦ Description: Usage of unsafe functions breaks referential transparency
195195
# ✦ Category: #Unsafe #AntiPattern
196196
# ✦ File: src\Stack\BuildOpts.hs
197197
#
198-
# 55
199-
# 56 ┃ buildMonoid = undefined :: BuildOptsMonoid
200-
# 57 ┃ ^^^^^^^^^
198+
# 56
199+
# 57 ┃ buildMonoid = undefined :: BuildOptsMonoid
200+
# 58 ┃ ^^^^^^^^^
201201

202202
# Anti-pattern: unsafe functions
203203
[[ignore]]
204-
id = "OBS-STAN-0212-FNS1cF-68:14"
204+
id = "OBS-STAN-0212-FNS1cF-69:14"
205205
# ✦ Description: Usage of unsafe functions breaks referential transparency
206206
# ✦ Category: #Unsafe #AntiPattern
207207
# ✦ File: src\Stack\BuildOpts.hs
208208
#
209-
# 67
210-
# 68 ┃ toMonoid = undefined :: TestOptsMonoid
211-
# 69 ┃ ^^^^^^^^^
209+
# 68
210+
# 69 ┃ toMonoid = undefined :: TestOptsMonoid
211+
# 70 ┃ ^^^^^^^^^
212212

213213
# Anti-pattern: Pattern matching on '_'
214214
# Pattern matching on '_' for sum types can create maintainability issues

ChangeLog.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ Other enhancements:
3333
command, as if it had been specified at the command line.
3434
* Add flag `--haddock-executables` to Stack's `build` command (including the
3535
`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).
36+
documentation for executables. Due to a bug in Cabal (the library), Stack will
37+
ignore the flag with a warning for GHC versions before 9.4.
3838

3939
Bug fixes:
4040

src/Stack/Build.hs

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import Stack.Types.BuildOptsMonoid
5050
, buildOptsMonoidInstallExesL, buildOptsMonoidTestsL
5151
)
5252
import Stack.Types.Compiler ( getGhcVersion )
53-
import Stack.Types.CompilerPaths ( cabalVersionL )
53+
import Stack.Types.CompilerPaths ( HasCompiler, cabalVersionL )
5454
import Stack.Types.Config
5555
( Config (..), HasConfig (..), buildOptsL
5656
)
@@ -194,24 +194,32 @@ build msetLocalFiles = do
194194
localsIdents -> throwM $ LocalPackagesPresent localsIdents
195195

196196
checkCabalVersion
197+
haddockExecutablesSupported <- warnAboutHaddockExecutables bopts
198+
let disableHaddockExecutables =
199+
local $ over buildOptsL $ \bo -> bo { haddockExecutables = False }
200+
withHaddockExecutablesGuarded = if haddockExecutablesSupported
201+
then id
202+
else disableHaddockExecutables
197203
warnAboutSplitObjs bopts
198204
warnIfExecutablesWithSameNameCouldBeOverwritten locals plan
199205

200206
when bopts.preFetch $
201207
preFetch plan
202208

203209
if boptsCli.dryrun
204-
then printPlan plan
205-
else executePlan
206-
boptsCli
207-
baseConfigOpts
208-
locals
209-
globalDumpPkgs
210-
snapshotDumpPkgs
211-
localDumpPkgs
212-
installedMap
213-
sourceMap.targets.targets
214-
plan
210+
then
211+
printPlan plan
212+
else
213+
withHaddockExecutablesGuarded $ executePlan
214+
boptsCli
215+
baseConfigOpts
216+
locals
217+
globalDumpPkgs
218+
snapshotDumpPkgs
219+
localDumpPkgs
220+
installedMap
221+
sourceMap.targets.targets
222+
plan
215223

216224
buildLocalTargets ::
217225
HasEnvConfig env
@@ -317,6 +325,33 @@ warnIfExecutablesWithSameNameCouldBeOverwritten locals plan = do
317325
collect :: Ord k => [(k, v)] -> Map k (NonEmpty v)
318326
collect = Map.mapMaybe nonEmpty . Map.fromDistinctAscList . groupSort
319327

328+
warnAboutHaddockExecutables ::
329+
(HasCompiler env, HasTerm env)
330+
=> BuildOpts
331+
-> RIO env Bool
332+
warnAboutHaddockExecutables bopts = do
333+
cabalVer <- view cabalVersionL
334+
if cabalVer < mkVersion [3, 8, 1]
335+
then do
336+
prettyWarnL
337+
[ flow "Stack builds Haddock documentation with the version of the \
338+
\Cabal package that comes with the specified version of GHC. \
339+
\Version"
340+
, fromString $ versionString cabalVer
341+
, flow "was found, which does not support the building of \
342+
\documentation for executables. The option to build such \
343+
\documentation will be ignored. To use the option, use a \
344+
\snapshot that specifies a version of GHC that is 9.4 or later. \
345+
\Stackage LTS Haskell 21.0"
346+
, parens (style Shell "lts-21.0")
347+
, flow "or later or Nightly 2022-11-19"
348+
, parens (style Shell "nightly-2022-11-19")
349+
, flow "or later specify such GHC versions."
350+
]
351+
pure False
352+
else
353+
pure bopts.haddockExecutables
354+
320355
warnAboutSplitObjs :: HasTerm env => BuildOpts -> RIO env ()
321356
warnAboutSplitObjs bopts | bopts.splitObjs =
322357
prettyWarnL

src/Stack/Build/Haddock.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,18 @@ generateHaddockIndex descr bco dumpPackages docRelFP destDir = do
258258
toInterfaceOpt ::
259259
DumpPackage
260260
-> IO (Maybe ([String], UTCTime, Path Abs File, Path Abs File))
261-
toInterfaceOpt DumpPackage {haddockInterfaces, packageIdent, haddockHtml} =
262-
case haddockInterfaces of
261+
toInterfaceOpt dp =
262+
case dp.haddockInterfaces of
263263
[] -> pure Nothing
264264
srcInterfaceFP:_ -> do
265265
srcInterfaceAbsFile <- parseCollapsedAbsFile srcInterfaceFP
266-
let (PackageIdentifier name _) = packageIdent
266+
let (PackageIdentifier name _) = dp.packageIdent
267267
destInterfaceRelFP =
268268
docRelFP FP.</>
269-
packageIdentifierString packageIdent FP.</>
269+
packageIdentifierString dp.packageIdent FP.</>
270270
(packageNameString name FP.<.> "haddock")
271271
docPathRelFP =
272-
fmap ((docRelFP FP.</>) . FP.takeFileName) haddockHtml
272+
fmap ((docRelFP FP.</>) . FP.takeFileName) dp.haddockHtml
273273
interfaces = intercalate "," $ mcons docPathRelFP [srcInterfaceFP]
274274

275275
destInterfaceAbsFile <-

0 commit comments

Comments
 (0)