diff --git a/ChangeLog.md b/ChangeLog.md index 99dd39dcb5..737dd19720 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,6 +4,9 @@ Release notes: +* The hash used as a key for Stack's pre-compiled package cache has changed, + following the dropping of support for Cabal versions older than `1.24.0.0`. + **Changes since v2.13.1:** Major changes: diff --git a/src/Stack/Build/Cache.hs b/src/Stack/Build/Cache.hs index 8386e80f61..0b50773580 100644 --- a/src/Stack/Build/Cache.hs +++ b/src/Stack/Build/Cache.hs @@ -341,13 +341,13 @@ getTestStatus dir = do -- -- We only pay attention to non-directory options. We don't want to avoid a -- cache hit just because it was installed in a different directory. -getPrecompiledCacheKey :: HasEnvConfig env - => PackageLocationImmutable - -> ConfigureOpts - -> Bool -- ^ build haddocks - -> Set GhcPkgId -- ^ dependencies - -> RIO env PrecompiledCacheKey -getPrecompiledCacheKey loc copts buildHaddocks installedPackageIDs = do +getPrecompiledCacheKey :: + HasEnvConfig env + => PackageLocationImmutable + -> ConfigureOpts + -> Bool -- ^ build haddocks + -> RIO env PrecompiledCacheKey +getPrecompiledCacheKey loc copts buildHaddocks = do compiler <- view actualCompilerVersionL cabalVersion <- view cabalVersionL @@ -359,28 +359,27 @@ getPrecompiledCacheKey loc copts buildHaddocks installedPackageIDs = do platformGhcDir <- platformGhcRelDir -- In Cabal versions 1.22 and later, the configure options contain the - -- installed package IDs, which is what we need for a unique hash. - -- Unfortunately, earlier Cabals don't have the information, so we must - -- supplement it with the installed package IDs directly. - -- See issue: https://github.com/commercialhaskell/stack/issues/1103 - let input = (coNoDirs copts, installedPackageIDs) + -- installed package IDs, which is what we need for a unique hash. See also + -- issue: https://github.com/commercialhaskell/stack/issues/1103 + let input = coNoDirs copts optionsHash = Mem.convert $ hashWith SHA256 $ encodeUtf8 $ tshow input - pure $ precompiledCacheKey platformGhcDir compiler cabalVersion packageKey optionsHash buildHaddocks + pure $ precompiledCacheKey + platformGhcDir compiler cabalVersion packageKey optionsHash buildHaddocks -- | Write out information about a newly built package -writePrecompiledCache :: HasEnvConfig env - => BaseConfigOpts - -> PackageLocationImmutable - -> ConfigureOpts - -> Bool -- ^ build haddocks - -> Set GhcPkgId -- ^ dependencies - -> Installed -- ^ library - -> [GhcPkgId] -- ^ sublibraries, in the GhcPkgId format - -> Set Text -- ^ executables - -> RIO env () -writePrecompiledCache baseConfigOpts loc copts buildHaddocks depIDs mghcPkgId sublibs exes = do - key <- getPrecompiledCacheKey loc copts buildHaddocks depIDs +writePrecompiledCache :: + HasEnvConfig env + => BaseConfigOpts + -> PackageLocationImmutable + -> ConfigureOpts + -> Bool -- ^ build haddocks + -> Installed -- ^ library + -> [GhcPkgId] -- ^ sublibraries, in the GhcPkgId format + -> Set Text -- ^ executables + -> RIO env () +writePrecompiledCache baseConfigOpts loc copts buildHaddocks mghcPkgId sublibs exes = do + key <- getPrecompiledCacheKey loc copts buildHaddocks ec <- view envConfigL let stackRootRelative = makeRelative (view stackRootL ec) mlibpath <- case mghcPkgId of @@ -399,23 +398,22 @@ writePrecompiledCache baseConfigOpts loc copts buildHaddocks depIDs mghcPkgId su -- reuse precompiled cache with haddocks also in case when haddocks are not -- required when buildHaddocks $ do - key' <- getPrecompiledCacheKey loc copts False depIDs + key' <- getPrecompiledCacheKey loc copts False savePrecompiledCache key' precompiled where pathFromPkgId stackRootRelative ipid = do ipid' <- parseRelFile $ ghcPkgIdString ipid ++ ".conf" stackRootRelative $ bcoSnapDB baseConfigOpts ipid' --- | Check the cache for a precompiled package matching the given --- configuration. -readPrecompiledCache :: forall env. HasEnvConfig env - => PackageLocationImmutable -- ^ target package - -> ConfigureOpts - -> Bool -- ^ build haddocks - -> Set GhcPkgId -- ^ dependencies - -> RIO env (Maybe (PrecompiledCache Abs)) -readPrecompiledCache loc copts buildHaddocks depIDs = do - key <- getPrecompiledCacheKey loc copts buildHaddocks depIDs +-- | Check the cache for a precompiled package matching the given configuration. +readPrecompiledCache :: + forall env. HasEnvConfig env + => PackageLocationImmutable -- ^ target package + -> ConfigureOpts + -> Bool -- ^ build haddocks + -> RIO env (Maybe (PrecompiledCache Abs)) +readPrecompiledCache loc copts buildHaddocks = do + key <- getPrecompiledCacheKey loc copts buildHaddocks mcache <- loadPrecompiledCache key maybe (pure Nothing) (fmap Just . mkAbs) mcache where diff --git a/src/Stack/Build/Execute.hs b/src/Stack/Build/Execute.hs index 40aab48446..5223492924 100644 --- a/src/Stack/Build/Execute.hs +++ b/src/Stack/Build/Execute.hs @@ -1719,7 +1719,6 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap loc (configCacheOpts cache) (configCacheHaddock cache) - (configCacheDeps cache) case mpc of Nothing -> pure Nothing -- Only pay attention to precompiled caches that refer to packages @@ -2071,7 +2070,6 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap loc (configCacheOpts cache) (configCacheHaddock cache) - (configCacheDeps cache) mpkgid sublibsPkgIds (packageExes package) _ -> pure ()