Skip to content

Commit e94aa71

Browse files
committed
--keep-going commercialhaskell#478
1 parent 2668f9b commit e94aa71

5 files changed

Lines changed: 34 additions & 17 deletions

File tree

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Add the __`--file-watch`__ flag to auto-rebuild on file changes [#113](https://github.com/commercialhaskell/stack/issues/113)
1414
* Rename `stack docker exec` to `stack exec --plain`
1515
* Add the `--skip-msys` flag [#377](https://github.com/commercialhaskell/stack/issues/377)
16+
* `--keep-going`, turned on by default for tests and benchmarks [#478](https://github.com/commercialhaskell/stack/issues/478)
1617

1718
## 0.1.1.0
1819

src/Control/Concurrent/Execute.hs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Control.Applicative
1414
import Control.Concurrent.Async (Concurrently (..), async)
1515
import Control.Concurrent.STM
1616
import Control.Exception
17-
import Control.Monad (join)
17+
import Control.Monad (join, unless)
1818
import Data.Foldable (sequenceA_)
1919
import Data.Set (Set)
2020
import qualified Data.Set as Set
@@ -45,6 +45,7 @@ data ExecuteState = ExecuteState
4545
, esExceptions :: TVar [SomeException]
4646
, esInAction :: TVar (Set ActionId)
4747
, esCompleted :: TVar Int
48+
, esKeepGoing :: Bool
4849
}
4950

5051
data ExecuteException
@@ -57,15 +58,17 @@ instance Show ExecuteException where
5758
"Inconsistent dependencies were discovered while executing your build plan. This should never happen, please report it as a bug to the stack team."
5859

5960
runActions :: Int -- ^ threads
61+
-> Bool -- ^ keep going after one task has failed
6062
-> [Action]
6163
-> (TVar Int -> IO ()) -- ^ progress updated
6264
-> IO [SomeException]
63-
runActions threads actions0 withProgress = do
65+
runActions threads keepGoing actions0 withProgress = do
6466
es <- ExecuteState
6567
<$> newTVarIO actions0
6668
<*> newTVarIO []
6769
<*> newTVarIO Set.empty
6870
<*> newTVarIO 0
71+
<*> pure keepGoing
6972
_ <- async $ withProgress $ esCompleted es
7073
if threads <= 1
7174
then runActions' es
@@ -78,7 +81,7 @@ runActions' ExecuteState {..} =
7881
where
7982
breakOnErrs inner = do
8083
errs <- readTVar esExceptions
81-
if null errs
84+
if null errs || esKeepGoing
8285
then inner
8386
else return $ return ()
8487
withActions inner = do
@@ -92,7 +95,8 @@ runActions' ExecuteState {..} =
9295
inAction <- readTVar esInAction
9396
if Set.null inAction
9497
then do
95-
modifyTVar esExceptions (toException InconsistentDependencies:)
98+
unless esKeepGoing $
99+
modifyTVar esExceptions (toException InconsistentDependencies:)
96100
return $ return ()
97101
else retry
98102
(xs, action:ys) -> do
@@ -107,15 +111,12 @@ runActions' ExecuteState {..} =
107111
eres <- try $ restore $ actionDo action ActionContext
108112
{ acRemaining = remaining
109113
}
110-
case eres of
111-
Left err -> atomically $ do
112-
modifyTVar esExceptions (err:)
113-
modifyTVar esInAction (Set.delete $ actionId action)
114-
modifyTVar esCompleted (+1)
115-
Right () -> do
116-
atomically $ do
117-
modifyTVar esInAction (Set.delete $ actionId action)
118-
modifyTVar esCompleted (+1)
114+
atomically $ do
115+
modifyTVar esInAction (Set.delete $ actionId action)
116+
modifyTVar esCompleted (+1)
117+
case eres of
118+
Left err -> modifyTVar esExceptions (err:)
119+
Right () ->
119120
let dropDep a = a { actionDeps = Set.delete (actionId action) $ actionDeps a }
120-
modifyTVar esActions $ map dropDep
121-
restore loop
121+
in modifyTVar esActions $ map dropDep
122+
restore loop

src/Stack/Build/Execute.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,15 @@ executePlan' plan ee@ExecuteEnv {..} = do
333333
(planTasks plan)
334334
(planFinals plan)
335335
threads <- asks $ configJobs . getConfig
336+
let keepGoing =
337+
case boptsKeepGoing eeBuildOpts of
338+
Just kg -> kg
339+
Nothing ->
340+
case boptsFinalAction eeBuildOpts of
341+
DoNothing -> False
342+
_ -> True
336343
terminal <- asks getTerminal
337-
errs <- liftIO $ runActions threads actions $ \doneVar -> do
344+
errs <- liftIO $ runActions threads keepGoing actions $ \doneVar -> do
338345
let total = length actions
339346
loop prev
340347
| prev == total =

src/Stack/Build/Types.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ data BuildOpts =
297297
-- suites.
298298
,boptsFileWatch :: !Bool
299299
-- ^ Watch files for changes and automatically rebuild
300+
,boptsKeepGoing :: !(Maybe Bool)
301+
-- ^ Keep building/running after failure
300302
}
301303
deriving (Show)
302304

@@ -318,6 +320,7 @@ defaultBuildOpts = BuildOpts
318320
, boptsOnlySnapshot = False
319321
, boptsCoverage = False
320322
, boptsFileWatch = False
323+
, boptsKeepGoing = Nothing
321324
}
322325

323326
-- | Run a Setup.hs action after building a package, before installing.

src/main/Main.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ buildOpts cmd = fmap process $
667667
BuildOpts <$> target <*> libProfiling <*> exeProfiling <*>
668668
optimize <*> haddock <*> haddockDeps <*> finalAction <*> dryRun <*> ghcOpts <*>
669669
flags <*> installExes <*> preFetch <*> testArgs <*> onlySnapshot <*> coverage <*>
670-
fileWatch'
670+
fileWatch' <*> keepGoing
671671
where process bopts =
672672
if boptsCoverage bopts
673673
then bopts { boptsExeProfile = True
@@ -751,6 +751,11 @@ buildOpts cmd = fmap process $
751751
(long "file-watch" <>
752752
help "Watch for changes in local files and automatically rebuild")
753753

754+
keepGoing = maybeBoolFlags
755+
"keep-going"
756+
"continue running after a step fails (default: false for build, true for test/bench)"
757+
idm
758+
754759
-- | Parser for docker cleanup arguments.
755760
dockerCleanupOpts :: Parser Docker.CleanupOpts
756761
dockerCleanupOpts =

0 commit comments

Comments
 (0)