Skip to content

Commit

Permalink
Merge pull request #6211 from commercialhaskell/re6184
Browse files Browse the repository at this point in the history
Re #6184 Minor refactoring/reformatting
  • Loading branch information
mpilgrem authored Aug 16, 2023
2 parents f177e65 + 90e3fd8 commit e9f3fb7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
20 changes: 9 additions & 11 deletions src/Stack/Build/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import qualified Distribution.PackageDescription as C
import qualified Pantry.SHA256 as SHA256
import Stack.Build.Cache ( tryGetBuildCache )
import Stack.Build.Haddock ( shouldHaddockDeps )
import Stack.FileDigestCache ( readFileDigest )
import Stack.Package ( resolvePackage )
import Stack.Prelude
import Stack.SourceMap
Expand All @@ -48,6 +47,7 @@ import Stack.Types.EnvConfig
( EnvConfig (..), HasEnvConfig (..), HasSourceMap (..)
, actualCompilerVersionL
)
import Stack.Types.FileDigestCache ( readFileDigest )
import Stack.Types.NamedComponent
( NamedComponent (..), isCInternalLib )
import Stack.Types.Package
Expand Down Expand Up @@ -436,20 +436,21 @@ loadLocalPackage pp = do

-- | Compare the current filesystem state to the cached information, and
-- determine (1) if the files are dirty, and (2) the new cache values.
checkBuildCache :: HasEnvConfig env
=> Map FilePath FileCacheInfo -- ^ old cache
-> [Path Abs File] -- ^ files in package
-> RIO env (Set FilePath, Map FilePath FileCacheInfo)
checkBuildCache ::
HasEnvConfig env
=> Map FilePath FileCacheInfo -- ^ old cache
-> [Path Abs File] -- ^ files in package
-> RIO env (Set FilePath, Map FilePath FileCacheInfo)
checkBuildCache oldCache files = do
fileTimes <- fmap Map.fromList $ forM files $ \fp -> do
fileDigests <- fmap Map.fromList $ forM files $ \fp -> do
mdigest <- getFileDigestMaybe (toFilePath fp)
pure (toFilePath fp, mdigest)
fmap (mconcat . Map.elems) $ sequence $
Map.merge
(Map.mapMissing (\fp mdigest -> go fp mdigest Nothing))
(Map.mapMissing (\fp fci -> go fp Nothing (Just fci)))
(Map.zipWithMatched (\fp mdigest fci -> go fp mdigest (Just fci)))
fileTimes
fileDigests
oldCache
where
go :: FilePath
Expand Down Expand Up @@ -524,10 +525,7 @@ getFileDigestMaybe fp = do
cache <- view $ envConfigL.to envConfigFileDigestCache
catch
(Just <$> readFileDigest cache fp)
(\e ->
if isDoesNotExistError e
then pure Nothing
else throwM e)
(\e -> if isDoesNotExistError e then pure Nothing else throwM e)

-- | Get 'PackageConfig' for package given its name.
getPackageConfig ::
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ import Stack.Constants
, relFileStackDotTmpDotExe, stackProgName, usrLibDirs
)
import Stack.Constants.Config ( distRelativeDir )
import Stack.FileDigestCache ( newFileDigestCache )
import Stack.GhcPkg
( createDatabase, getGlobalDB, ghcPkgPathEnvVar
, mkGhcPackagePath )
Expand Down Expand Up @@ -147,6 +146,7 @@ import Stack.Types.EnvConfig
)
import Stack.Types.EnvSettings ( EnvSettings (..), minimalEnvSettings )
import Stack.Types.ExtraDirs ( ExtraDirs (..) )
import Stack.Types.FileDigestCache ( newFileDigestCache )
import Stack.Types.GHCDownloadInfo ( GHCDownloadInfo (..) )
import Stack.Types.GHCVariant
( GHCVariant (..), HasGHCVariant (..), ghcVariantName
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Types/EnvConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import Stack.Constants
, relDirHoogle, relDirHpc, relDirInstall, relDirPkgdb
, relDirSnapshots, relFileDatabaseHoo
)
import Stack.FileDigestCache (FileDigestCache)
import Stack.Prelude
import Stack.Types.BuildConfig
( BuildConfig (..), HasBuildConfig (..), getProjectWorkDir )
Expand All @@ -53,6 +52,7 @@ import Stack.Types.CompilerBuild ( compilerBuildSuffix )
import Stack.Types.CompilerPaths
( CompilerPaths (..), HasCompiler (..) )
import Stack.Types.Config ( HasConfig (..), stackRootL )
import Stack.Types.FileDigestCache ( FileDigestCache )
import Stack.Types.GHCVariant ( HasGHCVariant (..), ghcVariantSuffix )
import Stack.Types.Platform
( HasPlatform (..), platformVariantSuffix )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
module Stack.FileDigestCache
{-# LANGUAGE NoImplicitPrelude #-}

module Stack.Types.FileDigestCache
( FileDigestCache
, newFileDigestCache
, readFileDigest
) where

import Stack.Prelude
import qualified Data.Map.Strict as Map
import Stack.Prelude
import qualified Pantry.SHA256 as SHA256

-- | Type synonym representing caches of digests of files.
type FileDigestCache = IORef (Map FilePath SHA256)

newFileDigestCache :: MonadIO m => m FileDigestCache
Expand Down
4 changes: 2 additions & 2 deletions stack.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.0

-- This file has been generated from package.yaml by hpack version 0.35.2.
-- This file has been generated from package.yaml by hpack version 0.35.4.
--
-- see: https://github.com/sol/hpack

Expand Down Expand Up @@ -322,7 +322,7 @@ library
Paths_stack
other-modules:
Stack.Config.ConfigureScript
Stack.FileDigestCache
Stack.Types.FileDigestCache
autogen-modules:
Build_stack
Paths_stack
Expand Down

0 comments on commit e9f3fb7

Please sign in to comment.