Skip to content

Fix haddock via Setup.hs with internal libraries #7827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 30, 2022
Merged

Fix haddock via Setup.hs with internal libraries #7827

merged 6 commits into from
Jan 30, 2022

Conversation

brandonchinn178
Copy link
Collaborator

@brandonchinn178 brandonchinn178 commented Nov 19, 2021

Fixes #1919

@brandonchinn178
Copy link
Collaborator Author

I wrote a test that failed and then made a fix that made it pass. I'm not sure if this is the correct fix, though. Would love guidance on an alternate fix

@brandonchinn178 brandonchinn178 changed the title [WIP] Fix haddock via Setup.hs with internal libraries Fix haddock via Setup.hs with internal libraries Nov 19, 2021
@Mikolaj
Copy link
Member

Mikolaj commented Nov 19, 2021

Hi @brandonchinn178! Thank you for the test that shows there is a problem and for the fix. Does anybody have any comments?

The CI failure seems to be not a random breakage, but related to haddocks, so probably there is some more work to do.

@brandonchinn178
Copy link
Collaborator Author

Sorry forgot to commit the output for cabal-testsuite with --with-cabal specified. Updated.

Copy link
Member

@Mikolaj Mikolaj left a comment

Choose a reason for hiding this comment

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

LGTM. Let's hope this fixes the stack use case.

@brandonchinn178
Copy link
Collaborator Author

@Mikolaj Thanks! Is there anything else I need to do to get this merged?

@Mikolaj
Copy link
Member

Mikolaj commented Nov 22, 2021

@brandonchinn178: lure one more reviewer with cookies.

@brandonchinn178
Copy link
Collaborator Author

@hsenag @int-e @mietek it seems like you three are the last contributors to comment on the issue. Any of you able/willing to review this?

@hsenag
Copy link
Member

hsenag commented Nov 22, 2021

@brandonchinn178 I tried your branch and I still get the error, but I'm not sure if I did the right things to actually use the dev cabal-install/Cabal. I pointed at eb2dd41 in a source-repository-package stanza in cabal.project, as well as building cabal-install from your branch and running that binary.

Regardless, I'm not really able to review your code itself, but once I can verify it fixes my problem I'd be happy to give a thumbs-up on that basis.

@Mikolaj
Copy link
Member

Mikolaj commented Nov 22, 2021

@hsenag: I'm afraid you might have used Cabal library from hackage. That's why README says to run cabal install --project-file=cabal.project.release cabal-install and the project file mentions packages: Cabal/ (which needs to be from the same branch/commit). I think the easiest way is to clone Brandon's fork and branch, e.g., with

git checkout -b brandonchinn178-chinn/haddock master
git pull https://github.com/brandonchinn178/cabal.git chinn/haddock

and run the cabal command above in there.

@Mikolaj
Copy link
Member

Mikolaj commented Nov 29, 2021

@hsenag: ping?

@hsenag
Copy link
Member

hsenag commented Nov 29, 2021

@Mikolaj sorry for the delay, I've kicked off going through the steps now. Feel free to ping me again in a day or two if I don't report back.

@hsenag
Copy link
Member

hsenag commented Nov 29, 2021

I'm still seeing the failure. What I've done this time:

  • Checked out eb2dd41 into ~/temp/cabal.
  • In ~/temp/cabal, run cabal install --project-file=cabal.project.release cabal-install --installdir=../bin
  • In my project folder (a recent version of darcs), added ~/temp/cabal/Cabal to packages
  • In my project folder, blew away dist-newstyle then ran ~/temp/bin/cabal v2-haddock test:darcs-test --enable-tests --enable-documentation --haddock-tests

and I still get

Running Haddock on test suite 'darcs-test' for darcs-2.17.1..
setup: internal error when calculating transitive package dependencies.
Debug info: []

@Mikolaj
Copy link
Member

Mikolaj commented Nov 29, 2021

Oh.

So we have a repro. Thank you @hsenag.

@brandonchinn178: are you able to reproduce the failure with darcs-2.17.1? Would you like me to try?

@brandonchinn178
Copy link
Collaborator Author

I use Stack primarily, so I'm not sure how much help I'll be in debugging Cabal invocations. If you could take a look, that'd be great. Thanks!

@hsenag
Copy link
Member

hsenag commented Nov 30, 2021

FYI I've now verified that this also happens with darcs-2.16.4 from hackage. Steps were to cabal unpack it, then add a cabal.project containing packages: . ~/temp/cabal/Cabal, then run the v2-haddock command.

@Mikolaj
Copy link
Member

Mikolaj commented Nov 30, 2021

@hsenag: I confirm your results, both with and without the cabal.project file.

However, I see Build-Type: Custom and I know custom setup files are usually a different can of worms. BTW, is the custom setup still necessary in the darcs package? Is there a ticket somewhere specifically about similar problems with Custom setups?

@brandonchinn178: did you intend to fix this for build-type: Simple or Build-Type: Custom or both? Can the fix be extended to Custom?

Here's the -v2 log of the run without cabal.project:

~/ttt/darcs-2.16.4$ ~/temp/bin/cabal -v2 v2-haddock test:darcs-test --enable-tests --enable-documentation --haddock-tests
this build was affected by the following (project) config files:
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built:
 - darcs-2.16.4 *test (first run)
creating /home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build
creating /home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/tmp
creating
/home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4
creating
/home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/cache
whenReRegister: nothing to register
creating
/home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/setup
/home/mikolaj/.ghcup/bin/ghc --make -fbuilding-cabal-package -odir /home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/setup -hidir /home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/setup -i -i/home/mikolaj/ttt/darcs-2.16.4/. -optP-include -optP/home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/setup/setup_macros.h -hide-all-packages -no-user-package-db -package-db /home/mikolaj/.cabal/store/ghc-8.10.7/package.db -package-db /home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/packagedb/ghc-8.10.7 -package-id Cabal-3.2.1.0 -package-id base-4.14.3.0 -package-id directory-1.3.6.0 -package-id filepath-1.4.2.1 -package-id process-1.6.13.2 /home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/setup/setup.hs -o /home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/setup/setup -threaded
/home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/setup/setup
haddock --verbose=2
--builddir=/home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4
--tests test:darcs-test
darcs log -a --from-tag 2.16.4 --count
creating
/home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/build/global-autogen
/home/mikolaj/.ghcup/bin/haddock --ghc-version
/home/mikolaj/.ghcup/bin/ghc --print-libdir -hide-all-packages
/home/mikolaj/.ghcup/ghc/8.10.7/bin/ghc-pkg-8.10.7 init /home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/package.conf.inplace
creating
/home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/build/darcs-test
creating
/home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/build/darcs-test/autogen
creating
/home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/build/darcs-test/autogen
Preprocessing test suite 'darcs-test' for darcs-2.16.4..
Running Haddock on test suite 'darcs-test' for darcs-2.16.4..
CallStack (from HasCallStack):
  $, called at libraries/Cabal/Cabal/Distribution/Simple/Haddock.hs:255:13 in Cabal-3.2.1.0:Distribution.Simple.Haddock
  haddock, called at libraries/Cabal/Cabal/Distribution/Simple.hs:636:35 in Cabal-3.2.1.0:Distribution.Simple
  haddockHook, called at libraries/Cabal/Cabal/Distribution/Simple/UserHooks.hs:139:5 in Cabal-3.2.1.0:Distribution.Simple.UserHooks
  haddockHook, called at libraries/Cabal/Cabal/Distribution/Simple/UserHooks.hs:139:5 in Cabal-3.2.1.0:Distribution.Simple.UserHooks
  cmd_hook, called at libraries/Cabal/Cabal/Distribution/Simple.hs:497:9 in Cabal-3.2.1.0:Distribution.Simple
  cmd_hook, called at libraries/Cabal/Cabal/Distribution/Simple.hs:516:4 in Cabal-3.2.1.0:Distribution.Simple
  hookedActionWithArgs, called at libraries/Cabal/Cabal/Distribution/Simple.hs:495:5 in Cabal-3.2.1.0:Distribution.Simple
  hookedAction, called at libraries/Cabal/Cabal/Distribution/Simple.hs:360:3 in Cabal-3.2.1.0:Distribution.Simple
  haddockAction, called at libraries/Cabal/Cabal/Distribution/Simple.hs:187:50 in Cabal-3.2.1.0:Distribution.Simple
  defaultMainHelper, called at libraries/Cabal/Cabal/Distribution/Simple.hs:125:42 in Cabal-3.2.1.0:Distribution.Simple
  $, called at /home/mikolaj/ttt/darcs-2.16.4/dist-newstyle/build/x86_64-linux/ghc-8.10.7/darcs-2.16.4/setup/setup.hs:36:8 in main:Main
setup: internal error when calculating transitive package dependencies.
Debug info: []

CallStack (from HasCallStack):
  withMetadata, called at src/Distribution/Simple/Utils.hs:379:14 in Cabal-3.7.0.0-543aaa840f170abad978ace330d2fed5d9915f52f7fc73a0f5f6df83df6a5532:Distribution.Simple.Utils
Error: cabal: Failed to build documentation for darcs-2.16.4-inplace.

@brandonchinn178
Copy link
Collaborator Author

The function I edited should be the single entrypoint for everything. Short of a custom Setup.hs script that overrides the haddock hook with some completely adhoc function, my fix should still apply. I'll try to download the darcs code today and take a look at the Setup.hs script

@Mikolaj
Copy link
Member

Mikolaj commented Nov 30, 2021

I'm afraid it does override a whole lot:

  haddockHook = \ pkg lbi hooks flags ->
                let verb = fromFlag $ haddockVerbosity flags
                 in commonBuildHook haddockHook pkg lbi hooks verb >>= ($ flags) ,

-- | For @./Setup build@ and @./Setup haddock@, do some unusual
-- things, then invoke the base behaviour ("simple hook").
commonBuildHook :: (UserHooks -> PackageDescription -> LocalBuildInfo -> t -> a)
                -> PackageDescription -> LocalBuildInfo -> t -> Verbosity -> IO a
commonBuildHook runHook pkg lbi hooks verbosity = do
  versionInfoExists <-
    (&&) <$> doesFileExist "release/distributed-context"
         <*> doesFileExist "release/distributed-version"
  unless versionInfoExists $
    callProcess "runghc" ["./release/gen-version-info.hs"]
  (version, state) <- determineVersion verbosity pkg
  generateVersionModule verbosity lbi version state
  return $ runHook simpleUserHooks pkg lbi hooks

@hsenag
Copy link
Member

hsenag commented Nov 30, 2021

It might just be on us to update the hook then, if so apologies for the noise. We have been trying to get rid of our custom setup but there are still a few pieces left.

@brandonchinn178
Copy link
Collaborator Author

@hsenag do your comments mean that you're unable to verify that this PR is correct, since the darcs repo does its own stuff with Cabal hooks?

@int-e @mietek are either of you able to review this change?

@hsenag
Copy link
Member

hsenag commented Dec 17, 2021

@hsenag do your comments mean that you're unable to verify that this PR is correct, since the darcs repo does its own stuff with Cabal hooks?

Based on my tests on the darcs repo, the problem still happens with your changes. But hopefully it should be possible to update our hook to take account of your changes? I didn't have a chance to take a deeper look to figure that out yet, though it's on my TODO list. If you can point me in the right direction it would probably speed that up :-)

@Mikolaj
Copy link
Member

Mikolaj commented Jan 29, 2022

@brandonchinn178, @hsenag: how about, to avoid mutual blocking, we merge this PR and test, fix, amend, etc., as needed, later on?

@hsenag
Copy link
Member

hsenag commented Jan 29, 2022

@brandonchinn178, @hsenag: how about, to avoid mutual blocking, we merge this PR and test, fix, amend, etc., as needed, later on?

I'd be very happy with that, and I never intended to block this PR.

If I understood the start of the discussion about whether it fixed the darcs case, it was because @brandonchinn178 needed a second reviewer and that I could review from the point of view of a user whose problem was fixed. Without that, and without knowing the cabal code, I'm not sure my review would be worth much. But given this has been languishing for a while, I could provide that approval anyway?

@Mikolaj
Copy link
Member

Mikolaj commented Jan 29, 2022

But given this has been languishing for a while, I could provide that approval anyway?

That would be very much appreciated indeed. :)

@hsenag
Copy link
Member

hsenag commented Jan 29, 2022

But given this has been languishing for a while, I could provide that approval anyway?

Turns out it doesn't help because I'm not a reviewer with write access :-(

@Mikolaj
Copy link
Member

Mikolaj commented Jan 29, 2022

Turns out it doesn't help because I'm not a reviewer with write access :-(

That's fine --- I can force-merge regardless. :)

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.

LGTM

@Mikolaj
Copy link
Member

Mikolaj commented Jan 29, 2022

@hsenag, @Kleidukos: thank you so much.

@brandonchinn178: once you rebase and fix the conflicts, let's merge!

@Mikolaj Mikolaj added merge me Tell Mergify Bot to merge and removed attention: needs-review labels Jan 29, 2022
@brandonchinn178
Copy link
Collaborator Author

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cabal: cmd/haddock merge me Tell Mergify Bot to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cabal haddock --executables fails with "internal error when calculating transitive package dependencies"
4 participants