Skip to content

Commit 9fcf300

Browse files
authored
Merge pull request #5586 from commercialhaskell/5578-setup-config-reconfig
Track changes to setup-config #5578
2 parents f3bbd95 + f641880 commit 9fcf300

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Bug fixes:
3434
* `stack setup` will look in sandboxed directories for executables, not
3535
relying on `findExecutables. See
3636
[GHC issue 20074](https://gitlab.haskell.org/ghc/ghc/-/issues/20074)
37+
* Track changes to `setup-config` properly to avoid reconfiguring on every change.
38+
See [#5578](https://github.com/commercialhaskell/stack/issues/5578)
3739

3840
## v2.7.1
3941

src/Stack/Build/Cache.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Stack.Build.Cache
2121
, writeBuildCache
2222
, writeConfigCache
2323
, writeCabalMod
24+
, writeSetupConfigMod
2425
, TestStatus (..)
2526
, setTestStatus
2627
, getTestStatus
@@ -182,6 +183,20 @@ writeCabalMod dir x = do
182183
writeBinaryFileAtomic fp "Just used for its modification time"
183184
liftIO $ setFileTimes (toFilePath fp) x x
184185

186+
-- | See 'tryGetSetupConfigMod'
187+
writeSetupConfigMod
188+
:: HasEnvConfig env
189+
=> Path Abs Dir
190+
-> Maybe CTime
191+
-> RIO env ()
192+
writeSetupConfigMod dir Nothing = do
193+
fp <- configSetupConfigMod dir
194+
ignoringAbsence $ removeFile fp
195+
writeSetupConfigMod dir (Just x) = do
196+
fp <- configSetupConfigMod dir
197+
writeBinaryFileAtomic fp "Just used for its modification time"
198+
liftIO $ setFileTimes (toFilePath fp) x x
199+
185200
-- | Delete the caches for the project.
186201
deleteCaches :: HasEnvConfig env => Path Abs Dir -> RIO env ()
187202
deleteCaches dir

src/Stack/Build/Execute.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,10 @@ ensureConfig :: HasEnvConfig env
845845
ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task = do
846846
newCabalMod <- liftIO $ modificationTime <$> getFileStatus (toFilePath cabalfp)
847847
setupConfigfp <- setupConfigFromDir pkgDir
848-
newSetupConfigMod <- liftIO $ either (const Nothing) (Just . modificationTime) <$>
849-
tryJust (guard . isDoesNotExistError) (getFileStatus (toFilePath setupConfigfp))
848+
let getNewSetupConfigMod =
849+
liftIO $ either (const Nothing) (Just . modificationTime) <$>
850+
tryJust (guard . isDoesNotExistError) (getFileStatus (toFilePath setupConfigfp))
851+
newSetupConfigMod <- getNewSetupConfigMod
850852
-- See https://github.com/commercialhaskell/stack/issues/3554
851853
taskAnyMissingHack <- view $ actualCompilerVersionL.to getGhcVersion.to (< mkVersion [8, 4])
852854
needConfig <-
@@ -905,6 +907,11 @@ ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task =
905907
TTLocalMutable{} -> writeConfigCache pkgDir newConfigCache
906908
TTRemotePackage{} -> return ()
907909
writeCabalMod pkgDir newCabalMod
910+
-- This file gets updated one more time by the configure step, so get
911+
-- the most recent value. We could instead change our logic above to
912+
-- check if our config mod file is newer than the file above, but this
913+
-- seems reasonable too.
914+
getNewSetupConfigMod >>= writeSetupConfigMod pkgDir
908915

909916
return needConfig
910917
where

0 commit comments

Comments
 (0)