Skip to content

Commit 3103ebe

Browse files
committed
Merge pull request commercialhaskell#2215 from kernelim/precompiled-cache-rel
Make the paths stored in precompiled-cache Stack-root relative
2 parents fb3f1d2 + ed9ccc0 commit 3103ebe

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/Stack/Build/Cache.hs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import Path
6666
import Path.IO
6767
import Stack.Constants
6868
import Stack.Types
69+
import qualified System.FilePath as FilePath
6970

7071
-- | Directory containing files to mark an executable as installed
7172
exeInstalledDir :: (MonadReader env m, HasEnvConfig env, MonadThrow m)
@@ -306,15 +307,19 @@ writePrecompiledCache :: (MonadThrow m, MonadReader env m, HasEnvConfig env, Mon
306307
writePrecompiledCache baseConfigOpts pkgident copts depIDs mghcPkgId exes = do
307308
(file, _) <- precompiledCacheFile pkgident copts depIDs
308309
ensureDir (parent file)
310+
ec <- asks getEnvConfig
311+
let stackRootRelative = makeRelative (getStackRoot ec)
309312
mlibpath <-
310313
case mghcPkgId of
311314
Executable _ -> return Nothing
312315
Library _ ipid -> liftM Just $ do
313316
ipid' <- parseRelFile $ ghcPkgIdString ipid ++ ".conf"
314-
return $ toFilePath $ bcoSnapDB baseConfigOpts </> ipid'
317+
relPath <- stackRootRelative $ bcoSnapDB baseConfigOpts </> ipid'
318+
return $ toFilePath $ relPath
315319
exes' <- forM (Set.toList exes) $ \exe -> do
316320
name <- parseRelFile $ T.unpack exe
317-
return $ toFilePath $ bcoSnapInstallRoot baseConfigOpts </> bindirSuffix </> name
321+
relPath <- stackRootRelative $ bcoSnapInstallRoot baseConfigOpts </> bindirSuffix </> name
322+
return $ toFilePath $ relPath
318323
taggedEncodeFile file PrecompiledCache
319324
{ pcLibrary = mlibpath
320325
, pcExes = exes'
@@ -328,14 +333,25 @@ readPrecompiledCache :: (MonadThrow m, MonadReader env m, HasEnvConfig env, Mona
328333
-> Set GhcPkgId -- ^ dependencies
329334
-> m (Maybe PrecompiledCache)
330335
readPrecompiledCache pkgident copts depIDs = do
336+
ec <- asks getEnvConfig
337+
let toAbsPath path = do
338+
if FilePath.isAbsolute path
339+
then path -- Only older version store absolute path
340+
else toFilePath (getStackRoot ec) FilePath.</> path
341+
let toAbsPC pc =
342+
PrecompiledCache
343+
{ pcLibrary = fmap toAbsPath (pcLibrary pc)
344+
, pcExes = map toAbsPath (pcExes pc)
345+
}
346+
331347
(file, getOldFile) <- precompiledCacheFile pkgident copts depIDs
332348
mres <- decodeFileMaybe file
333349
case mres of
334-
Just res -> return (Just res)
350+
Just res -> return (Just $ toAbsPC res)
335351
Nothing -> do
336352
-- Fallback on trying the old binary format.
337353
oldFile <- getOldFile
338-
mpc <- binaryDecodeFileOrFailDeep oldFile
354+
mpc <- fmap (fmap toAbsPC) $ binaryDecodeFileOrFailDeep oldFile
339355
-- Write out file in new format. Keep old file around for
340356
-- the benefit of older stack versions.
341357
forM_ mpc (taggedEncodeFile file)

0 commit comments

Comments
 (0)