Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Better support for multiple packages #1277

Merged
merged 8 commits into from
Apr 11, 2021

Conversation

coot
Copy link
Collaborator

@coot coot commented Dec 26, 2020

Description

This PR allows to create documentation for multiple packages. It is useful if one has multiple packages in a single repository.

Workflow

Workflow to create documentation for multiple packages. It assumes that there are two packages package-1 and package-2.

Configure & create haddocks

Add the following lines to cabal.project.local file (for every package):

package package-1
  haddock-options: --use-index=../doc-index.html --use-contents=../index.html --base-url=..

package package-2
  haddock-options: --use-index=../doc-index.html --use-contents=../index.html --base-url=..

The newly added option --base-url configures the location from which static files will be loaded.

One can now run:

cabal haddock --haddock-html --haddock-quickjump all

To compile haddocks.

Copy documentation

Copy documentation to a common directory (docs in this example), e.g.

mkdir docs
cp -r ./dist-newstyle/build/x86_64-linux/ghc-8.10.2/pakcage-1-0.1.0.0/noopt/doc/html/package-1 docs
cp -r ./dist-newstyle/build/x86_64-linux/ghc-8.10.2/pakcage-2-0.1.0.0/noopt/doc/html/package-2 docs

Create index

The following command will create html index as well doc-index.json file by combining doc-index.json files of all included packages.

haddock \
    -o docs \
    --quickjump \
    --gen-index \
    --gen-contents \
    --read-interface=some-package-1,docs/package-1/some-package-1.haddock \
    --read-interface=some-package-2,docs/package-2/some-package-2.haddock

Serve docs directory and enjoy the documentation with a single html index and QuickSearch working across all projects.

Changes

  • Using aeson for serialisation and deserialisation of doc-index.json files;
  • doc-index.json file for the summary page is generated from doc-index.json files of all packages included with --read-interface option (-i);
  • added --base-url flag (Flag_BaseURL). If given and not equal to . or ./ static files (css, js, json) will not be copied. All pages will load them from the given url.

Target branch

I am not sure which target branch I should pick for this PR, I choose ghc-8.10 as this is the current version of ghc.

@coot coot marked this pull request as draft December 26, 2020 18:03
@coot coot force-pushed the coot/multiple-packages branch from 5e68f07 to 33522ff Compare December 27, 2020 21:06
@coot coot changed the base branch from ghc-8.10 to ghc-head December 27, 2020 21:07
@coot coot force-pushed the coot/multiple-packages branch 2 times, most recently from 848a29c to 8373782 Compare December 28, 2020 16:24
@coot coot marked this pull request as ready for review December 28, 2020 16:27
@coot
Copy link
Collaborator Author

coot commented Jan 14, 2021

@Kleidukos anything, beside resolving conflicts ;), that I can help to make this PR get reviewed / accepted?

Copy link
Member

@Kleidukos Kleidukos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, a pretty good PR. I left a couple of remarks, mostly extraneous blank lines, and a question about the Json parser you're committing. cc @coot

haddock-api/src/Haddock.hs Outdated Show resolved Hide resolved
haddock-api/src/Haddock.hs Show resolved Hide resolved
haddock-api/src/Haddock/Backends/Xhtml.hs Show resolved Hide resolved
haddock-api/src/Haddock/Backends/Xhtml.hs Outdated Show resolved Hide resolved
haddock-api/src/Haddock/Utils/Json.hs Show resolved Hide resolved
haddock-api/src/Haddock/Utils/Json.hs Show resolved Hide resolved
haddock-api/src/Haddock/Utils/Json.hs Outdated Show resolved Hide resolved
haddock-api/src/Haddock/Utils/Json.hs Show resolved Hide resolved
@Kleidukos
Copy link
Member

@coot Also, don't forget to open a PR to update the docs with the new option --base-url and the workflow. :)

@coot coot force-pushed the coot/multiple-packages branch from 8373782 to 69da008 Compare January 23, 2021 07:33
@coot
Copy link
Collaborator Author

coot commented Jan 23, 2021

Which branch should I target, ghc-8.10 or ghc-9.0?

@coot
Copy link
Collaborator Author

coot commented Jan 23, 2021

I see that the ghc-9.0 is the default branch now, I'll target that branch then.

@coot coot force-pushed the coot/multiple-packages branch from 69da008 to 9a08ccd Compare January 23, 2021 07:49
@coot coot changed the base branch from ghc-head to ghc-9.0 January 23, 2021 07:54
@coot
Copy link
Collaborator Author

coot commented Jan 23, 2021

@Kleidukos all your comments are addressed.

@coot coot requested a review from Kleidukos January 23, 2021 07:56
@Kleidukos
Copy link
Member

@coot Wonderful, thank you very much for this contribution ✨

@coot coot force-pushed the coot/multiple-packages branch from 9a08ccd to c667a96 Compare January 23, 2021 08:11
@coot
Copy link
Collaborator Author

coot commented Jan 23, 2021

I spottved a typo in the description of --base-url option, and I pushed one commit which documents it in the invoke.rst file. Could you proof read it. I sometimes make silly typos.

@mpickering
Copy link
Collaborator

This is certainly an improvement. Thanks @coot. The patch didn't do quite what I expected though, the resulting index has all the modules merged together from all different packages.

2021-01-29-090611_869x951

and clicking on links from one package to another local package result in a rendering error, as the links are not correctly relative to the other copied documentation.

2021-01-29-090751_1123x937

2021-01-29-090843_1108x145

@coot
Copy link
Collaborator Author

coot commented Feb 5, 2021

@Kleidukos maybe you can help me: how one can build haddock ghc-9.0 branch, which compiler version one should use?

I tried to use just released ghc-9.0.1 but I get:

cabal: Could not resolve dependencies:
[__0] trying: haddock-api-2.24.0 (user goal)
[__1] trying: ghc-paths-0.1.0.12 (dependency of haddock-api)
[__2] next goal: ghc-paths:setup.Cabal (dependency of ghc-paths)
[__2] rejecting: ghc-paths:setup.Cabal-3.4.0.0/installed-3.4.0.0 (conflict:
ghc-paths => ghc-paths:setup.Cabal>=1.6 && <3.3)
[__2] rejecting: ghc-paths:setup.Cabal-3.2.1.0, ghc-paths:setup.Cabal-3.2.0.0,
ghc-paths:setup.Cabal-3.0.2.0, ghc-paths:setup.Cabal-3.0.1.0,
ghc-paths:setup.Cabal-3.0.0.0, ghc-paths:setup.Cabal-2.4.1.0,
ghc-paths:setup.Cabal-2.4.0.1, ghc-paths:setup.Cabal-2.4.0.0,
ghc-paths:setup.Cabal-2.2.0.1, ghc-paths:setup.Cabal-2.2.0.0,
ghc-paths:setup.Cabal-2.0.1.1, ghc-paths:setup.Cabal-2.0.1.0,
ghc-paths:setup.Cabal-2.0.0.2, ghc-paths:setup.Cabal-1.24.2.0,
ghc-paths:setup.Cabal-1.24.0.0, ghc-paths:setup.Cabal-1.22.8.0,
ghc-paths:setup.Cabal-1.22.7.0, ghc-paths:setup.Cabal-1.22.6.0,
ghc-paths:setup.Cabal-1.22.5.0, ghc-paths:setup.Cabal-1.22.4.0,
ghc-paths:setup.Cabal-1.22.3.0, ghc-paths:setup.Cabal-1.22.2.0,
ghc-paths:setup.Cabal-1.22.1.1, ghc-paths:setup.Cabal-1.22.1.0,
ghc-paths:setup.Cabal-1.22.0.0, ghc-paths:setup.Cabal-1.20.0.4,
ghc-paths:setup.Cabal-1.20.0.3, ghc-paths:setup.Cabal-1.20.0.2,
ghc-paths:setup.Cabal-1.20.0.1, ghc-paths:setup.Cabal-1.20.0.0,
ghc-paths:setup.Cabal-1.18.1.7, ghc-paths:setup.Cabal-1.18.1.6,
ghc-paths:setup.Cabal-1.18.1.5, ghc-paths:setup.Cabal-1.18.1.4,
ghc-paths:setup.Cabal-1.18.1.3, ghc-paths:setup.Cabal-1.18.1.2,
ghc-paths:setup.Cabal-1.18.1.1, ghc-paths:setup.Cabal-1.18.1,
ghc-paths:setup.Cabal-1.18.0, ghc-paths:setup.Cabal-1.16.0.3,
ghc-paths:setup.Cabal-1.16.0.2, ghc-paths:setup.Cabal-1.16.0.1,
ghc-paths:setup.Cabal-1.16.0, ghc-paths:setup.Cabal-1.14.0,
ghc-paths:setup.Cabal-1.12.0, ghc-paths:setup.Cabal-1.10.2.0,
ghc-paths:setup.Cabal-1.10.1.0, ghc-paths:setup.Cabal-1.10.0.0,
ghc-paths:setup.Cabal-1.8.0.6, ghc-paths:setup.Cabal-1.8.0.4,
ghc-paths:setup.Cabal-1.8.0.2, ghc-paths:setup.Cabal-1.6.0.3,
ghc-paths:setup.Cabal-1.6.0.2, ghc-paths:setup.Cabal-1.6.0.1,
ghc-paths:setup.Cabal-1.4.0.2, ghc-paths:setup.Cabal-1.4.0.1,
ghc-paths:setup.Cabal-1.4.0.0, ghc-paths:setup.Cabal-1.2.4.0,
ghc-paths:setup.Cabal-1.2.3.0, ghc-paths:setup.Cabal-1.2.2.0,
ghc-paths:setup.Cabal-1.2.1, ghc-paths:setup.Cabal-1.1.6,
ghc-paths:setup.Cabal-1.24.1.0 (constraint from minimum version of Cabal used
by Setup.hs requires >=3.4)
[__2] fail (backjumping, conflict set: ghc-paths, ghc-paths:setup.Cabal)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: ghc-paths:setup.Cabal, haddock-api,
ghc-paths

Building with hadrian/build still does not work?

Wouldn't it be more convenient to support multiple versions of ghc by haddock?

@Kleidukos
Copy link
Member

@coot Can you rebase on the current ghc-9.0? You should inherit the proper github action files for the CI

@coot
Copy link
Collaborator Author

coot commented Feb 7, 2021

Thanks @Kleidukos, it worked :).

@coot coot force-pushed the coot/multiple-packages branch from c667a96 to 8906a23 Compare February 7, 2021 14:36
@coot
Copy link
Collaborator Author

coot commented Feb 13, 2021

@mpickering did you tried to pass an absolute url to --base-url?

@coot
Copy link
Collaborator Author

coot commented Feb 13, 2021

Did you build haddock of sub-packages with cabal haddock --haddock-html --haddock-quickjump all and then copied all the produced haddocks to a common directory? Maybe I falsely assume that there should not be links to anything under dist-newstyle (at least for local packages).

@coot coot force-pushed the coot/multiple-packages branch from 8906a23 to 36c3173 Compare February 13, 2021 17:04
@coot
Copy link
Collaborator Author

coot commented Feb 13, 2021

I force pushed, because I found that the json index was not generated when the option --quickjump option was specified. I think I introduced this when I was rebasing the other time.

coot added 4 commits March 10, 2021 20:13
Aeson style FromJSON class with Parsec based json parser.
When creating haddock summary page for multiple packages render
doc-index.json file using contents of all found 'doc-index.json' files.
When rendering html, render doc-index.json file independently of
maybe_index_url option.  doc-index.json file is useful now even if
maybe_index_url is not `Nothing`.
New `Flag_BaseURL` which configures from where static files are loaded
(--base-url).  If given and not equal "." static files are not coppied,
as this indicates that they are not read from the the directory where
we'd copy them.  The default value is ".".
@coot coot force-pushed the coot/multiple-packages branch from 29a6443 to 4899f99 Compare March 10, 2021 19:13
@coot coot force-pushed the coot/multiple-packages branch from 4899f99 to de8873e Compare March 10, 2021 20:00
@coot
Copy link
Collaborator Author

coot commented Mar 10, 2021

All tests now pass :).

@Kleidukos
Copy link
Member

@alexbiehl This is a pretty meaty PR, I'll need your eyes on that one for the end ;)

@Mikolaj
Copy link
Member

Mikolaj commented Apr 9, 2021

Great job! Am I right that this could be used (perhaps with some changes) as a workaround for haddock not being able to produce sensible Hackage documentation for packages with many internal libraries? If this is trivial enough, could the necessary invocations be listed in documentation as well? I'd gladly test them on my multi-lib package.

@coot
Copy link
Collaborator Author

coot commented Apr 10, 2021

Am I right that this could be used (perhaps with some changes) as a workaround for haddock not being able to produce sensible Hackage documentation for packages with many internal libraries?

Yes you're right :).

If this is trivial enough, could the necessary invocations be listed in documentation as well? I'd gladly test them on my multi-lib package.

Good point, I should add that; For now you can check here for instructions (the haddocs are served on github-pages). The ultimate goal is to have cabal haddock --directory docs all to produce haddocs for all local components.

@Kleidukos Kleidukos merged commit 119ad93 into haskell:ghc-9.0 Apr 11, 2021
@Kleidukos
Copy link
Member

Alright it's squashed and merged. Thanks a lot for your patience @coot

@coot
Copy link
Collaborator Author

coot commented Apr 11, 2021

@Kleidukos my pleasure; since its merged to ghc-9.0 branch, does it mean it will be available in a next 9.0.x release?

@coot coot deleted the coot/multiple-packages branch April 11, 2021 08:29
@Kleidukos
Copy link
Member

@coot I'll backport the patch to ghc-9.2 as well

@coot
Copy link
Collaborator Author

coot commented Apr 11, 2021

Let me know if you'll have any problems or need some help with testing. It's easy to get it wrong (or at least I got it wrong when I was rebasing).

@Kleidukos
Copy link
Member

Okay sure, will ping you! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants