Skip to content
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
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Major changes:

Behavior changes:

* File watching now takes into account specified targets, old behavior could
be restored using the new flag `--watch-all`
[#5310](https://github.com/commercialhaskell/stack/issues/5310)

Other enhancements:

* `stack ls dependencies json` now includes fields `sha256` and `size` for
Expand Down
5 changes: 4 additions & 1 deletion doc/build_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ all of them, please use `stack build --help`. Some particularly convenient ones
worth mentioning here since they compose well with the rest of the build system
as described:

* `--file-watch` will rebuild your project every time a file changes
* `--file-watch` will rebuild your project every time a file changes, by default
it will take into account all files belonging to the targets you specify,
alternatively one could specify `--watch-all` which will make Stack watch
any local files (from project packages or from local dependencies)
* `--exec "cmd [args]"` will run a command after a successful build

To come back to the composable approach described above, consider this final
Expand Down
16 changes: 13 additions & 3 deletions src/Stack/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,22 @@ build msetLocalFiles = do

checkSubLibraryDependencies (Map.elems $ smProject sourceMap)

boptsCli <- view $ envConfigL.to envConfigBuildOptsCLI
-- Set local files, necessary for file watching
stackYaml <- view stackYamlL
for_ msetLocalFiles $ \setLocalFiles -> do
files <- sequence
[lpFiles lp | lp <- allLocals]
files <-
if boptsCLIWatchAll boptsCli
then sequence [lpFiles lp | lp <- allLocals]
else forM allLocals $ \lp -> do
let pn = packageName (lpPackage lp)
case Map.lookup pn (smtTargets $ smTargets sourceMap) of
Nothing ->
pure Set.empty
Just (TargetAll _) ->
lpFiles lp
Just (TargetComps components) ->
lpFilesForComponents components lp
liftIO $ setLocalFiles $ Set.insert stackYaml $ Set.unions files

checkComponentsBuildable allLocals
Expand All @@ -81,7 +92,6 @@ build msetLocalFiles = do
(installedMap, globalDumpPkgs, snapshotDumpPkgs, localDumpPkgs) <-
getInstalled installMap

boptsCli <- view $ envConfigL.to envConfigBuildOptsCLI
baseConfigOpts <- mkBaseConfigOpts boptsCli
plan <- constructPlan baseConfigOpts localDumpPkgs loadPackage sourceMap installedMap (boptsCLIInitialBuildSteps boptsCli)

Expand Down
3 changes: 3 additions & 0 deletions src/Stack/Options/BuildParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ buildOptsParser cmd =
help
"Like --file-watch, but polling the filesystem instead of using events") <|>
pure NoFileWatch) <*>
switch
(long "watch-all" <>
help "Watch all local files not taking targets into account") <*>
many (cmdOption
(long "exec" <>
metavar "CMD [ARGS]" <>
Expand Down
2 changes: 2 additions & 0 deletions src/Stack/Types/Config/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ defaultBuildOptsCLI = BuildOptsCLI
, boptsCLIGhcOptions = []
, boptsCLIBuildSubset = BSAll
, boptsCLIFileWatch = NoFileWatch
, boptsCLIWatchAll = False
, boptsCLIExec = []
, boptsCLIOnlyConfigure = False
, boptsCLICommand = Build
Expand Down Expand Up @@ -166,6 +167,7 @@ data BuildOptsCLI = BuildOptsCLI
, boptsCLIFlags :: !(Map ApplyCLIFlag (Map FlagName Bool))
, boptsCLIBuildSubset :: !BuildSubset
, boptsCLIFileWatch :: !FileWatchOpts
, boptsCLIWatchAll :: !Bool
, boptsCLIExec :: ![(String, [String])]
, boptsCLIOnlyConfigure :: !Bool
, boptsCLICommand :: !BuildCommand
Expand Down
8 changes: 8 additions & 0 deletions src/Stack/Types/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,14 @@ instance Show (MemoizedWith env a) where
lpFiles :: HasEnvConfig env => LocalPackage -> RIO env (Set.Set (Path Abs File))
lpFiles = runMemoizedWith . fmap (Set.unions . M.elems) . lpComponentFiles

lpFilesForComponents :: HasEnvConfig env
=> Set NamedComponent
-> LocalPackage
-> RIO env (Set.Set (Path Abs File))
lpFilesForComponents components lp = runMemoizedWith $ do
componentFiles <- lpComponentFiles lp
pure $ mconcat (M.elems (M.restrictKeys componentFiles components))

-- | A location to install a package into, either snapshot or local
data InstallLocation = Snap | Local
deriving (Show, Eq)
Expand Down