Skip to content

Commit 76eed10

Browse files
committed
Improvements to progress output
1 parent 69fc333 commit 76eed10

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

src/Control/Concurrent/Execute.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,19 @@ data Action = Action
3737
data ActionContext = ActionContext
3838
{ acRemaining :: !(Set ActionId)
3939
-- ^ Does not include the current action
40+
, acCompleted :: !Int
41+
-- ^ Number of actions completed so far
42+
, acTotalActions :: !Int
43+
-- ^ Total number of actions to be performed
4044
}
4145
deriving Show
4246

4347
data ExecuteState = ExecuteState
4448
{ esActions :: TVar [Action]
4549
, esExceptions :: TVar [SomeException]
4650
, esInAction :: TVar (Set ActionId)
51+
, esCompleted :: TVar Int
52+
, esTotalActions :: !Int
4753
}
4854

4955
data ExecuteException
@@ -63,6 +69,8 @@ runActions threads actions0 = do
6369
<$> newTVarIO actions0
6470
<*> newTVarIO []
6571
<*> newTVarIO Set.empty
72+
<*> newTVarIO 0
73+
<*> pure (length actions0)
6674
if threads <= 1
6775
then runActions' es
6876
else runConcurrently $ sequenceA_ $ replicate threads $ Concurrently $ runActions' es
@@ -99,17 +107,22 @@ runActions' ExecuteState {..} =
99107
inAction
100108
writeTVar esActions as'
101109
modifyTVar esInAction (Set.insert $ actionId action)
110+
completed <- readTVar esCompleted
102111
return $ mask $ \restore -> do
103112
eres <- try $ restore $ actionDo action ActionContext
104113
{ acRemaining = remaining
114+
, acCompleted = completed
115+
, acTotalActions = esTotalActions
105116
}
106117
case eres of
107118
Left err -> atomically $ do
108119
modifyTVar esExceptions (err:)
109120
modifyTVar esInAction (Set.delete $ actionId action)
121+
modifyTVar esCompleted (+1)
110122
Right () -> do
111123
atomically $ do
112124
modifyTVar esInAction (Set.delete $ actionId action)
125+
modifyTVar esCompleted (+1)
113126
let dropDep a = a { actionDeps = Set.delete (actionId action) $ actionDeps a }
114127
modifyTVar esActions $ map dropDep
115128
restore loop

src/Stack/Build/Execute.hs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ displayTask task = T.pack $ concat
145145
data ExecuteEnv = ExecuteEnv
146146
{ eeEnvOverride :: !EnvOverride
147147
, eeConfigureLock :: !(MVar ())
148-
, eeInstallLock :: !(MVar (Int,Int))
148+
, eeInstallLock :: !(MVar ())
149149
, eeBuildOpts :: !BuildOpts
150150
, eeBaseConfigOpts :: !BaseConfigOpts
151151
, eeGhcPkgIds :: !(TVar (Map PackageIdentifier Installed))
@@ -167,8 +167,7 @@ executePlan menv bopts baseConfigOpts locals plan = do
167167
withSystemTempDirectory stackProgName $ \tmpdir -> do
168168
tmpdir' <- parseAbsDir tmpdir
169169
configLock <- newMVar ()
170-
installLock <-
171-
newMVar (0,installStepCount plan)
170+
installLock <- newMVar ()
172171
idMap <- liftIO $ newTVarIO M.empty
173172
let setupHs = tmpdir' </> $(mkRelFile "Setup.hs")
174173
liftIO $ writeFile (toFilePath setupHs) "import Distribution.Simple\nmain = defaultMain"
@@ -239,11 +238,6 @@ executePlan menv bopts baseConfigOpts locals plan = do
239238
windowsRenameCopy (toFilePath file) destFile
240239
_ -> copyFile (toFilePath file) destFile
241240

242-
-- | Calculate how many actual install steps are going to happen for
243-
-- the build.
244-
installStepCount :: Plan -> Int
245-
installStepCount = M.size . planTasks
246-
247241
-- | Windows can't write over the current executable. Instead, we rename the
248242
-- current executable to something else and then do the copy.
249243
windowsRenameCopy :: FilePath -> FilePath -> IO ()
@@ -334,14 +328,15 @@ toActions runInBase ee (mbuild, mfinal) =
334328
-- | Ensure that the configuration for the package matches what is given
335329
ensureConfig :: M env m
336330
=> Path Abs Dir -- ^ package directory
331+
-> ActionContext
337332
-> ExecuteEnv
338333
-> Task
339334
-> m () -- ^ announce
340335
-> (Bool -> [String] -> m ()) -- ^ cabal
341336
-> Path Abs File -- ^ .cabal file
342337
-> [Text]
343338
-> m (ConfigCache, Bool)
344-
ensureConfig pkgDir ExecuteEnv {..} Task {..} announce cabal cabalfp extra = do
339+
ensureConfig pkgDir ac ExecuteEnv {..} Task {..} announce cabal cabalfp extra = do
345340
-- Determine the old and new configuration in the local directory, to
346341
-- determine if we need to reconfigure.
347342
mOldConfigCache <- tryGetConfigCache pkgDir
@@ -368,8 +363,8 @@ ensureConfig pkgDir ExecuteEnv {..} Task {..} announce cabal cabalfp extra = do
368363
|| mOldCabalMod /= Just newCabalMod
369364
when needConfig $ withMVar eeConfigureLock $ \_ -> do
370365
deleteCaches pkgDir
371-
withMVar eeInstallLock $ \(done,total) ->
372-
$logSticky ("Progress: " <> T.pack (show done) <> "/" <> T.pack (show total))
366+
withMVar eeInstallLock $ \() ->
367+
$logSticky ("Progress: " <> T.pack (show (acCompleted ac)) <> "/" <> T.pack (show (acTotalActions ac)))
373368
announce
374369
cabal False $ "configure" : map T.unpack configOpts
375370
$logDebug $ T.pack $ show configOpts
@@ -511,7 +506,7 @@ singleBuild :: M env m
511506
-> m ()
512507
singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} =
513508
withSingleContext ac ee task $ \package cabalfp pkgDir cabal announce console _mlogFile -> do
514-
(cache, _neededConfig) <- ensureConfig pkgDir ee task (announce "configure") cabal cabalfp []
509+
(cache, _neededConfig) <- ensureConfig pkgDir ac ee task (announce "configure") cabal cabalfp []
515510

516511
fileModTimes <- getPackageFileModTimes package cabalfp
517512
writeBuildCache pkgDir fileModTimes
@@ -520,15 +515,14 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} =
520515
config <- asks getConfig
521516
cabal (console && configHideTHLoading config) ["build"]
522517

523-
modifyMVar_ eeInstallLock $ \(done,total) -> do
518+
withMVar eeInstallLock $ \() -> do
524519
announce "install"
525520
cabal False ["install"]
526-
unless (total == 1) $ do
527-
let done' = done + 1
528-
$logSticky ("Progress: " <> T.pack (show done') <> "/" <> T.pack (show total))
529-
when (done' == total)
530-
($logStickyDone ("Completed all " <> T.pack (show total) <> " packages."))
531-
return (done + 1,total)
521+
unless (acTotalActions == 1) $ do
522+
let done' = acCompleted + 1
523+
$logSticky ("Progress: " <> T.pack (show done') <> "/" <> T.pack (show acTotalActions))
524+
when (done' == acTotalActions)
525+
($logStickyDone ("Completed all " <> T.pack (show acTotalActions) <> " packages."))
532526

533527
let pkgDbs =
534528
case taskLocation task of
@@ -557,7 +551,7 @@ singleTest :: M env m
557551
singleTest ac ee task =
558552
withSingleContext ac ee task $ \package cabalfp pkgDir cabal announce console mlogFile ->
559553
unless (Set.null $ packageTests package) $ do
560-
(_cache, neededConfig) <- ensureConfig pkgDir ee task (announce "configure (test)") cabal cabalfp ["--enable-tests"]
554+
(_cache, neededConfig) <- ensureConfig pkgDir ac ee task (announce "configure (test)") cabal cabalfp ["--enable-tests"]
561555
config <- asks getConfig
562556

563557
let needBuild = neededConfig ||
@@ -630,7 +624,7 @@ singleBench :: M env m
630624
singleBench ac ee task =
631625
withSingleContext ac ee task $ \package cabalfp pkgDir cabal announce console _mlogFile ->
632626
unless (Set.null $ packageBenchmarks package) $ do
633-
(_cache, neededConfig) <- ensureConfig pkgDir ee task (announce "configure (benchmarks)") cabal cabalfp ["--enable-benchmarks"]
627+
(_cache, neededConfig) <- ensureConfig pkgDir ac ee task (announce "configure (benchmarks)") cabal cabalfp ["--enable-benchmarks"]
634628

635629
let needBuild = neededConfig ||
636630
(case taskType task of

0 commit comments

Comments
 (0)