@@ -69,7 +69,7 @@ data AddDepRes
6969
7070type 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
106106constructPlan 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+
158187addDep :: PackageName -> M (Either ConstructPlanException AddDepRes )
159188addDep 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?
198227tellExecutables _ (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
334339psDirty :: PackageSource -> Bool
335340psDirty (PSLocal lp) = lpDirtyFiles lp
0 commit comments