Skip to content
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

cabal haddock --executables fails with "internal error when calculating transitive package dependencies" #1919

Closed
massysett opened this issue Jun 4, 2014 · 25 comments · Fixed by #7827

Comments

@massysett
Copy link

When running

cabal haddock --executables

the command fails with

cabal: internal error when calculating transitive package dependencies.
Debug info: []

I have tagged my source code tree where this problem exists:

https://github.com/massysett/penny/tree/cabal_error

This is cabal-install version 1.20.0.2.

@mietek
Copy link
Contributor

mietek commented Jun 26, 2014

@kosmikus: I have prepared a minimal Cabal package reproducing this error.

With GHC 7.8.2 and cabal 1.20.0.2:

$ git clone https://github.com/mietek/cabal-fail-one.git
$ cd cabal-fail-one
$ make
cabal sandbox init
Writing a default package environment file to
/Users/mietek/Projects/Haskell/cabal-fail-one/cabal.sandbox.config
Creating a new sandbox at
/Users/mietek/Projects/Haskell/cabal-fail-one/.cabal-sandbox
cabal install \
      --dependencies-only \
      --enable-documentation \
      --enable-tests \
      --reorder-goals
Resolving dependencies...
All the requested packages are already installed:
Use --reinstall if you want to reinstall anyway.
cabal configure --enable-tests
Resolving dependencies...
Configuring cabal-fail-one-0.1...
cabal test --show-details=streaming
Building cabal-fail-one-0.1...
Preprocessing library cabal-fail-one-0.1...
[1 of 1] Compiling Cabal.Fail.One   ( src/lib/Cabal/Fail/One.hs, dist/build/Cabal/Fail/One.o )
In-place registering cabal-fail-one-0.1...
Preprocessing executable 'cabal-fail-one' for cabal-fail-one-0.1...
[1 of 1] Compiling Main             ( src/cabal-fail-one.hs, dist/build/cabal-fail-one/cabal-fail-one-tmp/Main.o )
Linking dist/build/cabal-fail-one/cabal-fail-one ...
Preprocessing test suite 'test' for cabal-fail-one-0.1...
[1 of 1] Compiling Main             ( test/test.hs, dist/build/test/test-tmp/Main.o )
Linking dist/build/test/test ...
Running 1 test suites...
Test suite test: RUNNING...
Test suite test: PASS
Test suite logged to: dist/test/cabal-fail-one-0.1-test.log
1 of 1 test suites (1 of 1 test cases) passed.
cabal haddock --executables
Running Haddock for cabal-fail-one-0.1...
Preprocessing library cabal-fail-one-0.1...
Haddock coverage:
   0% (  0 /  1) in 'Cabal.Fail.One'
Documentation created: dist/doc/html/cabal-fail-one/index.html
Preprocessing executable 'cabal-fail-one' for cabal-fail-one-0.1...
cabal: internal error when calculating transitive package dependencies.
Debug info: []
make: *** [doc] Error 1

#1085 may be a related ticket.

@relrod
Copy link
Contributor

relrod commented Nov 2, 2014

Seeing this error on one of my projects as well.

@creichert
Copy link

I can confirm this error as well with the --executable flag.

@creichert
Copy link

I've tracked this error down to the dependencyClosure function.

dependencyClosure :: PackageFixedDeps pkg

From the local documentation:

Note that if the result is @right []@ it is because at least one of the original given
'PackageIdentifier's do not occur in the index.

It seems to be a problem resolving the inplace package dependency of the local library. When I remove that dependency I am able to generate the haddocks for the executable.

Would anyone familiar with the cabal code be able to give me anymore pointers for digging into this more? I don't mind spending more time to fix this.

@taladar
Copy link

taladar commented Mar 29, 2015

Has any progress been made on this issue? We have some projects with significant code in the modules which only appear in the executable and it would be great if documentation could be generated for those as well. Of course removing the dependency on the local library is not really an option.

@edsko
Copy link
Contributor

edsko commented Jun 20, 2016

This problem still occurs with 1.24.0.0.

@alexbiehl
Copy link
Member

alexbiehl commented Oct 27, 2018 via email

@int-e
Copy link
Contributor

int-e commented Feb 14, 2019

FWIW, this bug still exists for the v1-haddock command in cabal-install 2.4.1.0. It occurs when an executable depends on the library defined in the current package.

@mietek
Copy link
Contributor

mietek commented Feb 14, 2019

My cabal-fail-one repository is now named cabal-issue-1919.

@int-e
Copy link
Contributor

int-e commented Feb 14, 2019

Note that new-haddock is affected by a different issue that also causes executable documentation to not be built in some cases (including @mietek's repository, I think): #5890.

@madgen
Copy link

madgen commented Oct 17, 2019

I get the same error when I use cabal haddock on a package with internal libraries with Cabal 2.4.1.0. Since Stack currently supports up to Cabal 2.4, I imagine this affects some number of people.

Is the only workaround to just not use internal libraries? Does anyone have an idea where to start poking to work towards a patch?

@hsenag
Copy link
Member

hsenag commented Aug 23, 2020

FYI I'm getting this on darcs 2.16.2:

$ cabal unpack darcs-2.16.2
Unpacking to darcs-2.16.2\
$ cd darcs-2.16.2
$ cabal v2-haddock test:darcs-test --enable-tests --enable-documentation --haddock-tests
[...]
Running Haddock on test suite 'darcs-test' for darcs-2.16.2..
setup.exe: internal error when calculating transitive package dependencies.
Debug info: []

I'm using cabal-install 3.2 on Windows:

cabal-install version 3.2.0.0
compiled using version 3.2.0.0 of the Cabal library

@brandon-leapyear
Copy link

brandon-leapyear commented Jun 4, 2021

This is an old work account. Please reference @brandonchinn178 for all future communication


Seems like this is still an issue? I'm surprised this issue is still open after 7 years. Is there any progress yet? Is this work blocked by another issue, or can it be worked on today?

@Mikolaj
Copy link
Member

Mikolaj commented Jun 4, 2021

I don't see any label suggesting this is blocked (e.g., on a haddock bug), so I guess any work on this would be very welcome.

I'm surprised this is still failing: I'm running haddock on projects with multiple libraries and it works for me (even if it's rather useless until this haddock work is streamlined: haskell/haddock#1379). Apparently the pattern of internal library deps matters.

@brandon-leapyear
Copy link

brandon-leapyear commented Jun 4, 2021

This is an old work account. Please reference @brandonchinn178 for all future communication


Here's an up-to-date minimal repro: https://github.com/brandonchinn178/cabal-repro-1919

@Mikolaj
Copy link
Member

Mikolaj commented Jun 4, 2021

It works for me with development version of cabal (I run cabal haddock. Which version and what commandline do you use?

@brandon-leapyear
Copy link

brandon-leapyear commented Jun 4, 2021

This is an old work account. Please reference @brandonchinn178 for all future communication


oh interesting. It fails with stack haddock. With debugging enabled, I see it failing when running

.../.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_3.2.1.0_ghc-8.10.4 --builddir=.stack-work/dist/x86_64-osx/Cabal-3.2.1.0 haddock --html --hoogle --html-location=../$pkg-$version/ --haddock-option=--hyperlinked-source --haddock-option=--quickjump

so maybe it's a GHC bug?

EDIT: never mind, this is the cabal executable built by stack

@Mikolaj
Copy link
Member

Mikolaj commented Jun 5, 2021

Could you make stack build a newer cabal executable? Preferably dev version from branch master? This one looks like 3.2 and it works fine with 3.5 for me and the invocation you show does not see particularly wild, so perhaps this was fixed already?

@brandon-leapyear
Copy link

brandon-leapyear commented Jun 5, 2021

This is an old work account. Please reference @brandonchinn178 for all future communication


Hm so I checked out the Cabal-v3.4.0.0 tag to build 3.4, and then running cabal haddock worked. But then using Cabal 3.4 with Stack still fails

$ /Users/bchinn/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_3.4.0.0_ghc-9.0.1 --builddir=.stack-work/dist/x86_64-osx/Cabal-3.4.0.0 haddock

Preprocessing library for foo-0.1.0.0..
Running Haddock on library for foo-0.1.0.0..
Haddock coverage:
   0% (  0 /  2) in 'Foo'
  Missing documentation for:
    Module header
    doThing (src/Foo.hs:3)
Documentation created:
.stack-work/dist/x86_64-osx/Cabal-3.4.0.0/doc/html/foo/index.html
Preprocessing library 'foo-internal' for foo-0.1.0.0..
Running Haddock on library 'foo-internal' for foo-0.1.0.0..
Cabal-simple_mPHDZzAJ_3.4.0.0_ghc-9.0.1: internal error when calculating
transitive package dependencies.
Debug info: []

So it's probably a Stack bug.

I believe this issue can be closed. Mostly because cabal haddock --executables seems to not be a thing anymore

@Mikolaj
Copy link
Member

Mikolaj commented Jun 5, 2021

It would still be nice to report on Stack issue tracker and perhaps improve Cabal to avoid this problem, if it's more on our side.

@brandon-leapyear
Copy link

brandon-leapyear commented Jun 5, 2021

This is an old work account. Please reference @brandonchinn178 for all future communication


It is tracked for Stack: commercialhaskell/stack#4428

But it actually might be a bug in GHC/Cabal, now that I'm digging further. Can you clone my minimal repro again (https://github.com/brandonchinn178/stack-repro-4428) and do the following:

ghc-9.0.1 -package Cabal-3.4.0.0 Setup.hs -o setup
./setup configure
./setup haddock

@brandon-leapyear
Copy link

brandon-leapyear commented Jun 5, 2021

This is an old work account. Please reference @brandonchinn178 for all future communication


Ok I think I have a better idea of what's going on.

It seems that when calling cabal haddock, the haddock function (from Distribution.Simple.Haddock) is called separately for each component (in the minimal repro, the foo library, and the foo-internal internal library), so when building the haddocks for foo-internal, the foo library is registered.

But when manually building Setup.hs and calling haddock via Cabal-the-library, the haddock function is called once for everything, so when building the haddocks for foo-internal, the foo library doesn't exist.

Technical details

cabal haddock

haddock is called first with LocalBuildInfo containing:

  • configFlags.configArgs = ["lib:foo"]
  • componentEnabledSpec = OneComponentRequestedSpec (CLibName LMainLibName)
  • installedPkgs.unitIdIndex containing:
base-4.14.1.0
ghc-prim-0.6.1
integer-gmp-1.0.3.0
rts

Then haddock is called with LocalBuildInfo containing:

  • configFlags.configArgs = ["lib:foo-internal"]
  • componentEnabledSpec = OneComponentRequestedSpec (CLibName (LSubLibName (UnqualComponentName "foo-internal")))
  • installedPkgs.unitIdIndex containing:
base-4.14.1.0
foo-0.1.0.0-inplace
ghc-prim-0.6.1
integer-gmp-1.0.3.0
rts

Setup.hs, Cabal-the-library

haddock is called once with LocalBuildInfo containing:

  • configFlag.configArgs = []
  • componentEnabledSpec = ComponentRequestedSpec {testsRequested = False, benchmarksRequested = False}
  • installedPkgs.unitIdIndex containing:
base-4.14.1.0
ghc-prim-0.6.1
integer-gmp-1.0.3.0
rts

@Mikolaj
Copy link
Member

Mikolaj commented Jun 7, 2021

Reproduced. Got setup: internal error when calculating transitive package dependencies. What does ./setup configure even do?

So it looks like cabal problem? The Setup way outdated vs the v2 way?

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

Successfully merging a pull request may close this issue.