Skip to content

Commit c6d893b

Browse files
committed
unique workingDirectory for each in-memory hdv
1 parent b034cc3 commit c6d893b

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

haskell-debugger.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ library
149149

150150
haskell-debugger-view >= 0.2 && < 1.0,
151151
ghc-stack-annotations >=0.1 && <0.2,
152+
temporary,
152153

153154
if !os(windows)
154155
build-depends: unix >= 2.8.6 && < 2.9,

haskell-debugger/GHC/Debugger/Monad.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import System.Posix.Signals
3434
import qualified Data.List as L
3535
import qualified Data.List.NonEmpty as NonEmpty
3636

37+
import System.IO.Temp
38+
3739
import GHC
3840
import GHC.Data.StringBuffer
3941
import GHC.Driver.Config.Diagnostic
@@ -255,7 +257,7 @@ runDebuggerAction :: forall a. LogAction IO DebuggerLog
255257
-> Ghc () -- ^ load home units action
256258
-> Debugger a
257259
-> Ghc a
258-
runDebuggerAction l rootDir extraGhcArgs conf loadHomeUnit (Debugger action) = flip MC.finally cleanupInterp $ -- See Note [Shutting down the external interpreter]
260+
runDebuggerAction l rootDir extraGhcArgs conf loadHomeUnit (Debugger action) = withSystemTempDirectory "haskell-debugger-view-in-memory" $ \ hdvWorkDir -> flip MC.finally cleanupInterp $ -- See Note [Shutting down the external interpreter]
259261
do
260262
dflags0 <- GHC.getSessionDynFlags
261263
let dflags1 = dflags0
@@ -329,7 +331,7 @@ runDebuggerAction l rootDir extraGhcArgs conf loadHomeUnit (Debugger action) = f
329331
#ifndef DEBUG_WITH_GHC
330332
-- Find haskell-debugger-view in (deps of) home units, or load one from
331333
-- in-memory sources.
332-
(hdv_uid, loadedBuiltinModNames) <- findOrLoadHaskellDebuggerView l buildWays
334+
(hdv_uid, loadedBuiltinModNames) <- findOrLoadHaskellDebuggerView l hdvWorkDir buildWays
333335
#else
334336
let hdv_uid = hsDebuggerViewInMemoryUnitId
335337
let loadedBuiltinModNames = [] :: [ModuleName]
@@ -393,9 +395,10 @@ runDebuggerAction l rootDir extraGhcArgs conf loadHomeUnit (Debugger action) = f
393395

394396

395397
findOrLoadHaskellDebuggerView :: LogAction IO DebuggerLog
398+
-> FilePath
396399
-> Ways
397400
-> Ghc (UnitId, [ModuleName])
398-
findOrLoadHaskellDebuggerView l buildWays = do
401+
findOrLoadHaskellDebuggerView l hdvWorkDir buildWays = do
399402
let ghcLog = liftLogIO l
400403
hsc_env <- getSession
401404
let mod_graph_base = hsc_mod_graph hsc_env
@@ -408,7 +411,7 @@ findOrLoadHaskellDebuggerView l buildWays = do
408411

409412
-- Add the custom unit to the HUG
410413
let base_dep_uids = [uid | UnitNode _ uid <- mg_mss mod_graph_base]
411-
addInMemoryHsDebuggerViewUnit base_dep_uids . setDynFlagWays buildWays =<< getDynFlags
414+
addInMemoryHsDebuggerViewUnit hdvWorkDir base_dep_uids . setDynFlagWays buildWays =<< getDynFlags
412415

413416
-- Load unit modules using in-memory contents.
414417
let

haskell-debugger/GHC/Debugger/Session/Builtin.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import GHC.Data.StringBuffer
3333
import qualified GHC.Unit.Home.Graph as HUG
3434
import qualified GHC.Unit.Home.PackageTable as HPT
3535
import qualified GHC.Unit.State as State
36+
import GHC.Debugger.Session (setWorkingDirectory)
3637

3738
--------------------------------------------------------------------------------
3839
-- * Built-in Modules
@@ -91,10 +92,11 @@ hsDebuggerViewInMemoryUnitId = toUnitId $ stringToUnit "haskell-debugger-view-in
9192
-- and add it to the HUG
9293
addInMemoryHsDebuggerViewUnit
9394
:: GhcMonad m
94-
=> [UnitId] -- ^ The unit-ids from the transitive dependencies closure of the user-given targets
95+
=> FilePath -- ^ workingDirectory for the unit
96+
-> [UnitId] -- ^ The unit-ids from the transitive dependencies closure of the user-given targets
9597
-> DynFlags -- ^ Dynflags resulting from first downsweep of user given targets
9698
-> m ()
97-
addInMemoryHsDebuggerViewUnit base_uids initialDynFlags = do
99+
addInMemoryHsDebuggerViewUnit hdvWorkDir base_uids initialDynFlags = do
98100
let imhdv_dflags = initialDynFlags
99101
{ homeUnitId_ = hsDebuggerViewInMemoryUnitId
100102
, importPaths = []
@@ -108,7 +110,7 @@ addInMemoryHsDebuggerViewUnit base_uids initialDynFlags = do
108110
, unitId /= ghcInternalUnitId
109111
]
110112
, thisPackageName = Just "haskell-debugger-view"
111-
}
113+
} & setWorkingDirectory hdvWorkDir
112114
& setGeneralFlag' Opt_HideAllPackages
113115
hsc_env <- getSession
114116
let cached_unit_dbs = concat . catMaybes . fmap HUG.homeUnitEnv_unit_dbs $ Foldable.toList (hsc_HUG hsc_env)

0 commit comments

Comments
 (0)