Skip to content

Commit 13a7d4b

Browse files
authored
Merge pull request #3494 from commercialhaskell/3431-fix-precompiled-cache-checks
Do correct path checking in precompiled cache.
2 parents 08e4d02 + 7b5bfbc commit 13a7d4b

File tree

7 files changed

+48
-5
lines changed

7 files changed

+48
-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+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import StackTest
2+
import Control.Monad
3+
import Data.List
4+
5+
main :: IO ()
6+
main = do
7+
stack ["build", "stm", "--stack-yaml", "custom1/stack.yaml"]
8+
stackCheckStderr ["build", "stm", "--stack-yaml", "custom2/stack.yaml"] $ \out ->
9+
unless ("precompiled" `isInfixOf` out) $ error "Didn't use precompiled!"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resolver: ghc-8.2.1
2+
name: custom1
3+
packages:
4+
- stm-2.4.4.1
5+
- acme-missiles-0.3
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
resolver: custom1.yaml
2+
packages: []
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resolver: ghc-8.2.1
2+
name: custom2
3+
packages:
4+
- stm-2.4.4.1
5+
- acme-missiles-0.2
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
resolver: custom2.yaml
2+
packages: []

0 commit comments

Comments
 (0)