From 6f60796d84680eddf4a01b30e2f9d992a9717a6e Mon Sep 17 00:00:00 2001 From: Kiara Grouwstra Date: Wed, 15 Apr 2020 21:08:38 +0200 Subject: [PATCH] reinstate Haddock, closes #20 --- .github/workflows/nix-haddock-linux.yml | 31 +++++++++++++ nix/haddock-combine.nix | 59 +++++++++++++++++++++++++ nix/shared.nix | 10 +++++ 3 files changed, 100 insertions(+) create mode 100644 .github/workflows/nix-haddock-linux.yml create mode 100644 nix/haddock-combine.nix diff --git a/.github/workflows/nix-haddock-linux.yml b/.github/workflows/nix-haddock-linux.yml new file mode 100644 index 0000000..dbd7ef2 --- /dev/null +++ b/.github/workflows/nix-haddock-linux.yml @@ -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 diff --git a/nix/haddock-combine.nix b/nix/haddock-combine.nix new file mode 100644 index 0000000..6875e89 --- /dev/null +++ b/nix/haddock-combine.nix @@ -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[@]}" +'' \ No newline at end of file diff --git a/nix/shared.nix b/nix/shared.nix index 28f0f7e..571122c 100644 --- a/nix/shared.nix +++ b/nix/shared.nix @@ -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);