Skip to content

Commit

Permalink
reinstate Haddock, closes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
KiaraGrouwstra committed Apr 15, 2020
1 parent d6fdde5 commit 6f60796
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/nix-haddock-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: nix-haddock-linux

# If you need to debug this action, use following action.
# on: [push, pull_request]

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v7
- name: Setup repo
- name: Build
run: |
nix-env -i cachix
cachix use tycho01
nix-build -A synthesis-docs
pwd
find result/ |head
mkdir public
cp -r ./result/share/doc/* public/
- name: Deploy
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
# personal_token: ${{ secrets.PERSONAL_TOKEN }}
# github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
59 changes: 59 additions & 0 deletions nix/haddock-combine.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{ runCommand, lib, haskellPackages }:
{ hspkgs # Haskell packages to make documentation for. Only those with a "doc" output will be used.
# Note: we do not provide arbitrary additional Haddock options, as these would not be
# applied consistently, since we're reusing the already built Haddock for the packages.
, prologue ? null # Optionally, a file to be used for the Haddock "--prologue" option.
}:
let
hsdocs = builtins.map (x: x.doc) (builtins.filter (x: x ? doc) hspkgs);
in runCommand "haddock-join" { buildInputs = [ hsdocs ]; } ''
# Merge all the docs from the packages. We don't use symlinkJoin because:
# - We are going to want to redistribute this, so we don't want any symlinks.
# - We want to be selective about what we copy (we don't need the hydra
# tarballs from the other packages, for example.
mkdir -p "$out/share/doc"
for pkg in ${lib.concatStringsSep " " hsdocs}; do
cp -R $pkg/share/doc/* "$out/share/doc"
done
# We're going to sed all the files so they'd better be writable!
chmod -R +w $out/share/doc
# We're now going to rewrite all the pre-generated Haddock HTML output
# so that links point to the appropriate place within our combined output,
# rather than into the store.
root=$out/share/doc
for f in $(find $out -name "*.html"); do
# Replace all links to the docs we're processing with relative links
# to the root of the doc directory we're creating - the rest of the link is
# the same.
# Also, it's not a a file:// link now because it's a relative URL instead
# of an absolute one.
relpath=$(realpath --relative-to=$(dirname $f) --no-symlinks $root)
pkgsRegex="${"file://(" + (lib.concatStringsSep "|" hsdocs) + ")/share/doc"}"
sed -i -r "s,$pkgsRegex,$relpath,g" "$f"
# Now also replace the index/contents links so they point to (what will be)
# the combined ones instead.
# Match the enclosing quotes to make sure the regex for index.html doesn't also match
# the trailing part of doc-index.html
sed -i -r "s,\"index\.html\",\"$relpath/share/doc/index.html\",g" "$f"
sed -i -r "s,\"doc-index\.html\",\"$relpath/share/doc/doc-index.html\",g" "$f"
done
# Move to the docdir. We do this so that we can give relative docpaths to
# Haddock so it will generate relative (relocatable) links in the index.
cd $out/share/doc
# Collect all the interface files and their docpaths (in this case
# we can just use the enclosing directory).
interfaceOpts=()
for interfaceFile in $(find . -name "*.haddock"); do
docdir=$(dirname $interfaceFile)
interfaceOpts+=("--read-interface=$docdir,$interfaceFile")
done
# Generate the contents and index
${haskellPackages.ghc}/bin/haddock \
--gen-contents \
--gen-index \
${lib.optionalString (prologue != null) "--prologue ${prologue}"} \
"''${interfaceOpts[@]}"
''
10 changes: 10 additions & 0 deletions nix/shared.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ in
synthesis_cudatoolkit_10_1
;

synthesis-docs = (
(import ./haddock-combine.nix {
runCommand = pkgs.runCommand;
lib = pkgs.lib;
haskellPackages = pkgs.haskellPackages;
}) {hspkgs = [
synthesis_cpu
];
}
);
shell-synthesis_cpu = (doBenchmark base-compiler.synthesis_cpu).env.overrideAttrs(fixmkl);
shell-synthesis_cudatoolkit_9_2 = (doBenchmark base-compiler.synthesis_cudatoolkit_9_2).env.overrideAttrs(fixmkl);
shell-synthesis_cudatoolkit_10_1 = (doBenchmark base-compiler.synthesis_cudatoolkit_10_1).env.overrideAttrs(fixmkl);
Expand Down

0 comments on commit 6f60796

Please sign in to comment.