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

Equivalent of Cabal's preRepl, replHook, postRepl hooks for stack ghci #4315

Open
deech opened this issue Sep 22, 2018 · 10 comments
Open

Equivalent of Cabal's preRepl, replHook, postRepl hooks for stack ghci #4315

deech opened this issue Sep 22, 2018 · 10 comments

Comments

@deech
Copy link
Contributor

deech commented Sep 22, 2018

Steps to reproduce

  1. Create a Stack project stack new Foo.
  2. Add the following to Setup.hs:
import Distribution.Simple
main = defaultMain simpleUserHooks
 {
   preRepl = myPreRepl
 }

myPreRepl :: Args -> ReplFlags -> IO HookedBuildInfo
myPreRepl args replFlags = do
  putStrln "here!!!"
  (preRepl simpleUserHooks) args replFlags
  1. Run the repl: stack repl

Expected

"here!!!" on the console.

Actual

ghci loads but there is no output.

Stack version

$ stack --version
Version 1.7.1, Git revision 681c800873816c022739ca7ed14755e85a579565 (5807 commits) x86_64 hpack-0.28.2

Method of installation

  • Official binary, downloaded from stackage.org or fpcomplete's package repository
@deech deech changed the title Cabal's preRepl hook is not runj Cabal's preRepl hook is not run Sep 22, 2018
@deech
Copy link
Contributor Author

deech commented Sep 22, 2018

replHook and postRepl aren't run either.

@dbaynard
Copy link
Contributor

Hello @deech. stack new by default uses build-type: Simple which (I believe) ignores any Setup.hs. Have you tried adding build-type: Custom to the cabal or hpack file?

@deech
Copy link
Contributor Author

deech commented Sep 22, 2018

I changed it to build-type: Custom and it still does the same thing. Good thought!

@dbaynard
Copy link
Contributor

Hmm, that worked for me. I say worked, I got errors from the custom setup file. Did you run with --reconfigure?

If that didn't work, please post your stack.yaml and the output of stack -v repl --reconfigure.

@deech
Copy link
Contributor Author

deech commented Sep 22, 2018

Yes I got errors as well due to unimported modules and I fixed it:

import Distribution.Simple
import Distribution.Simple.Setup (ReplFlags)
import Distribution.PackageDescription
import Distribution.Simple.LocalBuildInfo
main = defaultMainWithHooks simpleUserHooks
 {
   preRepl = myPreRepl,
   replHook = myReplHook
 }

myPreRepl :: Args -> ReplFlags -> IO HookedBuildInfo
myPreRepl args replFlags = do
  putStrLn "here!!!"
  (preRepl simpleUserHooks) args replFlags

myReplHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> ReplFlags -> [String] -> IO ()
myReplHook pd lbi uh rf ss = do
  putStrLn "here!!!"
  (replHook simpleUserHooks) pd lbi uh rf ss

But I'm still not seeing "here!!!" outputted to the console as I expect.

@dbaynard
Copy link
Contributor

Hmm. Post the stack.yaml and the verbose output and I'll take a look tomorrow.

@deech
Copy link
Contributor Author

deech commented Sep 22, 2018

stack.yaml:

resolver: lts-12.10
packages:
- .

Output of stack -v repl --reconfigure:

$ stack -v repl --reconfigure
Version 1.7.1, Git revision 681c800873816c022739ca7ed14755e85a579565 (5807 commits) x86_64 hpack-0.28.2
2018-09-22 18:52:36.418946: [debug] Checking for project config at: /tmp/Testprerepl/stack.yaml
@(src/Stack/Config.hs:850:9)
2018-09-22 18:52:36.419113: [debug] Loading project config file stack.yaml
@(src/Stack/Config.hs:876:13)
2018-09-22 18:52:36.420111: [debug] Decoding build plan from: /home/deech/.stack/build-plan/lts-12.10.yaml
@(src/Stack/Snapshot.hs:164:5)
2018-09-22 18:52:36.420172: [debug] Trying to decode /home/deech/.stack/build-plan-cache/lts-12.10.cache
@(src/Stack/Snapshot.hs:156:32)
2018-09-22 18:52:36.425100: [debug] Success decoding /home/deech/.stack/build-plan-cache/lts-12.10.cache
@(src/Stack/Snapshot.hs:156:32)
2018-09-22 18:52:36.425355: [debug] Run process: /sbin/ldconfig -p
@(src/Stack/Setup.hs:580:22)
2018-09-22 18:52:36.427979: [debug] Process finished in 3ms: /sbin/ldconfig -p
@(src/Stack/Setup.hs:580:22)
2018-09-22 18:52:36.429228: [debug] Did not find shared library libtinfo.so.5
@(src/Stack/Setup.hs:603:38)
2018-09-22 18:52:36.429369: [debug] Found shared library libtinfo.so.6 in /usr/lib
@(src/Stack/Setup.hs:602:38)
2018-09-22 18:52:36.429427: [debug] Found shared library libncursesw.so.6 in 'ldconfig -p' output
@(src/Stack/Setup.hs:589:29)
2018-09-22 18:52:36.429542: [debug] Found shared library libgmp.so.10 in 'ldconfig -p' output
@(src/Stack/Setup.hs:589:29)
2018-09-22 18:52:36.429620: [debug] Did not find shared library libgmp.so.3
@(src/Stack/Setup.hs:603:38)
2018-09-22 18:52:36.429649: [debug] Potential GHC builds: tinfo6, ncurses6
@(src/Stack/Setup.hs:632:9)
2018-09-22 18:52:36.429702: [debug] Found already installed GHC builds: tinfo6
@(src/Stack/Setup.hs:458:13)
2018-09-22 18:52:36.429935: [debug] Getting global package database location
@(src/Stack/GhcPkg.hs:47:5)
2018-09-22 18:52:36.430046: [debug] Getting Cabal package version
@(src/Stack/GhcPkg.hs:180:5)
2018-09-22 18:52:36.430091: [debug] Run process: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --no-user-package-db list --global
@(src/Stack/GhcPkg.hs:76:10)
2018-09-22 18:52:36.430545: [debug] Asking GHC for its version
@(src/Stack/Setup/Installed.hs:98:13)
2018-09-22 18:52:36.430711: [debug] Run process: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --no-user-package-db field --simple-output Cabal version
@(src/Stack/GhcPkg.hs:76:10)
2018-09-22 18:52:36.431036: [debug] Run process: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc --numeric-version
@(src/Stack/Setup/Installed.hs:99:19)
2018-09-22 18:52:36.465416: [debug] Process finished in 35ms: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --no-user-package-db field --simple-output Cabal version
@(src/Stack/GhcPkg.hs:76:10)
2018-09-22 18:52:36.465757: [debug] Process finished in 36ms: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --no-user-package-db list --global
@(src/Stack/GhcPkg.hs:76:10)
2018-09-22 18:52:36.466330: [debug] Process finished in 35ms: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc --numeric-version
@(src/Stack/Setup/Installed.hs:99:19)
2018-09-22 18:52:36.466397: [debug] GHC version is: ghc-8.4.3
@(src/Stack/Setup/Installed.hs:102:13)
2018-09-22 18:52:36.466464: [debug] Resolving package entries
@(src/Stack/Setup.hs:256:5)
2018-09-22 18:52:36.466568: [debug] Trying to decode /home/deech/.stack/loaded-snapshot-cache/x86_64-linux/ghc-8.4.3/lts-12.10.cache
@(src/Stack/Snapshot.hs:384:9)
2018-09-22 18:52:36.499209: [debug] Success decoding /home/deech/.stack/loaded-snapshot-cache/x86_64-linux/ghc-8.4.3/lts-12.10.cache
@(src/Stack/Snapshot.hs:384:9)
2018-09-22 18:52:36.500441: [debug] Starting to execute command inside EnvConfig
@(src/Stack/Runners.hs:171:18)
2018-09-22 18:52:36.500572: [debug] Parsing the targets
@(src/Stack/Build/Target.hs:460:3)
2018-09-22 18:52:36.500713: [debug] Running hpack on /tmp/Testprerepl/package.yaml
@(src/Stack/Package.hs:1390:9)
2018-09-22 18:52:36.503122: [debug] hpack output unchanged in /tmp/Testprerepl/Testprerepl.cabal
@(src/Stack/Package.hs:1407:46)
2018-09-22 18:52:36.519673: [debug] Start: getPackageFiles /tmp/Testprerepl/Testprerepl.cabal
@(src/Stack/Package.hs:332:21)
2018-09-22 18:52:36.522161: [debug] Finished in 2ms: getPackageFiles /tmp/Testprerepl/Testprerepl.cabal
@(src/Stack/Package.hs:332:21)
2018-09-22 18:52:36.523307: [debug] Parsing the targets
@(src/Stack/Build/Target.hs:460:3)
2018-09-22 18:52:36.539203: [debug] Parsing the targets
@(src/Stack/Build/Target.hs:460:3)
2018-09-22 18:52:36.555252: [debug] Start: getPackageFiles /tmp/Testprerepl/Testprerepl.cabal
@(src/Stack/Package.hs:332:21)
2018-09-22 18:52:36.557349: [debug] Finished in 2ms: getPackageFiles /tmp/Testprerepl/Testprerepl.cabal
@(src/Stack/Package.hs:332:21)
2018-09-22 18:52:36.558254: [debug] Finding out which packages are already installed
@(src/Stack/Build/Installed.hs:57:5)
2018-09-22 18:52:36.558410: [debug] Run process: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --global --no-user-package-db dump --expand-pkgroot
@(src/Stack/Prelude.hs:117:3)
2018-09-22 18:52:36.594444: [debug] Process finished in 36ms: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --global --no-user-package-db dump --expand-pkgroot
@(src/Stack/Prelude.hs:117:3)
2018-09-22 18:52:36.594966: [debug] Ignoring package stm due to wanting version 2.4.5.1 instead of 2.4.5.0
@(src/Stack/Build/Installed.hs:185:5)
2018-09-22 18:52:36.595199: [debug] Ignoring package haskeline due to wanting version 0.7.4.3 instead of 0.7.4.2
@(src/Stack/Build/Installed.hs:185:5)
2018-09-22 18:52:36.595498: [debug] Run process: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --user --no-user-package-db --package-db /home/deech/.stack/snapshots/x86_64-linux-tinfo6/lts-12.10/8.4.3/pkgdb dump --expand-pkgroot
@(src/Stack/Prelude.hs:117:3)
2018-09-22 18:52:36.618427: [debug] Process finished in 23ms: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --user --no-user-package-db --package-db /home/deech/.stack/snapshots/x86_64-linux-tinfo6/lts-12.10/8.4.3/pkgdb dump --expand-pkgroot
@(src/Stack/Prelude.hs:117:3)
2018-09-22 18:52:36.618561: [debug] Run process: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --user --no-user-package-db --package-db /tmp/Testprerepl/.stack-work/install/x86_64-linux-tinfo6/lts-12.10/8.4.3/pkgdb dump --expand-pkgroot
@(src/Stack/Prelude.hs:117:3)
2018-09-22 18:52:36.641763: [debug] Process finished in 23ms: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --user --no-user-package-db --package-db /tmp/Testprerepl/.stack-work/install/x86_64-linux-tinfo6/lts-12.10/8.4.3/pkgdb dump --expand-pkgroot
@(src/Stack/Prelude.hs:117:3)
2018-09-22 18:52:36.642235: [debug] Constructing the build plan
@(src/Stack/Build/ConstructPlan.hs:186:5)
2018-09-22 18:52:36.643526: [debug] Checking if we are going to build multiple executables with the same name
@(src/Stack/Build.hs:177:5)
2018-09-22 18:52:36.643636: [debug] Executing the build plan
@(src/Stack/Build/Execute.hs:491:5)
2018-09-22 18:52:36.644243: [debug] Getting global package database location
@(src/Stack/GhcPkg.hs:47:5)
2018-09-22 18:52:36.644358: [debug] Run process: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --no-user-package-db list --global
@(src/Stack/GhcPkg.hs:76:10)
2018-09-22 18:52:36.667212: [debug] Process finished in 23ms: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --no-user-package-db list --global
@(src/Stack/GhcPkg.hs:76:10)
2018-09-22 18:52:36.667630: [debug] Finding out which packages are already installed
@(src/Stack/Build/Installed.hs:57:5)
2018-09-22 18:52:36.667718: [debug] Run process: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --global --no-user-package-db dump --expand-pkgroot
@(src/Stack/Prelude.hs:117:3)
2018-09-22 18:52:36.700571: [debug] Process finished in 33ms: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --global --no-user-package-db dump --expand-pkgroot
@(src/Stack/Prelude.hs:117:3)
2018-09-22 18:52:36.700798: [debug] Ignoring package stm due to wanting version 2.4.5.1 instead of 2.4.5.0
@(src/Stack/Build/Installed.hs:185:5)
2018-09-22 18:52:36.701126: [debug] Ignoring package haskeline due to wanting version 0.7.4.3 instead of 0.7.4.2
@(src/Stack/Build/Installed.hs:185:5)
2018-09-22 18:52:36.701304: [debug] Run process: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --user --no-user-package-db --package-db /home/deech/.stack/snapshots/x86_64-linux-tinfo6/lts-12.10/8.4.3/pkgdb dump --expand-pkgroot
@(src/Stack/Prelude.hs:117:3)
2018-09-22 18:52:36.725269: [debug] Process finished in 24ms: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --user --no-user-package-db --package-db /home/deech/.stack/snapshots/x86_64-linux-tinfo6/lts-12.10/8.4.3/pkgdb dump --expand-pkgroot
@(src/Stack/Prelude.hs:117:3)
2018-09-22 18:52:36.725418: [debug] Run process: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --user --no-user-package-db --package-db /tmp/Testprerepl/.stack-work/install/x86_64-linux-tinfo6/lts-12.10/8.4.3/pkgdb dump --expand-pkgroot
@(src/Stack/Prelude.hs:117:3)
2018-09-22 18:52:36.748235: [debug] Process finished in 23ms: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc-pkg --user --no-user-package-db --package-db /tmp/Testprerepl/.stack-work/install/x86_64-linux-tinfo6/lts-12.10/8.4.3/pkgdb dump --expand-pkgroot
@(src/Stack/Prelude.hs:117:3)
2018-09-22 18:52:36.748536: [debug] Start: getPackageFiles /tmp/Testprerepl/Testprerepl.cabal
@(src/Stack/Package.hs:332:21)
2018-09-22 18:52:36.750506: [debug] Finished in 2ms: getPackageFiles /tmp/Testprerepl/Testprerepl.cabal
@(src/Stack/Package.hs:332:21)
2018-09-22 18:52:36.750904: [warn] The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
@(src/Stack/Ghci.hs:359:9)
2018-09-22 18:52:36.750954: [info] Configuring GHCi with the following packages: Testprerepl
@(src/Stack/Ghci.hs:366:5)
2018-09-22 18:52:36.751235: [debug] Run process: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc --version
@(src/Stack/Ghci.hs:878:3)
2018-09-22 18:52:36.783286: [debug] Process finished in 32ms: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc --version
@(src/Stack/Ghci.hs:878:3)
2018-09-22 18:52:36.783439: [info] Using main module: 1. Package `Testprerepl' component exe:Testprerepl-exe with main-is file: /tmp/Testprerepl/app/Main.hs
@(src/Stack/Ghci.hs:488:28)
2018-09-22 18:52:36.783601: [debug] Run process: /home/deech/.stack/programs/x86_64-linux/ghc-tinfo6-8.4.3/bin/ghc --interactive -i -odir=/tmp/Testprerepl/.stack-work/odir -hidir=/tmp/Testprerepl/.stack-work/odir -hide-all-packages -i/tmp/Testprerepl/.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build -i/tmp/Testprerepl/src -i/tmp/Testprerepl/.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/autogen -i/tmp/Testprerepl/.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/global-autogen -stubdir=/tmp/Testprerepl/.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build -package-id=base-4.11.1.0 -i/tmp/Testprerepl/.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Testprerepl-exe -i/tmp/Testprerepl/app -i/tmp/Testprerepl/.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Testprerepl-exe/autogen -i/tmp/Testprerepl/.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Testprerepl-exe/Testprerepl-exe-tmp -rtsopts -with-rtsopts=-N -optP-include -optP/tmp/haskell-stack-ghci/eef63bdc/cabal_macros.h -ghci-script=/tmp/haskell-stack-ghci/ae4aed51/ghci-script
@(src/RIO/Process.hs:479:5)
GHCi, version 8.4.3: http://www.haskell.org/ghc/  :? for help
[1 of 2] Compiling Lib              ( /tmp/Testprerepl/src/Lib.hs, interpreted )
[2 of 2] Compiling Main             ( /tmp/Testprerepl/app/Main.hs, interpreted )
Ok, two modules loaded.
Loaded GHCi configuration from /tmp/haskell-stack-ghci/ae4aed51/ghci-script
*Main Lib> 

@mgsloan
Copy link
Contributor

mgsloan commented Sep 24, 2018

Yep, stack repl does not use cabal's repl mechanism, and instead uses its own implementation of ghci invocation. It does not invoke the hook. It would be nice to support cabal hooks, but I do not know of a straightforward way of doing so. Related discussions can be found at

@deech
Copy link
Contributor Author

deech commented Sep 24, 2018

Is there any way to perform some action before repl runs? In my case I'd like to set LIBRARY_PATH to a location known to Cabal.

@dbaynard
Copy link
Contributor

What's the actual code you wanted to run in the Setup.hs file?

@mpilgrem mpilgrem changed the title Cabal's preRepl hook is not run Equivalent of Cabal's preRepl, replHook, postRepl hooks for stack ghci Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants