Skip to content

Commit 78f580e

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

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
@@ -76,6 +76,7 @@ import Control.Monad
7676
import Control.Monad.Reader as Reader
7777
import Control.Monad.State as State
7878
import qualified Data.Map.Strict as Map
79+
import Distribution.Client.Compat.ExecutablePath (getExecutablePath)
7980
import System.Directory
8081
import System.FilePath
8182

@@ -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)