Skip to content

Commit

Permalink
Track changes to setup-config #5578
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Jul 16, 2021
1 parent fee62e7 commit f641880
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Bug fixes:
* `stack setup` will look in sandboxed directories for executables, not
relying on `findExecutables. See
[GHC issue 20074](https://gitlab.haskell.org/ghc/ghc/-/issues/20074)
* Track changes to `setup-config` properly to avoid reconfiguring on every change.
See [#5578](https://github.com/commercialhaskell/stack/issues/5578)

## v2.7.1

Expand Down
15 changes: 15 additions & 0 deletions src/Stack/Build/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Stack.Build.Cache
, writeBuildCache
, writeConfigCache
, writeCabalMod
, writeSetupConfigMod
, TestStatus (..)
, setTestStatus
, getTestStatus
Expand Down Expand Up @@ -182,6 +183,20 @@ writeCabalMod dir x = do
writeBinaryFileAtomic fp "Just used for its modification time"
liftIO $ setFileTimes (toFilePath fp) x x

-- | See 'tryGetSetupConfigMod'
writeSetupConfigMod
:: HasEnvConfig env
=> Path Abs Dir
-> Maybe CTime
-> RIO env ()
writeSetupConfigMod dir Nothing = do
fp <- configSetupConfigMod dir
ignoringAbsence $ removeFile fp
writeSetupConfigMod dir (Just x) = do
fp <- configSetupConfigMod dir
writeBinaryFileAtomic fp "Just used for its modification time"
liftIO $ setFileTimes (toFilePath fp) x x

-- | Delete the caches for the project.
deleteCaches :: HasEnvConfig env => Path Abs Dir -> RIO env ()
deleteCaches dir
Expand Down
11 changes: 9 additions & 2 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,10 @@ ensureConfig :: HasEnvConfig env
ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task = do
newCabalMod <- liftIO $ modificationTime <$> getFileStatus (toFilePath cabalfp)
setupConfigfp <- setupConfigFromDir pkgDir
newSetupConfigMod <- liftIO $ either (const Nothing) (Just . modificationTime) <$>
tryJust (guard . isDoesNotExistError) (getFileStatus (toFilePath setupConfigfp))
let getNewSetupConfigMod =
liftIO $ either (const Nothing) (Just . modificationTime) <$>
tryJust (guard . isDoesNotExistError) (getFileStatus (toFilePath setupConfigfp))
newSetupConfigMod <- getNewSetupConfigMod
-- See https://github.com/commercialhaskell/stack/issues/3554
taskAnyMissingHack <- view $ actualCompilerVersionL.to getGhcVersion.to (< mkVersion [8, 4])
needConfig <-
Expand Down Expand Up @@ -905,6 +907,11 @@ ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task =
TTLocalMutable{} -> writeConfigCache pkgDir newConfigCache
TTRemotePackage{} -> return ()
writeCabalMod pkgDir newCabalMod
-- This file gets updated one more time by the configure step, so get
-- the most recent value. We could instead change our logic above to
-- check if our config mod file is newer than the file above, but this
-- seems reasonable too.
getNewSetupConfigMod >>= writeSetupConfigMod pkgDir

return needConfig
where
Expand Down

0 comments on commit f641880

Please sign in to comment.