Skip to content

Commit 6b52d99

Browse files
committed
Use flag cache for executables too
1 parent 7d1649e commit 6b52d99

File tree

5 files changed

+26
-46
lines changed

5 files changed

+26
-46
lines changed

src/Stack/Build/Cache.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,19 @@ writeCache dir get' content = do
149149
(Binary.encode content))
150150

151151
flagCacheFile :: (MonadIO m, MonadThrow m, MonadReader env m, HasBuildConfig env)
152-
=> GhcPkgId
152+
=> Installed
153153
-> m (Path Abs File)
154-
flagCacheFile gid = do
155-
rel <- parseRelFile $ ghcPkgIdString gid
154+
flagCacheFile installed = do
155+
rel <- parseRelFile $
156+
case installed of
157+
Library gid -> ghcPkgIdString gid
158+
Executable ident -> packageIdentifierString ident
156159
dir <- flagCacheLocal
157160
return $ dir </> rel
158161

159162
-- | Loads the flag cache for the given installed extra-deps
160163
tryGetFlagCache :: (MonadIO m, MonadThrow m, MonadReader env m, HasBuildConfig env)
161-
=> GhcPkgId
164+
=> Installed
162165
-> m (Maybe ConfigCache)
163166
tryGetFlagCache gid = do
164167
file <- flagCacheFile gid
@@ -168,7 +171,7 @@ tryGetFlagCache gid = do
168171
_ -> return Nothing
169172

170173
writeFlagCache :: (MonadIO m, MonadReader env m, HasBuildConfig env, MonadThrow m)
171-
=> GhcPkgId
174+
=> Installed
172175
-> [ByteString]
173176
-> Set GhcPkgId
174177
-> m ()

src/Stack/Build/ConstructPlan.hs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ addPackageDeps package = do
270270
return $ Left (depname, (range, DependencyMismatch $ adrVersion adr))
271271
Right (ADRToInstall task) -> return $ Right
272272
(Set.singleton $ taskProvides task, Set.empty)
273-
Right (ADRFound _ Executable) -> return $ Right
273+
Right (ADRFound _ (Executable _)) -> return $ Right
274274
(Set.empty, Set.empty)
275275
Right (ADRFound _ (Library gid)) -> return $ Right
276276
(Set.empty, Set.singleton gid)
@@ -290,32 +290,7 @@ checkDirtiness :: PackageSource
290290
-> Package
291291
-> Set GhcPkgId
292292
-> M Bool
293-
checkDirtiness _ps@(PSLocal _lp) Executable _package _present = do
294-
{- FIXME proper dirtiness checking on executables
295-
ctx <- ask
296-
mtime <- packageSourceCabalModTime ps
297-
let configOpts = configureOpts
298-
(baseConfigOpts ctx)
299-
present
300-
(psWanted ps)
301-
(piiLocation ps) -- should be Local always
302-
(packageFlags package)
303-
configCache = ConfigCache
304-
{ configCacheOpts = map encodeUtf8 configOpts
305-
, configCacheDeps = present
306-
, configCabalFileModTime = mtime
307-
}
308-
let moldOpts = lpLastConfigOpts lp
309-
case moldOpts of
310-
Nothing -> return True
311-
Just oldOpts
312-
| oldOpts /= configCache -> return True
313-
| psDirty ps -> return $ Just SkipConfig
314-
| otherwise -> return Nothing
315-
-}
316-
return False
317-
checkDirtiness (PSUpstream _ _ _) Executable _ _ = return False -- TODO reinstall executables in the future
318-
checkDirtiness ps (Library installed) package present = do
293+
checkDirtiness ps installed package present = do
319294
ctx <- ask
320295
let configOpts = configureOpts
321296
(baseConfigOpts ctx)

src/Stack/Build/Execute.hs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ singleBuild ActionContext {..} ExecuteEnv {..} task@Task {..} =
301301
case Map.lookup ident idMap of
302302
Nothing -> error "singleBuild: invariant violated, missing package ID missing"
303303
Just (Library x) -> Just x
304-
Just Executable -> Nothing
304+
Just (Executable _) -> Nothing
305305
missing' = Set.fromList $ mapMaybe getMissing $ Set.toList missing
306306
TaskConfigOpts missing mkOpts = taskConfigOpts
307307
configOpts = mkOpts missing'
@@ -347,15 +347,16 @@ singleBuild ActionContext {..} ExecuteEnv {..} task@Task {..} =
347347
mpkgid <- findGhcPkgId eeEnvOverride pkgDbs (packageName package)
348348
mpkgid' <- case (packageHasLibrary package, mpkgid) of
349349
(False, _) -> assert (isNothing mpkgid) $ do
350-
markExeInstalled (taskLocation task) taskProvides -- FIXME this should also take the options, deps, etc
351-
return Executable
350+
markExeInstalled (taskLocation task) taskProvides -- TODO unify somehow with writeFlagCache?
351+
return $ Executable $ PackageIdentifier
352+
(packageName package)
353+
(packageVersion package)
352354
(True, Nothing) -> throwM $ Couldn'tFindPkgId $ packageName package
353-
(True, Just pkgid) -> do
354-
writeFlagCache
355-
pkgid
356-
(map encodeUtf8 configOpts)
357-
allDeps
358-
return $ Library pkgid
355+
(True, Just pkgid) -> return $ Library pkgid
356+
writeFlagCache
357+
mpkgid'
358+
(map encodeUtf8 configOpts)
359+
allDeps
359360
liftIO $ atomically $ modifyTVar eeGhcPkgIds $ Map.insert taskProvides mpkgid'
360361
where
361362
announce x = $logInfo $ T.concat

src/Stack/Build/Installed.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ type M env m = (MonadIO m,MonadReader env m,HasHttpManager env,HasBuildConfig en
4141
data LoadHelper = LoadHelper
4242
{ lhId :: !GhcPkgId
4343
, lhDeps :: ![GhcPkgId]
44-
, lhPair :: !(PackageName, (Version, Location, Installed))
44+
, lhPair :: !(PackageName, (Version, Location, Installed)) -- TODO Version is now redundant and can be gleaned from Installed
4545
}
4646
deriving Show
4747

48-
type InstalledMap = Map PackageName (Version, Location, Installed)
49-
data Installed = Library GhcPkgId | Executable
50-
deriving (Show, Eq, Ord)
48+
type InstalledMap = Map PackageName (Version, Location, Installed) -- TODO Version is now redundant and can be gleaned from Installed
5149

5250
-- | Returns the new InstalledMap and all of the locally registered packages.
5351
getInstalled :: (M env m, PackageInstallInfo pii)
@@ -103,7 +101,7 @@ getInstalled menv profiling sourceMap = do
103101
-- Passed all the tests, mark this as installed!
104102
_ -> m
105103
where
106-
m = Map.singleton name (version, loc, Executable)
104+
m = Map.singleton name (version, loc, Executable $ PackageIdentifier name version)
107105
exesSnap <- getInstalledExes Snap
108106
exesLocal <- getInstalledExes Local
109107
let installedMap = Map.unions

src/Stack/Build/Types.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,6 @@ modTime x =
447447
(utctDay x)
448448
, toRational
449449
(utctDayTime x))
450+
451+
data Installed = Library GhcPkgId | Executable PackageIdentifier
452+
deriving (Show, Eq, Ord)

0 commit comments

Comments
 (0)