-
Notifications
You must be signed in to change notification settings - Fork 715
Add --with-repl flag to modify program the "repl" starts with #10996
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
Open
mpickering
wants to merge
1
commit into
master
Choose a base branch
from
wip/for-repl
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module ModuleA where | ||
|
||
x :: Int | ||
x = 42 |
9 changes: 9 additions & 0 deletions
9
cabal-testsuite/PackageTests/WithRepl/SimpleTests/cabal-with-repl.cabal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cabal-version: 2.4 | ||
name: cabal-with-repl | ||
version: 0.1.0.0 | ||
build-type: Simple | ||
|
||
library | ||
exposed-modules: ModuleA | ||
build-depends: base | ||
default-language: Haskell2010 |
19 changes: 19 additions & 0 deletions
19
cabal-testsuite/PackageTests/WithRepl/SimpleTests/cabal.test.hs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Test.Cabal.Prelude | ||
import System.Directory (getCurrentDirectory) | ||
import System.FilePath ((</>)) | ||
|
||
main = do | ||
-- Test that --with-repl works with a valid GHC path | ||
cabalTest' "with-repl-valid-path" $ do | ||
cabal' "clean" [] | ||
-- Get the path to the system GHC | ||
ghc_prog <- requireProgramM ghcProgram | ||
res <- cabalWithStdin "v2-repl" ["--with-repl=" ++ programPath ghc_prog] "" | ||
assertOutputContains "Ok, one module loaded." res | ||
assertOutputContains "GHCi, version" res | ||
|
||
-- Test that --with-repl fails with an invalid path | ||
cabalTest' "with-repl-invalid-path" $ do | ||
cabal' "clean" [] | ||
res <- fails $ cabalWithStdin "v2-repl" ["--with-repl=/nonexistent/path/to/ghc"] "" | ||
assertOutputContains "does not exist" res |
10 changes: 10 additions & 0 deletions
10
cabal-testsuite/PackageTests/WithRepl/SimpleTests/cabal.with-repl-invalid-path.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# cabal clean | ||
# cabal v2-repl | ||
Resolving dependencies... | ||
Build profile: -w ghc-<GHCVER> -O1 | ||
In order, the following will be built: | ||
- cabal-with-repl-0.1.0.0 (interactive) (lib) (first run) | ||
Configuring library for cabal-with-repl-0.1.0.0... | ||
Preprocessing library for cabal-with-repl-0.1.0.0... | ||
Error: [Cabal-7125] | ||
repl failed for cabal-with-repl-0.1.0.0-inplace. |
8 changes: 8 additions & 0 deletions
8
cabal-testsuite/PackageTests/WithRepl/SimpleTests/cabal.with-repl-valid-path.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# cabal clean | ||
# cabal v2-repl | ||
Resolving dependencies... | ||
Build profile: -w ghc-<GHCVER> -O1 | ||
In order, the following will be built: | ||
- cabal-with-repl-0.1.0.0 (interactive) (lib) (first run) | ||
Configuring library for cabal-with-repl-0.1.0.0... | ||
Preprocessing library for cabal-with-repl-0.1.0.0... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import ModuleA | ||
|
||
main :: IO () | ||
main = print $ "My specific executable" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Main where | ||
|
||
main = print "My other executable" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module ModuleA where | ||
|
||
add :: Num a => a -> a -> a | ||
add x y = x + y |
14 changes: 14 additions & 0 deletions
14
cabal-testsuite/PackageTests/WithRepl/WithExe/cabal-with-repl-exe.cabal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
cabal-version: 2.4 | ||
name: cabal-with-repl-exe | ||
version: 0.1.0.0 | ||
build-type: Simple | ||
|
||
executable test-exe | ||
main-is: Main.hs | ||
build-depends: base | ||
default-language: Haskell2010 | ||
|
||
executable test-exe2 | ||
main-is: Main2.hs | ||
build-depends: base | ||
default-language: Haskell2010 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
packages: . |
32 changes: 32 additions & 0 deletions
32
cabal-testsuite/PackageTests/WithRepl/WithExe/cabal.test.hs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
import Distribution.Simple.Program | ||
import Distribution.Simple.Program.GHC | ||
import Distribution.Simple.Utils | ||
import Test.Cabal.Prelude | ||
|
||
-- On windows this test passed but then fails in CI with | ||
-- | ||
-- D:\a\_temp\cabal-testsuite-12064\cabal-multi.dist\work\.\dist\multi-out-63884\paths\cabal-with-repl-exe-0.1.0.0-inplace-test-exe: removeDirectoryRecursive:removeContentsRecursive:removePathRecursive:removeContentsRecursive:removePathRecursive:DeleteFile "\\\\?\\D:\\a\\_temp\\cabal-testsuite-12064\\cabal-multi.dist\\work\\dist\\multi-out-63884\\paths\\cabal-with-repl-exe-0.1.0.0-inplace-test-exe": permission denied (The process cannot access the file because it is being used by another process.) | ||
-- | ||
|
||
main = do | ||
mkTest "normal-repl" $ \exePath -> do | ||
-- Try using the executable with --with-repl | ||
res <- cabalWithStdin "v2-repl" ["--with-repl=" ++ exePath, "test-exe"] "" | ||
assertOutputContains "My specific executable" res | ||
mkTest "multi-repl" $ \exePath -> do | ||
requireGhcSupportsMultiRepl | ||
res <- cabalWithStdin "v2-repl" ["--enable-multi-repl", "--with-repl=" ++ exePath, "all"] "" | ||
assertOutputContains "My specific executable" res | ||
|
||
|
||
mkTest name act = do | ||
skipIfCIAndWindows 11026 | ||
cabalTest' name $ recordMode DoNotRecord $ do | ||
-- Build the executable | ||
cabal' "v2-build" ["test-exe"] | ||
-- Get the path to the built executable | ||
withPlan $ do | ||
exePath <- planExePath "cabal-with-repl-exe" "test-exe" | ||
act exePath | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
synopsis: Add --with-repl flag to specify alternative REPL program | ||
packages: [cabal-install, Cabal] | ||
prs: [10996] | ||
issues: [9115] | ||
--- | ||
|
||
Added a new `--with-repl` command-line option that allows specifying an alternative | ||
program to use when starting a REPL session, instead of the default GHC. | ||
|
||
This is particularly useful for tools like `doctest` and `hie-bios` that need to | ||
intercept the REPL session to perform their own operations. Previously, these tools | ||
had to use `--with-ghc` which required them to proxy all GHC invocations, including | ||
dependency compilation, making the implementation more complex. | ||
|
||
The `--with-repl` option only affects the final REPL invocation, simplifying the | ||
implementation of such wrapper tools. | ||
|
||
Example usage: | ||
```bash | ||
cabal repl --with-repl=doctest | ||
cabal repl --with-repl=/path/to/custom/ghc | ||
``` | ||
|
||
This change also removes the special handling for response files with `--interactive` | ||
mode, as tools are now expected to handle response files appropriately. | ||
geekosaur marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.