Skip to content

Commit fa38169

Browse files
committed
Remove target string manipulation
1 parent 9da6cf3 commit fa38169

File tree

3 files changed

+11
-33
lines changed

3 files changed

+11
-33
lines changed

cabal-install/src/Distribution/Client/CmdRepl.hs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ import Distribution.Utils.Generic
155155
import Distribution.Verbosity
156156
( lessVerbose
157157
, normal
158-
, silent
159158
)
160159
import Language.Haskell.Extension
161160
( Language (..)
@@ -287,22 +286,7 @@ multiReplDecision ctx compiler flags =
287286
-- For more details on how this works, see the module
288287
-- "Distribution.Client.ProjectOrchestration"
289288
replAction :: NixStyleFlags ReplFlags -> [String] -> GlobalFlags -> IO ()
290-
replAction flags@NixStyleFlags{extraFlags = replFlags@ReplFlags{..}, configFlags} targetStrings' globalFlags = do
291-
-- NOTE: The REPL will work with no targets in the context of a project if a
292-
-- single package is in the same directory as the project file. To have the
293-
-- same behaviour when the package is somewhere else we adjust the targets.
294-
targetStrings <-
295-
if null targetStrings'
296-
then withCtx silent targetStrings' $ \targetCtx ctx _ ->
297-
return . fromMaybe [] $ case targetCtx of
298-
ProjectContext ->
299-
let pkgs = projectPackages $ projectConfig ctx
300-
in if length pkgs == 1
301-
then pure <$> listToMaybe pkgs
302-
else Nothing
303-
_ -> Nothing
304-
else return targetStrings'
305-
289+
replAction flags@NixStyleFlags{extraFlags = replFlags@ReplFlags{..}, configFlags} targetStrings globalFlags = do
306290
withCtx verbosity targetStrings $ \targetCtx ctx targetSelectors -> do
307291
when (buildSettingOnlyDeps (buildSettings ctx)) $
308292
dieWithException verbosity ReplCommandDoesn'tSupport
@@ -312,7 +296,7 @@ replAction flags@NixStyleFlags{extraFlags = replFlags@ReplFlags{..}, configFlags
312296
baseCtx <- case targetCtx of
313297
ProjectContext -> do
314298
let pkgs = projectPackages $ projectConfig ctx
315-
when (null targetStrings && length pkgs /= 1) $
299+
when (null targetSelectors && not (null pkgs)) $
316300
let projectName = case projectConfigProjectFile . projectConfigShared $ projectConfig ctx of
317301
Flag "" -> Nothing
318302
Flag n -> Just $ quotes (text n)

cabal-testsuite/PackageTests/ReplProjectTarget/cabal.out

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,13 @@ Please pick a single [package:][ctype:]component as target for the REPL command.
3030
Configuration is affected by the following files:
3131
- empty.project
3232
Warning: There are no packages or optional-packages in the project
33-
Error: [Cabal-7076]
34-
There are no packages in 'empty.project'. Please add a package to the project and pick a single [package:][ctype:]component as target for the REPL command.
33+
Resolving dependencies...
3534
# checking repl command with a missing 'missing.project'
3635
# cabal repl
3736
# checking repl command with a single package in 'one.project'
3837
# cabal repl
3938
Configuration is affected by the following files:
4039
- one.project
41-
Resolving dependencies...
42-
Build profile: -w ghc-<GHCVER> -O1
43-
In order, the following will be built:
44-
- pkg-one-0.1 (interactive) (first run)
45-
Configuring pkg-one-0.1...
46-
Preprocessing library for pkg-one-0.1...
47-
Error: [Cabal-7554]
48-
can't find source for Foo in ., <ROOT>/cabal.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/pkg-one-0.1/build/autogen, <ROOT>/cabal.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/pkg-one-0.1/build/global-autogen
49-
Error: [Cabal-7125]
50-
repl failed for pkg-one-0.1-inplace.
40+
Error: [Cabal-7076]
41+
Please pick a single [package:][ctype:]component as target for the REPL command. The packages in 'one.project' from which to select a component target are:
42+
- pkg-one

cabal-testsuite/PackageTests/ReplProjectTarget/cabal.test.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ main = cabalTest . recordMode RecordMarked $ do
3333
assertOutputContains "The given project file 'missing.project' does not exist." missing
3434

3535
log "checking repl command with a single package in 'one.project'"
36-
one <- fails $ cabal' "repl" [ "--project-file=one.project" ]
37-
assertOutputContains "In order, the following will be built" one
38-
assertOutputContains "pkg-one-0.1 (interactive) (first run)" one
36+
oneProject <- fails $ cabal' "repl" [ "--project-file=one.project" ]
37+
assertOutputContains "Configuration is affected by the following files:" oneProject
38+
assertOutputContains "- one.project" oneProject
39+
assertOutputContains "The packages in 'one.project' from which to select a component target are:" oneProject
40+
assertOutputContains "- pkg-one" oneProject
3941

4042
return ()

0 commit comments

Comments
 (0)