Skip to content

Commit 3fe34d7

Browse files
committed
feat(cabal-install): implicilty monitor our own executable to burst stale cache
1 parent a80c654 commit 3fe34d7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

cabal-install/src/Distribution/Client/RebuildMonad.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import Control.Monad.State as State
7878
import qualified Data.Map.Strict as Map
7979
import System.Directory
8080
import System.FilePath
81+
import Distribution.Client.Compat.ExecutablePath (getExecutablePath)
8182

8283
-- | A monad layered on top of 'IO' to help with re-running actions when the
8384
-- input files and values they depend on change. The crucial operations are
@@ -134,6 +135,13 @@ rerunIfChanged verbosity monitor key action = do
134135
[x] -> return x
135136
_ -> error "rerunIfChanged: impossible!"
136137

138+
-- | Monitor our current executable file for changes. This is useful to prevent
139+
-- stale cache when upgrading the cabal executable itself or while developing.
140+
monitorOurselves :: Rebuild ()
141+
monitorOurselves = do
142+
self <- liftIO getExecutablePath
143+
monitorFiles [monitorFile self]
144+
137145
-- | Like 'rerunIfChanged' meets 'mapConcurrently': For when we want multiple actions
138146
-- that need to do be re-run-if-changed asynchronously. The function returns
139147
-- when all values have finished computing.
@@ -144,6 +152,8 @@ rerunConcurrentlyIfChanged
144152
-> [(FileMonitor a b, a, Rebuild b)]
145153
-> Rebuild [b]
146154
rerunConcurrentlyIfChanged verbosity mkJobControl triples = do
155+
-- Implicitly add a monitor on our own executable file
156+
monitorOurselves
147157
rootDir <- askRoot
148158
dacts <- forM triples $ \(monitor, key, action) -> do
149159
let monitorName = takeFileName (fileMonitorCacheFile monitor)

0 commit comments

Comments
 (0)