Skip to content

Commit ca17d17

Browse files
committed
Determine whether to reinstall from installed cache, not local cache #283
1 parent 34ecae1 commit ca17d17

File tree

5 files changed

+136
-230
lines changed

5 files changed

+136
-230
lines changed

src/Stack/Build/Cache.hs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ import qualified Data.Map as Map
3333
import Data.Maybe (catMaybes, mapMaybe)
3434
import Data.Set (Set)
3535
import qualified Data.Set as Set
36-
import Data.Text (Text)
37-
import Data.Text.Encoding (encodeUtf8)
3836
import GHC.Generics (Generic)
3937
import Path
4038
import Path.IO
@@ -124,25 +122,9 @@ writeBuildCache dir times =
124122
-- | Write the dirtiness cache for this package's configuration.
125123
writeConfigCache :: (MonadIO m, MonadReader env m, HasConfig env, MonadThrow m, MonadLogger m, HasEnvConfig env)
126124
=> Path Abs Dir
127-
-> [Text]
128-
-> Set GhcPkgId -- ^ dependencies
129-
-> Path Abs file
130-
-> TaskType
125+
-> ConfigCache
131126
-> m ()
132-
writeConfigCache dir opts deps cabalfp ttype =
133-
do now <- liftIO (getModificationTime (toFilePath cabalfp))
134-
let cache = ConfigCache
135-
{ configCacheOpts = map encodeUtf8 opts
136-
, configCacheDeps = deps
137-
, configCabalFileModTime =
138-
case ttype of
139-
TTLocal lp _ | lpWanted lp -> Just (modTime now)
140-
_ -> Nothing
141-
}
142-
writeCache
143-
dir
144-
configCacheFile
145-
cache
127+
writeConfigCache dir = writeCache dir configCacheFile
146128

147129
-- | Delete the caches for the project.
148130
deleteCaches :: (MonadIO m, MonadReader env m, HasConfig env, MonadLogger m, MonadThrow m, HasEnvConfig env)
@@ -189,18 +171,13 @@ writeFlagCache :: (MonadIO m, MonadReader env m, HasBuildConfig env, MonadThrow
189171
=> GhcPkgId
190172
-> [ByteString]
191173
-> Set GhcPkgId
192-
-> Path Abs File
193-
-> TaskType
194174
-> m ()
195-
writeFlagCache gid flags deps cabalfp ttype = do
175+
writeFlagCache gid flags deps = do
196176
file <- flagCacheFile gid
197-
now <- liftIO $ getModificationTime (toFilePath cabalfp)
198177
let cache = ConfigCache
199178
{ configCacheOpts = flags
200179
, configCacheDeps = deps
201-
, configCabalFileModTime = case ttype of
202-
TTLocal lp _ | lpWanted lp -> Just (modTime now)
203-
_ -> Nothing
180+
, configCabalFileModTime = Nothing -- FIXME I'm not convinced this should even be in ConfigCache
204181
}
205182
liftIO $ do
206183
createDirectoryIfMissing True $ toFilePath $ parent file

src/Stack/Build/ConstructPlan.hs

Lines changed: 29 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import Data.Text.Encoding (encodeUtf8)
2828
import Distribution.Package (Dependency (..))
2929
import Distribution.Version (anyVersion,
3030
intersectVersionRanges)
31-
import Path
3231
import Prelude hiding (FilePath, pi, writeFile)
3332
import Stack.Build.Cache
3433
import Stack.Build.Installed
@@ -38,7 +37,6 @@ import Stack.BuildPlan
3837

3938
import Stack.Package
4039
import Stack.Types
41-
import System.Directory
4240

4341
data PackageInfo
4442
= PIOnlyInstalled Version Location Installed
@@ -152,10 +150,7 @@ mkUnregisterLocal tasks locallyRegistered =
152150
toUnregister gid =
153151
case M.lookup name tasks of
154152
Nothing -> False
155-
Just task ->
156-
case taskType task of
157-
TTLocal _ JustFinal -> False
158-
_ -> True
153+
Just _ -> True
159154
where
160155
ident = ghcPkgIdPackageIdentifier gid
161156
name = packageIdentifierName ident
@@ -191,13 +186,13 @@ addDep'' name = do
191186
return $ Right $ ADRFound version installed
192187
Just (PIOnlySource ps) -> do
193188
tellExecutables name ps
194-
installPackage Nothing name ps
189+
installPackage name ps
195190
Just (PIBoth ps installed) -> do
196191
tellExecutables name ps
197-
mneededSteps <- checkNeededSteps name ps installed
198-
case mneededSteps of
199-
Nothing -> return $ Right $ ADRFound (piiVersion ps) installed
200-
Just neededSteps -> installPackage (Just neededSteps) name ps
192+
needInstall <- checkNeedInstall name ps installed
193+
if needInstall
194+
then installPackage name ps
195+
else return $ Right $ ADRFound (piiVersion ps) installed
201196

202197
tellExecutables :: PackageName -> PackageSource -> M ()
203198
tellExecutables _ (PSLocal lp)
@@ -222,12 +217,11 @@ tellExecutablesPackage loc p =
222217
-- TODO There are a lot of duplicated computations below. I've kept that for
223218
-- simplicity right now
224219

225-
installPackage :: Maybe NeededSteps -> PackageName -> PackageSource -> M (Either ConstructPlanException AddDepRes)
226-
installPackage mneededSteps name ps = do
220+
installPackage :: PackageName -> PackageSource -> M (Either ConstructPlanException AddDepRes)
221+
installPackage name ps = do
227222
ctx <- ask
228223
package <- psPackage name ps
229224
depsRes <- addPackageDeps package
230-
mtime <- packageSourceCabalModTime ps
231225
case depsRes of
232226
Left e -> return $ Left e
233227
Right (missing, present) -> do
@@ -247,41 +241,18 @@ installPackage mneededSteps name ps = do
247241
, taskType =
248242
case ps of
249243
PSLocal lp -> TTLocal lp
250-
$ case mneededSteps of
251-
Just neededSteps -> neededSteps
252-
Nothing ->
253-
case lpLastConfigOpts lp of
254-
Nothing -> AllSteps
255-
Just configOpts
256-
| not $ Set.null missing -> AllSteps
257-
| otherwise -> do
258-
259-
let newOpts = configureOpts
260-
(baseConfigOpts ctx)
261-
present
262-
(psWanted ps)
263-
(piiLocation ps)
264-
(packageFlags package)
265-
configCache = ConfigCache
266-
{ configCacheOpts = map encodeUtf8 newOpts
267-
, configCacheDeps = present
268-
, configCabalFileModTime = mtime
269-
}
270-
in if configCache == configOpts
271-
then SkipConfig
272-
else AllSteps
273244
PSUpstream _ loc _ -> TTUpstream package loc
274245
}
275246

276-
checkNeededSteps :: PackageName -> PackageSource -> Installed -> M (Maybe NeededSteps)
277-
checkNeededSteps name ps installed = assert (piiLocation ps == Local) $ do
247+
checkNeedInstall :: PackageName -> PackageSource -> Installed -> M Bool
248+
checkNeedInstall name ps installed = assert (piiLocation ps == Local) $ do
278249
package <- psPackage name ps
279250
depsRes <- addPackageDeps package
280251
case depsRes of
281-
Left _e -> return $ Just AllSteps -- installPackage will find the error again
252+
Left _e -> return True -- installPackage will find the error again
282253
Right (missing, present)
283254
| Set.null missing -> checkDirtiness ps installed package present
284-
| otherwise -> return $ Just AllSteps
255+
| otherwise -> return True
285256

286257
addPackageDeps :: Package -> M (Either ConstructPlanException (Set PackageIdentifier, Set GhcPkgId))
287258
addPackageDeps package = do
@@ -314,20 +285,13 @@ addPackageDeps package = do
314285
adrVersion (ADRToInstall task) = packageIdentifierVersion $ taskProvides task
315286
adrVersion (ADRFound v _) = v
316287

317-
packageSourceCabalModTime :: MonadIO m => PackageSource -> m (Maybe ModTime)
318-
packageSourceCabalModTime (PSLocal lp) | lpWanted lp = do
319-
now <-
320-
liftIO (getModificationTime
321-
(toFilePath (lpCabalFile lp)))
322-
return (Just (modTime now))
323-
packageSourceCabalModTime _ = return Nothing
324-
325288
checkDirtiness :: PackageSource
326289
-> Installed
327290
-> Package
328291
-> Set GhcPkgId
329-
-> M (Maybe NeededSteps)
330-
checkDirtiness ps@(PSLocal lp) Executable package present = do
292+
-> M Bool
293+
checkDirtiness _ps@(PSLocal _lp) Executable _package _present = do
294+
{- FIXME proper dirtiness checking on executables
331295
ctx <- ask
332296
mtime <- packageSourceCabalModTime ps
333297
let configOpts = configureOpts
@@ -343,15 +307,16 @@ checkDirtiness ps@(PSLocal lp) Executable package present = do
343307
}
344308
let moldOpts = lpLastConfigOpts lp
345309
case moldOpts of
346-
Nothing -> return $ Just AllSteps
310+
Nothing -> return True
347311
Just oldOpts
348-
| oldOpts /= configCache -> return $ Just AllSteps
312+
| oldOpts /= configCache -> return True
349313
| psDirty ps -> return $ Just SkipConfig
350314
| otherwise -> return Nothing
351-
checkDirtiness (PSUpstream _ _ _) Executable _ _ = return Nothing -- TODO reinstall executables in the future
315+
-}
316+
return False
317+
checkDirtiness (PSUpstream _ _ _) Executable _ _ = return False -- TODO reinstall executables in the future
352318
checkDirtiness ps (Library installed) package present = do
353319
ctx <- ask
354-
mtime <- packageSourceCabalModTime ps
355320
let configOpts = configureOpts
356321
(baseConfigOpts ctx)
357322
present
@@ -361,17 +326,19 @@ checkDirtiness ps (Library installed) package present = do
361326
configCache = ConfigCache
362327
{ configCacheOpts = map encodeUtf8 configOpts
363328
, configCacheDeps = present
364-
, configCabalFileModTime = mtime
329+
, configCabalFileModTime = Nothing
365330
}
366-
moldOpts <- psOldOpts ps installed
331+
moldOpts <- tryGetFlagCache installed
367332
case moldOpts of
368-
Nothing -> return $ Just AllSteps
333+
Nothing -> return True
369334
Just oldOpts
370-
| oldOpts /= configCache -> return $ Just AllSteps
371-
| psDirty ps -> return $ Just SkipConfig
335+
| oldOpts /= configCache -> return True
336+
| psDirty ps -> return True
372337
| otherwise -> do
373338
case ps of
339+
{- FIXME need to track finals completely differently now
374340
PSLocal lp | lpWanted lp -> do
341+
375342
-- track the fact that we need to perform a JustFinal. But
376343
-- don't put this in the main State Map, as that would
377344
-- trigger dependencies to rebuild also.
@@ -386,17 +353,14 @@ checkDirtiness ps (Library installed) package present = do
386353
}
387354
tell (Map.singleton (packageName package) task, Map.empty)
388355
-- FIXME need to force reconfigure when GhcPkgId for dependencies change
356+
-}
389357
_ -> return ()
390-
return Nothing
358+
return False
391359

392360
psDirty :: PackageSource -> Bool
393361
psDirty (PSLocal lp) = lpDirtyFiles lp
394362
psDirty (PSUpstream _ _ _) = False -- files never change in an upstream package
395363

396-
psOldOpts :: PackageSource -> GhcPkgId -> M (Maybe ConfigCache)
397-
psOldOpts (PSLocal lp) _ = return $ lpLastConfigOpts lp
398-
psOldOpts (PSUpstream _ _ _) installed = tryGetFlagCache installed
399-
400364
psWanted :: PackageSource -> Bool
401365
psWanted (PSLocal lp) = lpWanted lp
402366
psWanted (PSUpstream _ _ _) = False

0 commit comments

Comments
 (0)