Skip to content

Commit 2942f93

Browse files
ch1bohamishmack
andauthored
Add .doc derivation to test components (#1982)
* Add a .haddock/.doc derivation to test components Haddocks are built with --tests if we are in a test component. * Write haddocks of tests into package prefix dir Haddock will generate a <componentName>/ directory within this path automatically. So a package with name "foo" and test suite "bar" will have docdir paths: $doc/share/doc/foo/html/index.html # library haddocks $doc/share/doc/foo/html/bar/index.html # bar test suite haddocks * Remove references to component derivation Makes the cleanup step search more liberally for .html files to remove references from. This is needed because test suite haddocks are placed in a <package-name>/html/<test suite name>/ subdirectory. * Fix test --------- Co-authored-by: Hamish Mackenzie <[email protected]>
1 parent fc23ab9 commit 2942f93

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

builder/comp-builder.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ let
361361
});
362362
profiled = self (drvArgs // { enableLibraryProfiling = true; });
363363
dwarf = self (drvArgs // { enableDWARF = true; });
364-
} // lib.optionalAttrs (haskellLib.isLibrary componentId) ({
364+
} // lib.optionalAttrs (haskellLib.isLibrary componentId || haskellLib.isTest componentId) ({
365365
inherit haddock;
366366
inherit (haddock) haddockDir; # This is null if `doHaddock = false`
367367
} // lib.optionalAttrs (haddock ? doc) {

builder/haddock-builder.nix

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323

2424
let
2525
doHaddock' = doHaddock
26-
&& (haskellLib.isLibrary componentId)
26+
&& (haskellLib.isLibrary componentId || haskellLib.isTest componentId)
2727
&& !haskellLib.isCrossHost;
2828

29-
# the target dir for haddock documentation
30-
docdir = docoutput: docoutput + "/share/doc/" + componentId.cname;
29+
# The target dir for haddock documentation
30+
docdir = docoutput: docoutput + "/share/doc/" + package.identifier.name;
3131

3232
packageCfgDir = configFiles.packageCfgDir;
3333

@@ -111,6 +111,7 @@ let
111111
[[ -n $(find . -name "*.hs" -o -name "*.lhs") ]] && {
112112
$SETUP_HS haddock \
113113
"--html" \
114+
${lib.optionalString (haskellLib.isTest componentId) "--tests"} \
114115
${lib.optionalString doHoogle "--hoogle"} \
115116
${lib.optionalString hyperlinkSource "--hyperlink-source"} \
116117
${lib.optionalString quickjump "--quickjump"} \
@@ -129,7 +130,7 @@ let
129130
# Ensure that libraries are not pulled into the docs closure.
130131
# As an example, the prettified source code of a
131132
# Paths_package module will contain store paths of the library package.
132-
for x in "$html/src/"*.html; do
133+
for x in $(find "$html" -name "*.html"); do
133134
remove-references-to -t $out $x
134135
remove-references-to -t ${componentDrv} $x
135136
done

test/sublib-docs/default.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ in recurseIntoAttrs {
4646
otool -L $exe |grep .dylib
4747
'') + ''
4848
49-
# Check that it looks like we have docs
49+
printf "check that it looks like we have docs..." >& 2
5050
test -f "${packages.sublib-docs.components.library.doc}/share/doc/sublib-docs/html/Lib.html"
51-
test -f "${packages.sublib-docs.components.sublibs.slib.doc}/share/doc/slib/html/Slib.html"
51+
test -f "${packages.sublib-docs.components.sublibs.slib.doc}/share/doc/sublib-docs/html/Slib.html"
5252
5353
touch $out
5454
'';

0 commit comments

Comments
 (0)