Skip to content

Handle apparent package dependency cycles due to test suites / benchmarks #1575

Open

Description

@tibbe

Update by @ezyang: See @edsko's comment at #1575 (comment) we don't actually want to dep solver for each package individually, according to @dcoutts.

Update by @dcoutts: the latest iteration of idea 1 below is as follows:

Suppose for sake of argument we're looking at bytestring which has a test suite that uses tasty, and tasty depends indirectly on bytestring. So the original proposal was to resolve this cycle by building the under-development bytestring and then building tasty against that, and then building the bytestring testsuite against the freshly built tasty package. But actually this is crazy, it means every time I make a small edit to bytestring and want to re-run the tests, cabal has to go and rebuild tasty (and all the other deps of tasty that use bytestring). This would get really annoying really quickly. Also, we don't really want to build tasty against an in-development version of bytestring, we want tasty to use a stable version of bytestring. So much better is to have tasty be built using an existing stable bytestring. Then tasty etc does not need to be rebuilt as we make minor changes to the in-development version of bytestring.

So this requires we have a solution using two different version of bytestring. We already have something like this for dependencies of Setup scripts, which we call "independent" dependencies. So we can treat the dependencies of the test-suite /which it doesn't share with the library/ as independent. See #3422 for a partial implementation of this idea and a discussion of the difficulties.

Idea 2 below would require a different approach. In general it is important to have consistent behaviour of code in one component (e.g. exe) vs another component in the same package. This is what authors generally expect. This means that two exes both use some lib then they need to use the same version of that lib. If authors really want to allow two exes in the same package to use different versions of some dep then this ought to be explicit and we should come up with some mechanism to do so. If we go down this route then we should also consider the case of the same component using two different version of a lib. We might handle that like package qualified module imports, giving each one a different local name. This also relates to backpack.


I think we should create the install plan on a component (i.e. library, executable, test-suite, and benchmark) basis instead of creating one for the whole package.

There are two use cases I can think of:

  1. There's a growing number of packages (anything that's a dependency of either test-frame-work and its related packages or of criterion) that can't have test suite or benchmark sections, as that would create a dependency cycle.
  2. Users have requested being able to build executables (in a single package) that have conflicting dependencies.

I suggest that we treat each component as if it was a "package" with name package-x.y.z.w:component-name, for the purpose of dependency resolution.

Activity

  1. 23Skidoo commented on Nov 11, 2013

    @23Skidoo
    Member

    +1, this would be nice to have.

  2. ygale commented on Nov 28, 2013

    @ygale
    Contributor

    #1532 might be another reason this would be a good idea.

  3. kosmikus commented on Nov 28, 2013

    @kosmikus
    Contributor

    I don't think that the solver-part would be really hard. But we need to be able to build and install the components separately, otherwise this is worthless.

  4. 23Skidoo commented on Nov 29, 2013

    @23Skidoo
    Member

    But we need to be able to build and install the components separately, otherwise this is worthless.

    With 1.18, we have this for build. I think that we don't need per-component install. The use cases Johan mentions don't actually require splitting packages other than the install target (one can only depend on libraries anyway, and there's guaranteed to be only a single library per package). We only need a way to selectively enable components with configure; for tests and benchmarks we already have that with --enable-tests and --enable-benchmarks.

    So it looks to me that both use cases can be supported with no changes to the solver, only by splitting the install target into several virtual packages. Example of the first use case:

    $ cd /path/to/$pkgid
    $ cabal install --only-dependencies --enable-benchmarks --enable-tests
    # Runs 'cabal install --only-dependencies $pkgid:library $pkgid:benchmark[0..N] $pkgid:test[0..N]' under the hood
    $ cabal configure --enable-benchmarks --enable-tests
    # Succeeds, since each component is treated as a separate package
    

    For building a subset of exes something like configure --enable-component=foo,bar,baz will have to be added. Again, this will be needed only for the current target. Not sure if we want to allow installing such partially-configured packages with cabal install.

  5. ygale commented on Nov 29, 2013

    @ygale
    Contributor

    In #1541 you have a use case with two targets, A and B, with A an executable used as a preprocessor for the source code of library or executable B. A must be built and installed (or at least made accessible at some predictable path) before B is built.

  6. 23Skidoo commented on Nov 29, 2013

    @23Skidoo
    Member

    @ygale

    In #1541, all you want is to build A before B (A and B don't have conflicting dependencies). This should be possible to fix on the component graph level (since they are both a part of the same package), once there's a way to declare that B depends on A.

    #1532 seems to be unrelated.

  7. ygale commented on Nov 29, 2013

    @ygale
    Contributor

    Yes, you are correct that in our case it happens that there are no conflicting dependencies. But that is certainly possible. So this is another use case.

    Also, here you need access to the compiled executable for A before beginning to build B, so there needs to be some kind of "install" step for A before B is built. It doesn't necessarily need to be the same thing as cabal install, but the salted dist directory is not suitable.

  8. 23Skidoo commented on Nov 29, 2013

    @23Skidoo
    Member

    Also, here you need access to the compiled executable for A before beginning to build B, so there needs to be some kind of "install" step for A before B is built.

    A only needs to be in PATH. I believe that this works now since you said that that worked with 1.16.

  9. 23Skidoo commented on Apr 16, 2015

    @23Skidoo
    Member

    Related: @edsko's work on independent goals (#2531, #2530, #2515, #2514, etc.) and this comment by @kosmikus.

  10. edsko commented on Apr 16, 2015

    @edsko
    Contributor

    With my work on fine grained dependencies in the solver, the solver part of this should be relatively easy. The harder part would be to change the way the installer works.

  11. edsko commented on Apr 16, 2015

    @edsko
    Contributor

    Incidentally, the testsuite use case mentioned by @tibbe can be addressed in a simpler, if not quite as general way: we can treat the dependencies of the test-suite which it doesn't share with the library as independent. This would make it possible to have, say, a tasty testsuite for optparse-applicative even though tasty depends on optparse-applicative.

    Without changing anything else, this would mean we can then link tasty to an another (probably older) version of optparse-applicative than the one we are testing. (It would require the optparse-applicative test suite to use the src/ dir of its main library directly, rather than have an internal dependency on the optparse-applicative library).

    This is something I've previously discussed with @dcoutts and it should be quite easy to do know do (I'm not sure I'll have time left to do it though).

  12. added this to the milestone on Apr 23, 2015
  13. BardurArantsson commented on Jun 25, 2015

    @BardurArantsson
    Collaborator

    @edsko Please do what it is you do. From my experience the major irritation here is the test-suite case.

  14. 26 remaining items

  15. sebright commented on Nov 5, 2016

    @sebright
    Collaborator

    Issues describing specific examples of cyclic dependencies caused by test suites:
    #935 - containers
    #960 - text
    #3824 - bytestring

  16. phadej commented on Jun 26, 2017

    @phadej
    Collaborator

    BTW already in #3824 was mentioned that it's a blocker for 2.0;

    yet if 3.0 if the milestone where new-build is the only thing, that's a hard deadline.

    Today while going through some packages, few other occurrences:

    • unordered-containers: cannot build benchmarks (criterion in the loop)
    • aeson has a workaround: benchmarks pulled into separate package
    • integer-logarithms cannot build test-suite (quickcheck-instances -> scientific)
    • Also scientific has benchmark suite

    This is a real blocker to develop core packages using new-build.


    To return comment to the starting post:

    Suppose for sake of argument we're looking at bytestring which has a test suite that uses tasty, and tasty depends indirectly on bytestring. So the original proposal was to resolve this cycle by building the under-development bytestring and then building tasty against that, and then building the bytestring testsuite against the freshly built tasty package. But actually this is crazy, it means every time I make a small edit to bytestring and want to re-run the tests, cabal has to go and rebuild tasty

    I'd prefer to rebuild the tasty each time. Because currently in some packages' Travis scripts we do

    cabal install  --disable-tests --disable-benchmarks
    cabal install test-framework criterion ...
    cabal configure --enable-tests --enable-benchmarks
    cabal test

    E.g. hashable: https://github.com/tibbe/hashable/blob/339ae0ad3250c4d6b703e2fc781ce81a190c8d23/.travis.yml#L121

    That workaround is impossible with new-build.

    Fancier solution using multiple package versions would be cool, but this issue have been open for almost 4 years. I don't need the perfect solution, I'm quite ok with some solution.

  17. sebright commented on Jun 27, 2017

    @sebright
    Collaborator

    I'd prefer to rebuild the tasty each time.

    That makes sense. The only downside I can think of is that projects might start relying on cyclic dependencies between packages, and then it might be harder to switch to the more limited, two-version solution later.

  18. phadej commented on Jun 27, 2017

    @phadej
    Collaborator

    @GrayJay I'm not sure I personally even want two version solution. All the cases mentioned in your #1575 (comment) and my #1575 (comment) are "core" packages, which are (possibly transitive) dependencies of criterion, tasty or test-framework.

    It would be completely OK for me to explicitly toggle the switch to allow such "loop" (no name idea atm, but some flag to new-build)

  19. chris-martin commented on Oct 19, 2017

    @chris-martin

    Sorry I'm about to ask some dumb question here, but I've been reading a lot of discussion on this issue dating back many years, and -- I'm very confused about the state of this bug, so I'm just hoping to understand where we are with it, to figure out whether there's hope of ever testing my projects with Cabal.

    • Do I understand correctly that if my project has three units foo:test -> bar:lib -> foo:lib (with dependency relationships indicated by the arrows), Cabal will always fail to build this project?
    • Is this working in any existing Cabal releases?
    • Is there any plan to make it work in any future Cabal releases?
    • Stack can build a project like this - I understand that Stack uses Cabal under the hood, so how is that possible?
  20. sebright commented on Oct 22, 2017

    @sebright
    Collaborator

    Do I understand correctly that if my project has three units foo:test -> bar:lib -> foo:lib (with
    dependency relationships indicated by the arrows), Cabal will always fail to build this project?

    Is this working in any existing Cabal releases?

    cabal can't build the tests in one step, but it is possible to install foo, install bar, and then build foo with tests enabled. cabal new-build can't build the tests, though, because it can't install packages in one step and then use the installed packages as inputs when calculating the next install plan.

    Is there any plan to make it work in any future Cabal releases?

    Yes, though there are two possible solutions. #4087 would allow install plans to have cycles between packages, but no cycles between components. #3422 would allow install plans to use two versions of the library to break a cycle when building test suites and benchmarks.

    Stack can build a project like this - I understand that Stack uses Cabal under the hood, so how is that possible?

    I think that stack builds the packages in multiple steps.

  21. added a commit that references this issue on Mar 20, 2018
  22. sebright commented on Jun 11, 2018

    @sebright
    Collaborator

    See #5200 for an example of a project where cabal would need to use consistent versions for the library used by the test suite helper and the library under test.

  23. sebright commented on Oct 29, 2018

    @sebright
    Collaborator

    See #5645 for more discussion of this issue.

  24. parsonsmatt commented on Apr 6, 2019

    @parsonsmatt
    Collaborator

    This issue is blocking the use of cabal new-* on the persistent repository.

  25. hvr commented on Apr 7, 2019

    @hvr
    Member

    This issue is blocking the use of cabal new-* on the persistent repository.

    Not for me and I wasn't able to confirm your claim. I performed the following steps:

    # clone repo
    cabal get -s persistent && persistent
    # translate `stack.yaml` into `cabal.project`
    cat > cabal.project <<EOF
    tests: true
    packages:
        ./persistent
        ./persistent-template
        ./persistent-sqlite
        ./persistent-test
        ./persistent-mongoDB
        ./persistent-mysql
        ./persistent-postgresql
        ./persistent-redis
        ./persistent-qq
    EOF
    
    # try to run the testsuites
    cabal test all
    
    # ERROR: When using configuration(s) from cabal.project, the following errors occurred: The package directory './persistent-qq' does not contain any .cabal file
    
    # curse about unnecessarily cabal-hostile use of trivial package.yaml  in the repo; get `hpack` executable from somewhere, and then finally use `hpack` to convert into proper .cabal file:
    hpack persistent-qq/package.yaml
    
    # try to build & run the testsuite a 2nd time
    $ cabal v2-test all 
    Build profile: -w ghc-8.4.4 -O1
    In order, the following will be built (use -v for more details):
     - persistent-2.9.2 (lib) (first run)
     - persistent-2.9.2 (test:test) (first run)
     - persistent-template-2.6.0 (lib) (first run)
     - persistent-sqlite-2.9.3 (lib) (first run)
     - persistent-redis-2.5.2.2 (lib) (first run)
     - persistent-template-2.6.0 (test:test) (first run)
     - persistent-sqlite-2.9.3 (test:test) (first run)
     - persistent-redis-2.5.2.2 (test:basic) (first run)
    Configuring library for persistent-2.9.2..
    Configuring test suite 'test' for persistent-2.9.2..
    Preprocessing library for persistent-2.9.2..
    Building library for persistent-2.9.2..
    ...
    Preprocessing test suite 'test' for persistent-2.9.2..
    Building test suite 'test' for persistent-2.9.2..
    Running 1 test suites...
    Test suite test: RUNNING...
    Test suite test: PASS
    Test suite logged to:
    /tmp/persistent/dist-newstyle/build/x86_64-linux/ghc-8.4.4/persistent-2.9.2/t/test/test/persistent-2.9.2-test.log
    1 of 1 test suites (1 of 1 test cases) passed.
    Preprocessing test suite 'basic' for persistent-redis-2.5.2.2..
    Building test suite 'basic' for persistent-redis-2.5.2.2..
    Running 1 test suites...
    Test suite basic: RUNNING...
    "Inserting..."
    basic: Network.Socket.connect: <socket: 3>: does not exist (Connection refused)
    Test suite basic: FAIL
    Test suite logged to:
    /tmp/persistent/dist-newstyle/build/x86_64-linux/ghc-8.4.4/persistent-redis-2.5.2.2/t/basic/test/persistent-redis-2.5.2.2-basic.log
    0 of 1 test suites (0 of 1 test cases) passed.
    cabal: Tests failed for test:basic from persistent-redis-2.5.2.2.

    So for me the lack of a cabal.project-equivalent to the stack.yaml file combined with the gratuitous use of hpack in one of the 9 local packages was blocking the use of cabal new-build with persistent's repo to be working out of the box; but other than the use of non-standard file formats I didn't notice any problems.

  26. parsonsmatt commented on Apr 8, 2019

    @parsonsmatt
    Collaborator

    @hvr The issue is occurring in this branch which introduces a pseudocircular dependency. The failure occurred after writing an appropriate cabal.project file and using hpack to generate the cabal file.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions