Skip to content

Commit ddc76ce

Browse files
snoybergtswelsh
authored andcommitted
Do correct path checking in precompiled cache.
The commit ed9ccc0 changed the behavior of the precompiled cache to store relative instead of absolute paths. That seems to have broken the ability to properly check if a library exists, thereby defeating precompiled caching. The issue that discovered this is commercialhaskell#3431, and ascribed this to extensible snapshots. I _think_, though I'm not 100% certain, that this bug reaches much farther than extensible snapshots, and in fact breaks all precompiled caches.
1 parent 33ca57d commit ddc76ce

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ Bug fixes:
148148
* `stack build --only-dependencies` no longer builds local project packages
149149
that are depended on. See
150150
[#3476](https://github.com/commercialhaskell/stack/issues/3476).
151+
* Properly handle relative paths stored in the precompiled cache files. See
152+
[#3431](https://github.com/commercialhaskell/stack/issues/3431).
151153

152154

153155
## 1.5.1

src/Stack/Build/Cache.hs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module Stack.Build.Cache
3434

3535
import Stack.Prelude
3636
import Crypto.Hash (hashWith, SHA256(..))
37+
import Control.Monad.Trans.Maybe
3738
import qualified Data.ByteArray as Mem (convert)
3839
import qualified Data.ByteString.Base64.URL as B64URL
3940
import qualified Data.ByteString as B
@@ -55,6 +56,7 @@ import Stack.Types.GhcPkgId
5556
import Stack.Types.Package
5657
import Stack.Types.PackageIdentifier
5758
import Stack.Types.Version
59+
import qualified System.FilePath as FP
5860

5961
-- | Directory containing files to mark an executable as installed
6062
exeInstalledDir :: (MonadReader env m, HasEnvConfig env, MonadThrow m)
@@ -313,11 +315,27 @@ writePrecompiledCache baseConfigOpts loc copts depIDs mghcPkgId exes = do
313315

314316
-- | Check the cache for a precompiled package matching the given
315317
-- configuration.
316-
readPrecompiledCache :: (MonadThrow m, MonadReader env m, HasEnvConfig env, MonadUnliftIO m, MonadLogger m)
318+
readPrecompiledCache :: forall env. HasEnvConfig env
317319
=> PackageLocationIndex FilePath -- ^ target package
318320
-> ConfigureOpts
319321
-> Set GhcPkgId -- ^ dependencies
320-
-> m (Maybe PrecompiledCache)
321-
readPrecompiledCache loc copts depIDs =
322-
precompiledCacheFile loc copts depIDs >>=
323-
maybe (return Nothing) $(versionedDecodeFile precompiledCacheVC)
322+
-> RIO env (Maybe PrecompiledCache)
323+
readPrecompiledCache loc copts depIDs = runMaybeT $
324+
MaybeT (precompiledCacheFile loc copts depIDs) >>=
325+
MaybeT . $(versionedDecodeFile precompiledCacheVC) >>=
326+
lift . mkAbs
327+
where
328+
-- Since commit ed9ccc08f327bad68dd2d09a1851ce0d055c0422,
329+
-- pcLibrary paths are stored as relative to the stack
330+
-- root. Therefore, we need to prepend the stack root when
331+
-- checking that the file exists. For the older cached paths, the
332+
-- file will contain an absolute path, which will make `stackRoot
333+
-- </>` a no-op.
334+
mkAbs :: PrecompiledCache -> RIO env PrecompiledCache
335+
mkAbs pc0 = do
336+
stackRoot <- view stackRootL
337+
let mkAbs' = (toFilePath stackRoot FP.</>)
338+
return PrecompiledCache
339+
{ pcLibrary = mkAbs' <$> pcLibrary pc0
340+
, pcExes = mkAbs' <$> pcExes pc0
341+
}

0 commit comments

Comments
 (0)