From 90e3fd8d2fe73b35a10cf177602dad6f21c10056 Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Wed, 16 Aug 2023 21:33:47 +0100 Subject: [PATCH] Re #6184 Minor refactoring/reformatting --- src/Stack/Build/Source.hs | 20 +++++++++----------- src/Stack/Setup.hs | 2 +- src/Stack/Types/EnvConfig.hs | 2 +- src/Stack/{ => Types}/FileDigestCache.hs | 7 +++++-- stack.cabal | 4 ++-- 5 files changed, 18 insertions(+), 17 deletions(-) rename src/Stack/{ => Types}/FileDigestCache.hs (83%) diff --git a/src/Stack/Build/Source.hs b/src/Stack/Build/Source.hs index 649064a00e..f60c326abb 100644 --- a/src/Stack/Build/Source.hs +++ b/src/Stack/Build/Source.hs @@ -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 @@ -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 @@ -436,12 +436,13 @@ 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 $ @@ -449,7 +450,7 @@ checkBuildCache oldCache files = do (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 @@ -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 :: diff --git a/src/Stack/Setup.hs b/src/Stack/Setup.hs index 6f6bfcf2e2..0fe2398b7f 100644 --- a/src/Stack/Setup.hs +++ b/src/Stack/Setup.hs @@ -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 ) @@ -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 diff --git a/src/Stack/Types/EnvConfig.hs b/src/Stack/Types/EnvConfig.hs index 766895e254..dd6d3ba9b3 100644 --- a/src/Stack/Types/EnvConfig.hs +++ b/src/Stack/Types/EnvConfig.hs @@ -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 ) @@ -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 ) diff --git a/src/Stack/FileDigestCache.hs b/src/Stack/Types/FileDigestCache.hs similarity index 83% rename from src/Stack/FileDigestCache.hs rename to src/Stack/Types/FileDigestCache.hs index b4becd0d96..5c11f4d93c 100644 --- a/src/Stack/FileDigestCache.hs +++ b/src/Stack/Types/FileDigestCache.hs @@ -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 diff --git a/stack.cabal b/stack.cabal index bcf21236be..634c9b61c2 100644 --- a/stack.cabal +++ b/stack.cabal @@ -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 @@ -322,7 +322,7 @@ library Paths_stack other-modules: Stack.Config.ConfigureScript - Stack.FileDigestCache + Stack.Types.FileDigestCache autogen-modules: Build_stack Paths_stack