Skip to content

Commit

Permalink
Merge pull request #3565 from tswelsh/3483-file-watch-components
Browse files Browse the repository at this point in the history
Don't watch files for non-library components that are not being built
  • Loading branch information
snoyberg authored Nov 28, 2017
2 parents 8910ef9 + 1684c07 commit 7af4393
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ Other enhancements:
[#3520](https://github.com/commercialhaskell/stack/issues/3520).
* Log when each individual test suite finishes. See:
[#3552](https://github.com/commercialhaskell/stack/issues/3552).
* Avoid spurious rebuilds when using `--file-watch` by not watching files for
executable, test and benchmark components that aren't a target. See:
[#3483](https://github.com/commercialhaskell/stack/issues/3483).
* Stack will now try to detect the width of the running terminal
(only on POSIX for the moment) and use that to better display
output messages. Work is ongoing, so some messages will not
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,7 @@ checkForUnlistedFiles (TTFiles lp _) preBuildTime pkgDir = do
preBuildTime
(lpPackage lp)
(lpCabalFile lp)
(lpComponents lp)
(lpNewBuildCache lp)
unless (null addBuildCache) $
writeBuildCache pkgDir $
Expand Down
35 changes: 21 additions & 14 deletions src/Stack/Build/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ loadLocalPackage isLocal boptsCli targets (name, lpv) = do
case packageLibraries pkg of
NoLibraries -> False
HasLibraries _ -> True
in hasLibrary || not (Set.null allComponents)
in hasLibrary || not (Set.null nonLibComponents)

filterSkippedComponents = Set.filter (not . (`elem` boptsSkipComponents bopts))

(exes, tests, benches) = (filterSkippedComponents exeCandidates,
filterSkippedComponents testCandidates,
filterSkippedComponents benchCandidates)

allComponents = toComponents exes tests benches
nonLibComponents = toComponents exes tests benches

toComponents e t b = Set.unions
[ Set.map CExe e
Expand Down Expand Up @@ -281,7 +281,8 @@ loadLocalPackage isLocal boptsCli targets (name, lpv) = do
benchpkg = resolvePackage benchconfig gpkg

mbuildCache <- tryGetBuildCache $ lpvRoot lpv
(files,_) <- getPackageFilesSimple pkg (lpvCabalFP lpv)

(files,_) <- getPackageFilesForTargets pkg (lpvCabalFP lpv) nonLibComponents

(dirtyFiles, newBuildCache) <- checkBuildCache
(fromMaybe Map.empty mbuildCache)
Expand All @@ -304,7 +305,7 @@ loadLocalPackage isLocal boptsCli targets (name, lpv) = do
, lpCabalFile = lpvCabalFP lpv
, lpDir = lpvRoot lpv
, lpWanted = isWanted
, lpComponents = allComponents
, lpComponents = nonLibComponents
-- TODO: refactor this so that it's easier to be sure that these
-- components are indeed unbuildable.
--
Expand Down Expand Up @@ -407,10 +408,11 @@ addUnlistedToBuildCache
=> ModTime
-> Package
-> Path Abs File
-> Set NamedComponent
-> Map FilePath a
-> RIO env ([Map FilePath FileCacheInfo], [PackageWarning])
addUnlistedToBuildCache preBuildTime pkg cabalFP buildCache = do
(files,warnings) <- getPackageFilesSimple pkg cabalFP
addUnlistedToBuildCache preBuildTime pkg cabalFP nonLibComponents buildCache = do
(files,warnings) <- getPackageFilesForTargets pkg cabalFP nonLibComponents
let newFiles =
Set.toList $
Set.map toFilePath files `Set.difference` Map.keysSet buildCache
Expand All @@ -428,16 +430,21 @@ addUnlistedToBuildCache preBuildTime pkg cabalFP buildCache = do
return (Map.singleton fp newFci)
else return Map.empty

-- | Gets list of Paths for files in a package
getPackageFilesSimple
-- | Gets list of Paths for files relevant to a set of components in a package.
-- Note that the library component, if any, is always automatically added to the
-- set of components.
getPackageFilesForTargets
:: HasEnvConfig env
=> Package -> Path Abs File -> RIO env (Set (Path Abs File), [PackageWarning])
getPackageFilesSimple pkg cabalFP = do
(_,compFiles,cabalFiles,warnings) <-
=> Package -> Path Abs File -> Set NamedComponent -> RIO env (Set (Path Abs File), [PackageWarning])
getPackageFilesForTargets pkg cabalFP components = do
(_,compFiles,otherFiles,warnings) <-
getPackageFiles (packageFiles pkg) cabalFP
return
( Set.map dotCabalGetPath (mconcat (M.elems compFiles)) <> cabalFiles
, warnings)
let filesForComponent cn = Set.map dotCabalGetPath
$ M.findWithDefault mempty cn compFiles
files = Set.unions
$ otherFiles
: map filesForComponent (Set.toList $ Set.insert CLib components)
return (files, warnings)

-- | Get file modification time, if it exists.
getModTimeMaybe :: MonadIO m => FilePath -> m (Maybe ModTime)
Expand Down

0 comments on commit 7af4393

Please sign in to comment.