@@ -265,28 +265,36 @@ loadLocalPackage isLocal boptsCli targets (name, lpv) = do
265265 testpkg = resolvePackage testconfig gpkg
266266 benchpkg = resolvePackage benchconfig gpkg
267267
268- mbuildCache <- tryGetBuildCache $ lpvRoot lpv
269-
270- (files,_) <- getPackageFilesForTargets pkg (lpvCabalFP lpv) nonLibComponents
271-
272- (dirtyFiles, newBuildCache) <- checkBuildCache
273- (fromMaybe Map. empty mbuildCache)
274- (Set. toList files)
268+ (componentFiles,_) <- getPackageFilesForTargets pkg (lpvCabalFP lpv) nonLibComponents
269+
270+ checkCacheResults <- forM (Map. toList componentFiles) $ \ (component, files) -> do
271+ mbuildCache <- tryGetBuildCache (lpvRoot lpv) component
272+ checkCacheResult <- checkBuildCache
273+ (fromMaybe Map. empty mbuildCache)
274+ (Set. toList files)
275+ return (component, checkCacheResult)
276+
277+ let allDirtyFiles =
278+ Set. unions $
279+ map (\ (_, (dirtyFiles, _)) -> dirtyFiles) checkCacheResults
280+ newBuildCaches =
281+ M. fromList $
282+ map (\ (c, (_, cache)) -> (c, cache)) checkCacheResults
275283
276284 return LocalPackage
277285 { lpPackage = pkg
278286 , lpTestDeps = packageDeps testpkg
279287 , lpBenchDeps = packageDeps benchpkg
280288 , lpTestBench = btpkg
281- , lpFiles = files
289+ , lpComponentFiles = componentFiles
282290 , lpForceDirty = boptsForceDirty bopts
283291 , lpDirtyFiles =
284- if not (Set. null dirtyFiles )
292+ if not (Set. null allDirtyFiles )
285293 then let tryStripPrefix y =
286294 fromMaybe y (stripPrefix (toFilePath $ lpvRoot lpv) y)
287- in Just $ Set. map tryStripPrefix dirtyFiles
295+ in Just $ Set. map tryStripPrefix allDirtyFiles
288296 else Nothing
289- , lpNewBuildCache = newBuildCache
297+ , lpNewBuildCaches = newBuildCaches
290298 , lpCabalFile = lpvCabalFP lpv
291299 , lpDir = lpvRoot lpv
292300 , lpWanted = isWanted
@@ -394,15 +402,18 @@ addUnlistedToBuildCache
394402 -> Package
395403 -> Path Abs File
396404 -> Set NamedComponent
397- -> Map FilePath a
398- -> RIO env ([Map FilePath FileCacheInfo ], [PackageWarning ])
399- addUnlistedToBuildCache preBuildTime pkg cabalFP nonLibComponents buildCache = do
400- (files,warnings) <- getPackageFilesForTargets pkg cabalFP nonLibComponents
401- let newFiles =
402- Set. toList $
403- Set. map toFilePath files `Set.difference` Map. keysSet buildCache
404- addBuildCache <- mapM addFileToCache newFiles
405- return (addBuildCache, warnings)
405+ -> Map NamedComponent (Map FilePath a )
406+ -> RIO env (Map NamedComponent [Map FilePath FileCacheInfo ], [PackageWarning ])
407+ addUnlistedToBuildCache preBuildTime pkg cabalFP nonLibComponents buildCaches = do
408+ (componentFiles, warnings) <- getPackageFilesForTargets pkg cabalFP nonLibComponents
409+ results <- forM (M. toList componentFiles) $ \ (component, files) -> do
410+ let buildCache = M. findWithDefault M. empty component buildCaches
411+ newFiles =
412+ Set. toList $
413+ Set. map toFilePath files `Set.difference` Map. keysSet buildCache
414+ addBuildCache <- mapM addFileToCache newFiles
415+ return ((component, addBuildCache), warnings)
416+ return (M. fromList (map fst results), concatMap snd results)
406417 where
407418 addFileToCache fp = do
408419 mmodTime <- getModTimeMaybe fp
@@ -420,16 +431,18 @@ addUnlistedToBuildCache preBuildTime pkg cabalFP nonLibComponents buildCache = d
420431-- set of components.
421432getPackageFilesForTargets
422433 :: HasEnvConfig env
423- => Package -> Path Abs File -> Set NamedComponent -> RIO env (Set (Path Abs File ), [PackageWarning ])
424- getPackageFilesForTargets pkg cabalFP components = do
434+ => Package
435+ -> Path Abs File
436+ -> Set NamedComponent
437+ -> RIO env (Map NamedComponent (Set (Path Abs File )), [PackageWarning ])
438+ getPackageFilesForTargets pkg cabalFP nonLibComponents = do
425439 (_,compFiles,otherFiles,warnings) <-
426440 getPackageFiles (packageFiles pkg) cabalFP
427- let filesForComponent cn = Set. map dotCabalGetPath
428- $ M. findWithDefault mempty cn compFiles
429- files = Set. unions
430- $ otherFiles
431- : map filesForComponent (Set. toList $ Set. insert CLib components)
432- return (files, warnings)
441+ let components = Set. insert CLib nonLibComponents
442+ componentsFiles =
443+ M. map (\ files -> Set. union otherFiles (Set. map dotCabalGetPath files)) $
444+ M. filterWithKey (\ component _ -> component `Set.member` components) compFiles
445+ return (componentsFiles, warnings)
433446
434447-- | Get file modification time, if it exists.
435448getModTimeMaybe :: MonadIO m => FilePath -> m (Maybe ModTime )
0 commit comments