7

UPDATE: This question is now out of date. Hackage now uses Haskell version 7.10.2 to build, so the following failure does not occur. The change also appears to have broken some of the scripts mentioned in the answers.

How do I get documentation for my Haskell package onto Hackage?

My understanding what that Hackage would build them, but I get an error

Resolving dependencies...
cabal: Could not resolve dependencies:
trying: MyPackage-0.1.0.2 (user goal)
next goal: base (dependency of MyPackage-0.1.0.2)
rejecting: base-4.7.0.1/installed-e4b... (conflict: MyPackage => base>=4.8 &&
<4.9)
rejecting: base-4.8.1.0, 4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0, 4.6.0.1, 4.6.0.0,
4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0, 4.3.0.0, 4.2.0.2, 4.2.0.1,
4.2.0.0, 4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global constraint requires
installed instance)
Dependency tree exhaustively searched.

I'm not able to downgrade the requirements for my package (which appears to be the obstacle to an automatic build) and I see that some packages say "Docs uploaded by user". However any attempt to build fails (see below.)

How do I get documentation for my Haskell package onto Hackage? In particular, what do I need to do to upload them myself?


I've tried

$ cp -R ./dist/doc/html/MyPackage/ MyPackage-0.1.0.2-docs
$ tar cvzf --format=ustar -f MyPackage-0.1.0.2-docs.tar.gz MyPackage-0.1.0.2-docs
$ curl -X PUT -H 'Content-Type: application/x-tar' -H 'Content-Encoding: gzip' --data-binary '@MyPackage-0.1.0.2-docs.tar.gz' 'https://hackage.haskell.org/package/MyPackage-0.1.0.2/docs' -u 'Rax'

but get

Invalid documentation tarball: File in tar archive is not in the expected directory 'MyPackage-0.1.0.2-docs'


name:                   MyPackage
version:                0.1.0.2
license:                BSD3
license-file:           LICENSE
-- copyright:           
category:               Development
build-type:             Simple
-- extra-source-files:  
cabal-version:          >= 1.22.1.1

library
    -- default-extensions: Trustworthy
    exposed-modules:    MyMod.A,
                        MyMod.A.B
    other-modules:      MyMod.C
    -- other-extensions:
    build-depends:      base >= 4.8.1.0 && <4.9,
                        containers >= 0.5.5.1,
                        split >= 0.2.2,
                        MissingH >= 1.3.0.1
    -- hs-source-dirs:
    default-language:   Haskell2010

I've also tried my own version of the several scripts linked below, but get the same error:

#!/bin/bash

cabal haddock --hyperlink-source --html-location='/package/$pkg-$version/docs'  --contents-location='/package/$pkg'
S=$?
if [ "${S}" -eq "0" ]; then
    cd "dist/doc/html"
    DDIR="${1}-${2}-docs"
    cp -r "${1}" "${DDIR}" && tar -c -v -z --format=ustar -f "${DDIR}.tar.gz" "${DDIR}"
    CS=$?
    if [ "${CS}" -eq "0" ]; then
        echo "Uploading to Hackage…"
        curl -X PUT -H 'Content-Type: application/x-tar' -H 'Content-Encoding: gzip' --data-binary "@${DDIR}.tar.gz" --digest --netrc "https://hackage.haskell.org/package/${1}-${2}/docs"
        exit $?
    else
        echo "Error when packaging the documentation"
        exit $CS
    fi
else
    echo "Error when trying to build the package."
    exit $S
fi

which I invoke with

myscript MyPackage 0.1.0.2

but get the same error.

orome
  • 45,163
  • 57
  • 202
  • 418
  • What's your .cabal file? – ErikR Sep 24 '15 at 19:15
  • @user5402: Added .cabal file. – orome Sep 24 '15 at 19:29
  • Your `tar` command ends with `MyPackage-0.0.1.3-docs`, which doesn't match the version in the rest. Did you perhaps pack the wrong one by accidental tab completion? – Ørjan Johansen Sep 24 '15 at 22:22
  • @ØrjanJohansen: Typo in the question. Sorry. – orome Sep 24 '15 at 22:30
  • What version of haddock are you using? I remember it used to get the links all wrong. I have been using https://github.com/michaelt/streaming/blob/master/upload.sh with Haddock version 2.16.1 (Add your user name when you call "sh upload.sh MyHackageName") Also, I think "cabal-version: >= 1.10" should be fine. – Michael Sep 27 '15 at 14:22
  • @Michael: My Cabal version is `1.22.4.0`. I don't have a separate Haddock version, but my (local) docs show they were built with `2.16.1`. – orome Sep 27 '15 at 15:48
  • @Michael: using the linked `upload.sh` script give the same error as everything else. – orome Sep 27 '15 at 15:49

2 Answers2

5

Does your library require base >= 4.8.1.0?

That's the problem - Hackage is trying to use base == 4.7.0.1 which conflicts with your cabal file.

I would see if you can build your library with the base that Hackage is using.

Some links to uploading docs to Hackage yourself:

ErikR
  • 51,541
  • 9
  • 73
  • 124
  • Ah. I see. That's why it seems to be such a common problem (poking around I see the exact, word for word, error for a couple dozen packages just hit at random). I'll see if I can step down. If not, what are my options for getting docs onto Hackage? – orome Sep 24 '15 at 19:39
  • 3
    Yuk. Cabal needs to do that. No wonder this is a common issue. – orome Sep 24 '15 at 20:37
  • I've also tried the linked approach (which amounts to the same thing as indicated in the edit to my question) with the same result. – orome Sep 25 '15 at 00:54
  • I've tried every link I can find. Every version of the scripts derived from fails the same way. I've added the script I'm using to the question. – orome Sep 25 '15 at 22:00
  • Also note that the [first link's](http://fuuzetsu.co.uk/blog/posts/2014-01-06-Fix-your-Hackage-documentation.html) instructions are wrong (the docs are not in the directory indicated but in an `html` subdirectory). Perhaps they are outdated. All the other instructions I've found are essentially the same as what I have in the script above, and work until the upload stage where I get the indicated error. – orome Sep 26 '15 at 12:22
  • It looks like Hacakge now supports to 7.10.2! Hooray! – orome Sep 28 '15 at 12:16
4

Even if the docs would build on hackage, they take some time to appear and at some point they were broken for an extended period of time. I got used to do it with the neil tool as described here:

http://neilmitchell.blogspot.si/2014/10/fixing-haddock-docs-on-hackage.html

I first install neil (in another sandbox on my disk), then, in the folder of your library:

neil docs --username=YourHackageUsername

It takes care of all the details for you!

Emmanuel Touzery
  • 9,008
  • 3
  • 65
  • 81
  • This would build them locally with my version of `base` though, right? – orome Sep 27 '15 at 15:55
  • Yes honestly it works so transparently that i am not 100% certain how it works but i am pretty sure it does everything locally and just uploads the final product to hackage. – Emmanuel Touzery Sep 27 '15 at 15:57
  • Since I get all the way to the upload step with the other scripts, I think the best avenue is to figure out what "file in tar archive is not in the expected directory". Is there perhaps something that Hackage needs to be uploaded, that would not have been built locally; a setting I should add to my (local) Cabal/Haddock config, perhaps? – orome Sep 27 '15 at 16:02
  • So you didn't try `neil` yet? Honestly at the time I was in your position, I tried `neil`, never looked back, and thankfully never needed to understand the details. – Emmanuel Touzery Sep 27 '15 at 16:21
  • I was a bit spooked by the pages of packages that installing it threatens to break. – orome Sep 27 '15 at 16:53
  • Yes install it in a separate sandbox. Create a new folder, `cabal sandbox init`, `cabal install neil`, then the executable will be in `.cabal-sandbox/bin`. Run it from your app's folder and you are set. You must trust it though because it asks for your hackage password. – Emmanuel Touzery Sep 27 '15 at 17:10
  • I guess I need to get comfortable with sandboxes (I've never used them). Briefly though (1) how do I tear down a sandbox and (2) if `neil docs` works, can I leave the sandbox around and not use it for anything else other than to invoke `neil` from the command line? – orome Sep 27 '15 at 17:18
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/90740/discussion-between-emmanuel-touzery-and-raxacoricofallapatorius). – Emmanuel Touzery Sep 27 '15 at 17:21
  • Oh dear. Now it fails with "curl: (18) transfer closed with outstanding read data remaining". I haven't changed anything! – orome Sep 27 '15 at 22:15
  • Sounds like a straightforward network or server issue. – Emmanuel Touzery Sep 28 '15 at 04:27
  • Probably. It looks like things were changing there. I still get the error, but it no longer matters: Hackage built the docs [with 7.10.2](https://github.com/haskell/hackage-server/issues/419). – orome Sep 28 '15 at 12:15