Skip to content

Commit 2764334

Browse files
committed
Tests and benchmarks run as separate tasks #283
1 parent 810199e commit 2764334

File tree

6 files changed

+254
-142
lines changed

6 files changed

+254
-142
lines changed

src/Control/Concurrent/Execute.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import Stack.Types
2424

2525
data ActionType
2626
= ATBuild
27-
| ATInstall
28-
| ATWanted
27+
| ATFinal
2928
deriving (Show, Eq, Ord)
3029
data ActionId = ActionId !PackageIdentifier !ActionType
3130
deriving (Show, Eq, Ord)
@@ -36,15 +35,15 @@ data Action = Action
3635
}
3736

3837
data ActionContext = ActionContext
39-
{ acRemaining :: !Int
38+
{ acRemaining :: !(Set ActionId)
4039
-- ^ Does not include the current action
4140
}
4241
deriving Show
4342

4443
data ExecuteState = ExecuteState
4544
{ esActions :: TVar [Action]
4645
, esExceptions :: TVar [SomeException]
47-
, esInAction :: TVar Int
46+
, esInAction :: TVar (Set ActionId)
4847
}
4948

5049
data ExecuteException
@@ -63,7 +62,7 @@ runActions threads actions0 = do
6362
es <- ExecuteState
6463
<$> newTVarIO actions0
6564
<*> newTVarIO []
66-
<*> newTVarIO 0
65+
<*> newTVarIO Set.empty
6766
if threads <= 1
6867
then runActions' es
6968
else runConcurrently $ sequenceA_ $ replicate threads $ Concurrently $ runActions' es
@@ -87,28 +86,30 @@ runActions' ExecuteState {..} =
8786
case break (Set.null . actionDeps) as of
8887
(_, []) -> do
8988
inAction <- readTVar esInAction
90-
if inAction == 0
89+
if Set.null inAction
9190
then do
9291
modifyTVar esExceptions (toException InconsistentDependencies:)
9392
return $ return ()
9493
else retry
9594
(xs, action:ys) -> do
9695
let as' = xs ++ ys
9796
inAction <- readTVar esInAction
98-
let remaining = length as' + inAction
97+
let remaining = Set.union
98+
(Set.fromList $ map actionId as')
99+
inAction
99100
writeTVar esActions as'
100-
modifyTVar esInAction (+ 1)
101+
modifyTVar esInAction (Set.insert $ actionId action)
101102
return $ mask $ \restore -> do
102103
eres <- try $ restore $ actionDo action ActionContext
103104
{ acRemaining = remaining
104105
}
105106
case eres of
106107
Left err -> atomically $ do
107108
modifyTVar esExceptions (err:)
108-
modifyTVar esInAction (subtract 1)
109+
modifyTVar esInAction (Set.delete $ actionId action)
109110
Right () -> do
110111
atomically $ do
111-
modifyTVar esInAction (subtract 1)
112+
modifyTVar esInAction (Set.delete $ actionId action)
112113
let dropDep a = a { actionDeps = Set.delete (actionId action) $ actionDeps a }
113114
modifyTVar esActions $ map dropDep
114115
restore loop

src/Stack/Build.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ build bopts = do
6262
constructPlan mbp baseConfigOpts locals extraToBuild locallyRegistered loadPackage sourceMap installedMap
6363

6464
if boptsDryrun bopts
65-
then printPlan plan
65+
then printPlan (boptsFinalAction bopts) plan
6666
else executePlan menv bopts baseConfigOpts locals plan
6767
where
6868
profiling = boptsLibProfile bopts || boptsExeProfile bopts

src/Stack/Build/ConstructPlan.hs

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ data AddDepRes
6969

7070
type M = RWST
7171
Ctx
72-
( Map PackageName Task -- JustFinal
72+
( Map PackageName (Either ConstructPlanException Task) -- finals
7373
, Map Text Location -- executable to be installed, and location where the binary is placed
7474
)
7575
(Map PackageName (Either ConstructPlanException AddDepRes))
@@ -105,28 +105,31 @@ constructPlan :: forall env m.
105105
-> m Plan
106106
constructPlan mbp0 baseConfigOpts0 locals extraToBuild0 locallyRegistered loadPackage0 sourceMap installedMap = do
107107
bconfig <- asks getBuildConfig
108-
let inner = mapM_ addDep $ Set.toList allTargets
109-
((), m, (justFinals, installExes)) <- liftIO $ runRWST inner (ctx bconfig) M.empty
108+
let inner = do
109+
mapM_ addFinal $ filter lpWanted locals
110+
mapM_ addDep $ Set.toList extraToBuild0
111+
((), m, (efinals, installExes)) <- liftIO $ runRWST inner (ctx bconfig) M.empty
110112
let toEither (_, Left e) = Left e
111113
toEither (k, Right v) = Right (k, v)
112-
case partitionEithers $ map toEither $ M.toList m of
113-
([], adrs) -> do
114+
(errlibs, adrs) = partitionEithers $ map toEither $ M.toList m
115+
(errfinals, finals) = partitionEithers $ map toEither $ M.toList efinals
116+
errs = errlibs ++ errfinals
117+
if null errs
118+
then do
114119
let toTask (_, ADRFound _ _) = Nothing
115120
toTask (name, ADRToInstall task) = Just (name, task)
116121
tasks = M.fromList $ mapMaybe toTask adrs
117122
return Plan
118-
{ planTasks = Map.union tasks justFinals
123+
{ planTasks = tasks
124+
, planFinals = M.fromList finals
119125
, planUnregisterLocal = mkUnregisterLocal tasks locallyRegistered
120126
, planInstallExes =
121127
if boptsInstallExes $ bcoBuildOpts baseConfigOpts0
122128
then installExes
123129
else Map.empty
124130
}
125-
(errs, _) -> throwM $ ConstructPlanExceptions errs
131+
else throwM $ ConstructPlanExceptions errs
126132
where
127-
allTargets = Set.fromList (map (packageName . lpPackage) (filter lpWanted locals))
128-
<> extraToBuild0
129-
130133
ctx bconfig = Ctx
131134
{ mbp = mbp0
132135
, baseConfigOpts = baseConfigOpts0
@@ -155,6 +158,32 @@ mkUnregisterLocal tasks locallyRegistered =
155158
ident = ghcPkgIdPackageIdentifier gid
156159
name = packageIdentifierName ident
157160

161+
addFinal :: LocalPackage -> M ()
162+
addFinal lp = do
163+
depsRes <- addPackageDeps package
164+
res <- case depsRes of
165+
Left e -> return $ Left e
166+
Right (missing, present) -> do
167+
ctx <- ask
168+
return $ Right Task
169+
{ taskProvides = PackageIdentifier
170+
(packageName package)
171+
(packageVersion package)
172+
, taskConfigOpts = TaskConfigOpts missing $ \missing' ->
173+
let allDeps = Set.union present missing'
174+
in configureOpts
175+
(baseConfigOpts ctx)
176+
allDeps
177+
True -- wanted
178+
Local
179+
(packageFlags package)
180+
, taskPresent = present
181+
, taskType = TTLocal lp
182+
}
183+
tell (Map.singleton (packageName package) res, mempty)
184+
where
185+
package = lpPackageFinal lp
186+
158187
addDep :: PackageName -> M (Either ConstructPlanException AddDepRes)
159188
addDep name = do
160189
m <- get
@@ -194,7 +223,7 @@ addDep'' name = do
194223
then installPackage name ps
195224
else return $ Right $ ADRFound (piiVersion ps) installed
196225

197-
tellExecutables :: PackageName -> PackageSource -> M ()
226+
tellExecutables :: PackageName -> PackageSource -> M () -- TODO merge this with addFinal above?
198227
tellExecutables _ (PSLocal lp)
199228
| lpWanted lp = tellExecutablesPackage Local $ lpPackage lp
200229
| otherwise = return ()
@@ -305,31 +334,7 @@ checkDirtiness ps installed package present = do
305334
moldOpts <- tryGetFlagCache installed
306335
case moldOpts of
307336
Nothing -> return True
308-
Just oldOpts
309-
| oldOpts /= configCache -> return True
310-
| psDirty ps -> return True
311-
| otherwise -> do
312-
case ps of
313-
{- FIXME need to track finals completely differently now
314-
PSLocal lp | lpWanted lp -> do
315-
316-
-- track the fact that we need to perform a JustFinal. But
317-
-- don't put this in the main State Map, as that would
318-
-- trigger dependencies to rebuild also.
319-
let task = Task
320-
{ taskProvides = PackageIdentifier
321-
(packageName package)
322-
(packageVersion package)
323-
, taskType = TTLocal lp JustFinal
324-
, taskConfigOpts = TaskConfigOpts Set.empty $ \missing' ->
325-
assert (Set.null missing') configOpts
326-
, taskPresent = present
327-
}
328-
tell (Map.singleton (packageName package) task, Map.empty)
329-
-- FIXME need to force reconfigure when GhcPkgId for dependencies change
330-
-}
331-
_ -> return ()
332-
return False
337+
Just oldOpts -> return $ oldOpts /= configCache || psDirty ps
333338

334339
psDirty :: PackageSource -> Bool
335340
psDirty (PSLocal lp) = lpDirtyFiles lp

0 commit comments

Comments
 (0)