Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the paths stored in precompiled-cache Stack-root relative #2215

Merged
merged 1 commit into from
Jun 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/Stack/Build/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import Path
import Path.IO
import Stack.Constants
import Stack.Types
import qualified System.FilePath as FilePath

-- | Directory containing files to mark an executable as installed
exeInstalledDir :: (MonadReader env m, HasEnvConfig env, MonadThrow m)
Expand Down Expand Up @@ -306,15 +307,19 @@ writePrecompiledCache :: (MonadThrow m, MonadReader env m, HasEnvConfig env, Mon
writePrecompiledCache baseConfigOpts pkgident copts depIDs mghcPkgId exes = do
(file, _) <- precompiledCacheFile pkgident copts depIDs
ensureDir (parent file)
ec <- asks getEnvConfig
let stackRootRelative = makeRelative (getStackRoot ec)
mlibpath <-
case mghcPkgId of
Executable _ -> return Nothing
Library _ ipid -> liftM Just $ do
ipid' <- parseRelFile $ ghcPkgIdString ipid ++ ".conf"
return $ toFilePath $ bcoSnapDB baseConfigOpts </> ipid'
relPath <- stackRootRelative $ bcoSnapDB baseConfigOpts </> ipid'
return $ toFilePath $ relPath
exes' <- forM (Set.toList exes) $ \exe -> do
name <- parseRelFile $ T.unpack exe
return $ toFilePath $ bcoSnapInstallRoot baseConfigOpts </> bindirSuffix </> name
relPath <- stackRootRelative $ bcoSnapInstallRoot baseConfigOpts </> bindirSuffix </> name
return $ toFilePath $ relPath
taggedEncodeFile file PrecompiledCache
{ pcLibrary = mlibpath
, pcExes = exes'
Expand All @@ -328,14 +333,25 @@ readPrecompiledCache :: (MonadThrow m, MonadReader env m, HasEnvConfig env, Mona
-> Set GhcPkgId -- ^ dependencies
-> m (Maybe PrecompiledCache)
readPrecompiledCache pkgident copts depIDs = do
ec <- asks getEnvConfig
let toAbsPath path = do
if FilePath.isAbsolute path
then path -- Only older version store absolute path
else toFilePath (getStackRoot ec) FilePath.</> path
let toAbsPC pc =
PrecompiledCache
{ pcLibrary = fmap toAbsPath (pcLibrary pc)
, pcExes = map toAbsPath (pcExes pc)
}

(file, getOldFile) <- precompiledCacheFile pkgident copts depIDs
mres <- decodeFileMaybe file
case mres of
Just res -> return (Just res)
Just res -> return (Just $ toAbsPC res)
Nothing -> do
-- Fallback on trying the old binary format.
oldFile <- getOldFile
mpc <- binaryDecodeFileOrFailDeep oldFile
mpc <- fmap (fmap toAbsPC) $ binaryDecodeFileOrFailDeep oldFile
-- Write out file in new format. Keep old file around for
-- the benefit of older stack versions.
forM_ mpc (taggedEncodeFile file)
Expand Down