13
13
module Main (main ) where
14
14
15
15
import Arguments
16
+ import Control.Concurrent.Async
16
17
import Control.Concurrent.Extra
17
18
import Control.Exception
18
19
import Control.Monad.Extra
@@ -190,8 +191,8 @@ main = do
190
191
{ optReportProgress = clientSupportsProgress caps
191
192
, optShakeProfiling = argsShakeProfiling
192
193
, optTesting = argsTesting
194
+ , optThreads = argsThreads
193
195
, optInterfaceLoadingDiagnostics = argsTesting
194
- , optThreads = argsThread
195
196
}
196
197
debouncer <- newAsyncDebouncer
197
198
initialise caps (mainRule >> pluginRules plugins >> action kick)
@@ -408,7 +409,6 @@ loadSession dir = liftIO $ do
408
409
return res
409
410
410
411
lock <- newLock
411
- cradle_lock <- newLock
412
412
413
413
-- This caches the mapping from hie.yaml + Mod.hs -> [String]
414
414
sessionOpts <- return $ \ (hieYaml, file) -> do
@@ -435,17 +435,39 @@ loadSession dir = liftIO $ do
435
435
finished_barrier <- newBarrier
436
436
-- fork a new thread here which won't be killed by shake
437
437
-- throwing an async exception
438
- void $ forkIO $ withLock cradle_lock $ do
439
- putStrLn $ " Shelling out to cabal " <> show file
438
+ void $ forkIO $ do
439
+ putStrLn $ " Consulting the cradle for " <> show file
440
440
cradle <- maybe (loadImplicitCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
441
441
opts <- cradleToSessionOpts cradle cfp
442
442
print opts
443
443
res <- fst <$> session (hieYaml, toNormalizedFilePath' cfp, opts)
444
444
signalBarrier finished_barrier res
445
445
waitBarrier finished_barrier
446
- return $ \ file -> liftIO $ mask_ $ withLock lock $ do
447
- hieYaml <- cradleLoc file
448
- sessionOpts (hieYaml, file)
446
+
447
+ dummyAs <- async $ return (error " Uninitialised" )
448
+ runningCradle <- newIORef dummyAs
449
+ -- The main function which gets options for a file. We only want one of these running
450
+ -- at a time.
451
+ let getOptions file = do
452
+ hieYaml <- cradleLoc file
453
+ sessionOpts (hieYaml, file)
454
+ -- The lock is on the `runningCradle` resource
455
+ return $ \ file -> liftIO $ withLock lock $ do
456
+ as <- readIORef runningCradle
457
+ finished <- poll as
458
+ case finished of
459
+ Just {} -> do
460
+ as <- async $ getOptions file
461
+ writeIORef runningCradle as
462
+ wait as
463
+ -- If it's not finished then wait and then get options, this could of course be killed still
464
+ Nothing -> do
465
+ _ <- wait as
466
+ getOptions file
467
+
468
+
469
+
470
+
449
471
450
472
checkDependencyInfo :: Map. Map FilePath (Maybe UTCTime ) -> IO Bool
451
473
checkDependencyInfo old_di = do
0 commit comments