@@ -78,6 +78,7 @@ import Control.Monad.State as State
7878import qualified Data.Map.Strict as Map
7979import System.Directory
8080import 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 ]
146154rerunConcurrentlyIfChanged 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