-
Notifications
You must be signed in to change notification settings - Fork 244
/
Copy pathhaddock-builder.nix
161 lines (134 loc) · 5.19 KB
/
haddock-builder.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
{ stdenv, buildPackages, lib, haskellLib, ghc, ghcForComponent, nonReinstallablePkgs, runCommand, writeText, writeScript, makeConfigFiles }:
{ componentId
, component
, package
, flags
, commonAttrs
, preHaddock
, postHaddock
, pkgconfig
, commonConfigureFlags
, doHaddock
, doHoogle
, hyperlinkSource
, quickjump
, setupHaddockFlags
, needsProfiling
, componentDrv
, configFiles # component config files
}:
let
doHaddock' = doHaddock
&& (haskellLib.isLibrary componentId || haskellLib.isTest componentId)
&& !haskellLib.isCrossHost;
# The target dir for haddock documentation
docdir = docoutput: docoutput + "/share/doc/" + package.identifier.name;
packageCfgDir = configFiles.packageCfgDir;
fullName = "${componentDrv.name}-haddock";
# These config files are like the one used in the build derivation,
# but `chooseDrv` will be used to map all the references to libraries
# to their haddock derivation.
docsConfigFiles = makeConfigFiles {
inherit (package) identifier;
inherit component fullName flags needsProfiling;
chooseDrv = p: p.haddock;
inherit (componentDrv) enableDWARF;
};
finalConfigureFlags = lib.concatStringsSep " " (
[ "--prefix=${componentDrv}"
"${haskellLib.componentTarget componentId}"
"$(cat $configFiles/configure-flags)"
]
++ commonConfigureFlags
++ lib.optional doHaddock' " --docdir=${docdir "$doc"}");
shellWrappers = ghcForComponent {
componentName = fullName;
configFiles = docsConfigFiles;
inherit (componentDrv) enableDWARF;
inherit (component) plugins;
};
drv = stdenv.mkDerivation (commonAttrs // {
name = fullName;
passthru = {
# The directory containing the haddock documentation.
haddockDir = lib.const (if doHaddock' then "${docdir drv.doc}/html" else null);
};
# `out` contains the `package.conf.d` files used for building the
# haddock files.
# `doc` contains just the haddock output files.
outputs = ["out" "configFiles" "ghc"]
++ lib.optional doHaddock' "doc";
propagatedBuildInputs = haskellLib.checkUnique "${fullName} propagatedBuildInputs" (
haskellLib.uniqueWithName (map lib.getDev (builtins.concatLists pkgconfig))
++ configFiles.libDeps); # libDeps is already deduplicated
buildInputs = haskellLib.uniqueWithName (lib.flatten component.libs);
nativeBuildInputs =
[ ghc buildPackages.removeReferencesTo ]
++ componentDrv.executableToolDepends;
configurePhase = ''
mkdir -p $configFiles
mkdir -p $ghc
wrappedGhc=$ghc
${docsConfigFiles.script}
${shellWrappers.script}
PATH=$wrappedGhc/bin:$PATH
runHook preConfigure
echo Configure flags:
printf "%q " ${finalConfigureFlags}
echo
$SETUP_HS configure ${finalConfigureFlags}
runHook postConfigure
'';
buildPhase = ''
mkdir -p $out
'' + lib.optionalString doHaddock' ''
runHook preHaddock
docdir="${docdir "$doc"}"
# This mkdir needed for packages like base-noprelude and bytestring-builder
# (which is also empty when `bytestring >= 0.10.4`)
mkdir -p "$docdir"
# If we don't have any source files, no need to run haddock
[[ -n $(find . -name "*.hs" -o -name "*.lhs") ]] && {
$SETUP_HS haddock \
"--html" \
${lib.optionalString (haskellLib.isTest componentId) "--tests"} \
${lib.optionalString doHoogle "--hoogle"} \
${lib.optionalString hyperlinkSource "--hyperlink-source"} \
${lib.optionalString quickjump "--quickjump"} \
${lib.concatStringsSep " " setupHaddockFlags}
}
runHook postHaddock
'';
installPhase =
''
html="dist/doc/html/${package.identifier.name}"
if [ -d "$html" ]; then
# Ensure that libraries are not pulled into the docs closure.
# As an example, the prettified source code of a
# Paths_package module will contain store paths of the library package.
for x in $(find "$html" -name "*.html"); do
remove-references-to -t $out $x
remove-references-to -t ${componentDrv} $x
done
docdir="${docdir "$doc"}"
mkdir -p "$docdir"
cp -R "$html" "$docdir"/html
fi
${ghc.targetPrefix}ghc-pkg -v0 init $out/package.conf.d
for i in "${componentDrv}/package.conf.d"/*.conf; do
# Copy the .conf files from the build derivation, but replace the `haddock-intefaces:`
# field with correct location for haddocks (now it is known). This will insure that
# the other haddock derivations build to reference this one will have the correct
# working hyper links.
pkg=$(basename "$i")
sed -e "s|haddock-interfaces:.*|haddock-interfaces: $docdir/html/${componentId.cname}.haddock|" -e "s|haddock-html:.*|haddock-html: $docdir/html/|" "$i" > "$pkg"
${ghc.targetPrefix}ghc-pkg -v0 --package-db $configFiles/${configFiles.packageCfgDir} -f $out/package.conf.d register "$pkg"
done
ln -s ${componentDrv}/exactDep $out/exactDep
ln -s ${componentDrv}/envDep $out/envDep
'';
}
// haskellLib.optionalHooks {
inherit preHaddock postHaddock;
});
in drv