-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-colcon-package-docs.nix
62 lines (51 loc) · 1.95 KB
/
build-colcon-package-docs.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
# These arguments filled automatically when the file is imported with callPackage.
{
colconMinimalDocs,
fontconfig,
graphviz,
lib,
makeColconHook,
propagateColconRunDepends,
stdenv
}:
# Passed manually when the function is called in buildColconPackage.
pkgFinal:
with lib; let
# The doc build of a package requires the package's runtime environment, plus access to the doc
# outputs of all build dependencies (for the purposes of doxygen tags and intersphinx).
colconRecursiveBuildDependsDocs = map (d: d.docs) pkgFinal.colconRecursiveBuildDepends;
recursiveDocDepends = propagateColconRunDepends [ pkgFinal ];
partitionedDocDepends = partition (d: d.colconPackage or false) recursiveDocDepends;
colconRecursiveDocDepends = partitionedDocDepends.right;
nonColconRecursiveDocDepends = partitionedDocDepends.wrong;
in stdenv.mkDerivation {
name = "${pkgFinal.name}-docs";
src = pkgFinal.src;
nativeBuildInputs = [
colconMinimalDocs
fontconfig
graphviz
];
buildInputs = nonColconRecursiveDocDepends;
phases = [ "unpackPhase" "patchPhase" "buildPhase" "fixupPhase" ];
postHook = makeColconHook colconRecursiveDocDepends;
colconDocumentArgs = [
"--docs-base $out"
];
COLCON_DOCUMENT_PATH = lib.makeSearchPath "/" colconRecursiveBuildDependsDocs;
# Sandboxed builds don't have access to /etc or /home, so without this config we get a spew of warnings.
FONTCONFIG_FILE="${fontconfig.out}/etc/fonts/fonts.conf";
FONTCONFIG_PATH="${fontconfig.out}/etc/fonts/"; # default config directory
XDG_CACHE_HOME = "/tmp/cache"; # creating a temp cache drectory for fontconfig
buildPhase = ''
colconArgs=$(eval echo "document $colconDocumentArgs")
colcon $colconArgs
rm -f $out/COLCON_IGNORE
'';
# Replace any symlinks with the actual files, so we don't have broken links to the source.
fixupPhase = ''
for f in $(find $out -type l); do
cp --remove-destination $(readlink -e $f) $f
done
'';
}