Skip to content

Commit d4d3f28

Browse files
committed
Use dedicated hie-self-debug-test.yaml for self-debug
- Added `cradleFile` Launch argument and --cradle-file option to support use of custom hie.yaml files for debug. - self-debug tests specify cradleFile=hie-self-debug-test.yaml, which means: - using cradle with single "all" component - ignoring cabal.project.local - Also added hie-self-debug.yaml which also uses "all" cradle but does not ignore cabal.project.local. - specified as cradleFile in .vscode/launch.json - Uncommented multi cradles in default hie.yaml file, and removed "all" cradle.
1 parent b32ada0 commit d4d3f28

15 files changed

Lines changed: 77 additions & 23 deletions

File tree

.vscode/launch.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"entryFile": "hdb/Main.hs",
1010
"entryArgs": ["server", "--port", "12345"],
1111
"entryPoint": "main",
12-
"extraGhcArgs": []
12+
"extraGhcArgs": [],
13+
"cradleFile" : "hie-self-debug.yaml"
1314
},
1415
{
1516
"type": "haskell-debugger",
@@ -19,7 +20,8 @@
1920
"entryFile": "test/haskell/Main.hs",
2021
"entryPoint": "main",
2122
"entryArgs": ["--pattern", "DAP.Scopes"],
22-
"extraGhcArgs": []
23+
"extraGhcArgs": [],
24+
"cradleFile": "hie-self-debug.yaml"
2325
}
2426
]
2527
}

cabal.project.self-debug-test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- cabal project file used for self-debug tests.
2+
-- Meant to be just `cabal.project` but separate file to prevent cabal
3+
-- from including `cabal.project.local` as well.
4+
--
5+
-- Referenced by hie-self-debug-test.yaml
6+
7+
import: cabal.project

hdb-dap/Development/Debug/Adapter/Init.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ data LaunchArgs
8080
-- or function arguments otherwise.
8181
, extraGhcArgs :: Maybe [String]
8282
-- ^ Additional arguments to pass to the GHC invocation inferred by hie-bios for this project
83+
, cradleFile :: Maybe FilePath
84+
-- ^ specify cradle file rather than let it be inferred from @entryFile@, relative to @projectRoot@.
8385
} deriving stock (Show, Eq, Generic)
8486
deriving anyclass FromJSON
8587

@@ -115,6 +117,7 @@ initDebugger l servConf supportsRunInTerminal preferInternalInterpreter
115117
, entryPoint = fromMaybe "main" -> entryPoint
116118
, entryArgs = fromMaybe [] -> entryArgs
117119
, extraGhcArgs = fromMaybe [] -> extraGhcArgs
120+
, cradleFile
118121
} = do
119122
syncRequests <- liftIO newEmptyMVar
120123
syncResponses <- liftIO newEmptyMVar
@@ -144,7 +147,7 @@ initDebugger l servConf supportsRunInTerminal preferInternalInterpreter
144147
WithSeverity msg sev
145148
| sev >= Info -> dapLogger <& renderSessionSetupLog msg
146149
| otherwise -> mempty
147-
let debugRunnerConf = DebugRunnerConf projectRoot entryFile extraGhcArgs
150+
let debugRunnerConf = DebugRunnerConf projectRoot entryFile extraGhcArgs cradleFile
148151
liftIO (getDebugRunner servConf hieBiosLogger debugRunnerConf) >>= \case
149152
Left e -> throwError (ErrorMessage (T.pack e), Nothing)
150153
Right (ghcInvocation, debugRunner) -> do

hdb-dap/Development/Debug/Session/Setup.hs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{-# LANGUAGE LambdaCase #-}
33
{-# LANGUAGE OverloadedStrings #-}
44
{-# LANGUAGE RecordWildCards #-}
5+
{-# LANGUAGE ViewPatterns #-}
56

67
module Development.Debug.Session.Setup
78
(
@@ -75,6 +76,10 @@ data DebugRunnerConf = DebugRunnerConf
7576
{ drcProjectRoot :: FilePath
7677
, drcEntryFile :: FilePath
7778
, drcExtraGhcArgs :: [String]
79+
, drcCradleFile :: Maybe FilePath
80+
-- ^ specified cradle file rather than letting be inferred from
81+
-- @drcEntryFile@, relative to @drcProjectRoot@ if so. @DebugRunnerProvider@s
82+
-- must WARN if this field is @Just@ but they do not use hie cradles.
7883
}
7984

8085
data SessionSetupLog
@@ -106,11 +111,12 @@ data HieBiosFlags = HieBiosFlags
106111
hieBiosSetup :: LogAction IO (WithSeverity SessionSetupLog)
107112
-> FilePath -- ^ project root
108113
-> FilePath -- ^ entry file
114+
-> Maybe FilePath -- ^ cradle file
109115
-> ExceptT String IO (Either String HieBiosFlags)
110-
hieBiosSetup logger projectRoot entryFile = do
116+
hieBiosSetup logger projectRoot entryFile cradleFile = do
111117

112118
logInfo "Figuring out the right flags to compile the project using hie-bios..."
113-
cradle <- hieBiosCradle logger projectRoot entryFile & ExceptT
119+
cradle <- hieBiosCradle logger projectRoot entryFile cradleFile & ExceptT
114120

115121
-- GHC is found in PATH (by hie-bios as well).
116122
logInfo "Checking GHC version against debugger version..."
@@ -129,10 +135,16 @@ hieBiosSetup logger projectRoot entryFile = do
129135
hieBiosCradle :: LogAction IO (WithSeverity SessionSetupLog)
130136
-> FilePath -- ^ Project root
131137
-> FilePath -- ^ Entry file relative to root
138+
-> Maybe FilePath -- ^ Cradle file relative to root
132139
-> IO (Either String (HIE.Cradle Void))
133-
hieBiosCradle logger root relTarget = runExceptT $ do
140+
hieBiosCradle logger root relTarget mrelCradle = runExceptT $ do
134141
let target = root </> relTarget
135-
explicitCradle <- HIE.findCradle target & liftIO
142+
explicitCradle <- case mrelCradle of
143+
Nothing -> HIE.findCradle target & liftIO
144+
Just ((root </>) -> cradleFile) -> do
145+
liftIO (doesFileExist cradleFile) >>= \case
146+
True -> return $ Just cradleFile
147+
False -> throwError $ "Specified Cradle file does not exist: " ++ cradleFile
136148
cradle <- maybe (loadImplicitCradle hieBiosLogger target)
137149
(HIE.loadCradle hieBiosLogger) explicitCradle & liftIO
138150
liftLogIO logger <& WithSeverity (LogCradle cradle) Info
@@ -219,8 +231,8 @@ hieDebugRunner
219231
:: LogAction IO (WithSeverity SessionSetupLog)
220232
-> DebugRunnerConf
221233
-> IO (Either String (GhcInvocation, Debugger.DebugRunner Ghc a))
222-
hieDebugRunner l (DebugRunnerConf projectRoot entryFile extraGhcArgs) = runExceptT $ do
223-
r <- hieBiosSetup l projectRoot entryFile
234+
hieDebugRunner l (DebugRunnerConf projectRoot entryFile extraGhcArgs cradleFile) = runExceptT $ do
235+
r <- hieBiosSetup l projectRoot entryFile cradleFile
224236
HieBiosFlags{..} <- case r of
225237
Left e -> throwError e
226238
Right f -> return f

hdb/Development/Debug/Interactive.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ runIDM :: LogAction IO InteractiveLog
4747
-> FilePath -- ^ entryFile
4848
-> [String] -- ^ entryArgs
4949
-> [String] -- ^ extraGhcArgs
50+
-> Maybe FilePath
5051
-> RunDebuggerSettings
5152
-> InteractiveDM a
5253
-> IO a
53-
runIDM logger entryPoint entryFile entryArgs extraGhcArgs runConf act = do
54+
runIDM logger entryPoint entryFile entryArgs extraGhcArgs cradleFile runConf act = do
5455
projectRoot <- getCurrentDirectory
5556

5657
let hieBiosLogger = contramap ISessionSetupLog logger
57-
hieDebugRunner hieBiosLogger (DebugRunnerConf projectRoot entryFile extraGhcArgs) >>= \case
58+
hieDebugRunner hieBiosLogger (DebugRunnerConf projectRoot entryFile extraGhcArgs cradleFile) >>= \case
5859
Left e -> exitWithMsg e
5960
Right (_ghcInvocation, debugRunner)
6061
-> do

hdb/Development/Debug/Options.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ data HdbOptions
2121
, entryFile :: FilePath
2222
, entryArgs :: [String]
2323
, extraGhcArgs :: [String]
24+
, cradleFile :: Maybe FilePath
2425
, verbosity :: Severity
2526
, internalInterpreter :: Bool
2627
, disableIpeBacktraces :: Bool

hdb/Development/Debug/Options/Parser.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ cliParser = HdbCLI
5454
<> metavar "GHC_ARGS"
5555
<> value []
5656
<> help "Additional flags to pass to the ghc invocation that loads the program for debugging" )
57+
<*> option (Just <$> str)
58+
(long "cradle-file"
59+
<> metavar "HIE_PATH"
60+
<> value Nothing
61+
<> help "Path to .yaml file to use as cradle configuration. Location inferred from ENTRY_POINT otherwise."
62+
)
5763
<*> verbosityParser Warning
5864
<*> internalInterpreterParser
5965
<*> disableIpeBacktracesParser

hdb/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ main = do
9696
, externalInterpreterCustomProc = Left stdinStream
9797
, externalInterpreterProg = thisProg
9898
}
99-
runIDM (contramap InteractiveLog l) entryPoint entryFile entryArgs extraGhcArgs
99+
runIDM (contramap InteractiveLog l) entryPoint entryFile entryArgs extraGhcArgs cradleFile
100100
runConf debugInteractive
101101
HdbProxy{port} -> do
102102
setBacktraceMechanismState IPEBacktrace True

hie-self-debug-test.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# HIE cradle used for self-debug tests.
2+
# It has to be at the project root, otherwise HIE will not resolve it properly.
3+
cradle:
4+
cabal:
5+
cabalProject: "cabal.project.self-debug-test"
6+
component: "all"

hie-self-debug.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cradle:
2+
cabal:
3+
component: "all"

0 commit comments

Comments
 (0)