Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't watch files for non-library components that are not being built #3565

Merged
merged 5 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,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 @@ -1563,6 +1563,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 @@ -225,15 +225,15 @@ loadLocalPackage 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 @@ -278,7 +278,8 @@ loadLocalPackage 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 @@ -301,7 +302,7 @@ loadLocalPackage 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 @@ -404,10 +405,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 @@ -425,16 +427,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