Skip to content

Mutually-dependent packages don't play nicely with stack ghci #3295

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

Closed
DaveCTurner opened this issue Jul 27, 2017 · 1 comment
Closed

Mutually-dependent packages don't play nicely with stack ghci #3295

DaveCTurner opened this issue Jul 27, 2017 · 1 comment

Comments

@DaveCTurner
Copy link
Contributor

#2583 (comment) indicates that you're allowed to have two packages, pkg-a and pkg-b that form a dependency cycle in the sense that pkg-a:test depends on pkg-b:lib which depends on pkg-a:lib. However this doesn't seem to play nicely with stack ghci:

mkdir -p pkg-a pkg-b

cat <<EOF >./stack.yaml
resolver: lts-8.13
packages:
  - 'pkg-a'
  - 'pkg-b'
EOF

cat <<EOF >./pkg-a/pkg-a.cabal
name:                pkg-a
version:             0.1.0.0
license:             BSD3
build-type:          Simple
cabal-version:       >=1.10

library
  exposed-modules:     LibA
  build-depends:       base >= 4.7 && < 5
  default-language:    Haskell2010

test-suite pkg-a-test
  type:                exitcode-stdio-1.0
  main-is:             Spec.hs
  build-depends:       base
                     , pkg-b
  default-language:    Haskell2010
EOF

cat <<EOF >./pkg-a/Setup.hs
import Distribution.Simple
main = defaultMain
EOF

cat <<EOF >./pkg-a/LibA.hs
module LibA where

funcA :: Int -> Int
funcA = (+7)
EOF

cat <<EOF >./pkg-b/pkg-b.cabal
name:                pkg-b
version:             0.1.0.0
license:             BSD3
build-type:          Simple
cabal-version:       >=1.10

library
  exposed-modules:     LibB
  build-depends:       base >= 4.7 && < 5
    , pkg-a
  default-language:    Haskell2010
EOF

cat <<EOF >./pkg-b/LibB.hs
module LibB where

import LibA

funcB :: Int -> Int
funcB = (*4) . funcA
EOF

cat <<EOF >./pkg-b/Setup.hs
import Distribution.Simple
main = defaultMain
EOF

cat <<EOF >./pkg-a/Spec.hs
import LibB

main :: IO ()
main = if funcB 7 == 56 then return () else undefined
EOF

stack ghci pkg-a/Spec.hs

Output:

Using configuration for pkg-a:test:pkg-a-test to load /home/linuxadmin/stack-dep-cycle/repro/pkg-a/Spec.hs
pkg-a-0.1.0.0: configure (lib)
Configuring pkg-a-0.1.0.0...
pkg-a-0.1.0.0: initial-build-steps (lib)
Configuring GHCi with the following packages: pkg-a
Using main module: 1. Package `pkg-a' component test:pkg-a-test with main-is file: ../pkg-a/Spec.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
<command line>: cannot satisfy -package pkg-b-0.1.0.0
    (use -v for more information)

If pkg-b is built (via stack build pkg-b) then stack ghci pkg-a/Spec.hs outputs:

$ stack ghci pkg-a/Spec.hs
Using configuration for pkg-a:test:pkg-a-test to load /home/linuxadmin/stack-dep-cycle/repro/pkg-a/Spec.hs
Configuring GHCi with the following packages: pkg-a
Using main module: 1. Package `pkg-a' component test:pkg-a-test with main-is file: /home/linuxadmin/stack-dep-cycle/repro/pkg-a/Spec.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( /home/linuxadmin/stack-dep-cycle/repro/pkg-a/Spec.hs, interpreted )
Ok, modules loaded: Main.
Loaded GHCi configuration from /tmp/ghci31095/ghci-script
*Main>

I think it should do this without having to build pkg-b first.

@mpilgrem
Copy link
Member

mpilgrem commented Apr 1, 2024

I am closing this issue given the passage of time and because I could not reproduce the issue with Stack 2.15.5. With a two-package project ('package-A', 'package-B') where the test suite of package-A depends on the library of package-B and the library of package-B depends on the library of package-A: (1) stack build worked as expected and (2) stack ghci package-A/test/Spec.hs worked as expected.

@mpilgrem mpilgrem closed this as completed Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants