Skip to content

Commit

Permalink
Minor reformatting of signatures, for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Feb 9, 2025
1 parent 33485f2 commit 0cf403e
Show file tree
Hide file tree
Showing 25 changed files with 379 additions and 284 deletions.
15 changes: 8 additions & 7 deletions src/GHC/Utils/GhcPkg/Main/Compat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,14 @@ unregisterPackages globalDb pkgargs pkgDb = do
where
-- Update a list of 'packages by package database' for a package. Assumes that
-- a package to be unregistered is in no more than one database.
getPkgsByPkgDBs :: [(PackageDB GhcPkg.DbReadWrite, [UnitId])]
-- ^ List of considered 'packages by package database'
-> [(PackageDB GhcPkg.DbReadWrite, [UnitId])]
-- ^ List of to be considered 'packages by package database'
-> PackageArg
-- Package to update
-> RIO env [(PackageDB GhcPkg.DbReadWrite, [UnitId])]
getPkgsByPkgDBs ::
[(PackageDB GhcPkg.DbReadWrite, [UnitId])]
-- ^ List of considered 'packages by package database'
-> [(PackageDB GhcPkg.DbReadWrite, [UnitId])]
-- ^ List of to be considered 'packages by package database'
-> PackageArg
-- Package to update
-> RIO env [(PackageDB GhcPkg.DbReadWrite, [UnitId])]
-- No more 'packages by package database' to consider? We need to try to get
-- another package database.
getPkgsByPkgDBs pkgsByPkgDBs [] pkgarg =
Expand Down
21 changes: 13 additions & 8 deletions src/Network/HTTP/StackClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,24 @@ setGitHubHeaders = setRequestHeader "Accept" ["application/vnd.github.v3+json"]
-- appropriate destination.
--
-- Throws an exception if things go wrong
download :: HasTerm env
=> Request
-> Path Abs File -- ^ destination
-> RIO env Bool -- ^ Was a downloaded performed (True) or did the file already exist (False)?
download ::
HasTerm env
=> Request
-> Path Abs File
-- ^ destination
-> RIO env Bool
-- ^ Was a downloaded performed (True) or did the file already exist
-- (False)?
download req = Download.download (setUserAgent req)

-- | Same as 'download', but will download a file a second time if it is already present.
--
-- Returns 'True' if the file was downloaded, 'False' otherwise
redownload :: HasTerm env
=> Request
-> Path Abs File -- ^ destination
-> RIO env Bool
redownload ::
HasTerm env
=> Request
-> Path Abs File -- ^ destination
-> RIO env Bool
redownload req = Download.redownload (setUserAgent req)

-- | Copied and extended version of Network.HTTP.Download.download.
Expand Down
62 changes: 33 additions & 29 deletions src/Path/Find.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,36 @@ import System.PosixCompat.Files
( getSymbolicLinkStatus, isSymbolicLink )

-- | Find the location of a file matching the given predicate.
findFileUp :: (MonadIO m, MonadThrow m)
=> Path Abs Dir -- ^ Start here.
-> (Path Abs File -> Bool) -- ^ Predicate to match the file.
-> Maybe (Path Abs Dir) -- ^ Do not ascend above this directory.
-> m (Maybe (Path Abs File)) -- ^ Absolute file path.
findFileUp ::
(MonadIO m, MonadThrow m)
=> Path Abs Dir -- ^ Start here.
-> (Path Abs File -> Bool) -- ^ Predicate to match the file.
-> Maybe (Path Abs Dir) -- ^ Do not ascend above this directory.
-> m (Maybe (Path Abs File)) -- ^ Absolute file path.
findFileUp = findPathUp snd

-- | Find the location of a directory matching the given predicate.
findDirUp :: (MonadIO m,MonadThrow m)
=> Path Abs Dir -- ^ Start here.
-> (Path Abs Dir -> Bool) -- ^ Predicate to match the directory.
-> Maybe (Path Abs Dir) -- ^ Do not ascend above this directory.
-> m (Maybe (Path Abs Dir)) -- ^ Absolute directory path.
findDirUp ::
(MonadIO m,MonadThrow m)
=> Path Abs Dir -- ^ Start here.
-> (Path Abs Dir -> Bool) -- ^ Predicate to match the directory.
-> Maybe (Path Abs Dir) -- ^ Do not ascend above this directory.
-> m (Maybe (Path Abs Dir)) -- ^ Absolute directory path.
findDirUp = findPathUp fst

-- | Find the location of a path matching the given predicate.
findPathUp :: (MonadIO m,MonadThrow m)
=> (([Path Abs Dir],[Path Abs File]) -> [Path Abs t])
-- ^ Choose path type from pair.
-> Path Abs Dir
-- ^ Start here.
-> (Path Abs t -> Bool)
-- ^ Predicate to match the path.
-> Maybe (Path Abs Dir)
-- ^ Do not ascend above this directory.
-> m (Maybe (Path Abs t))
-- ^ Absolute path.
findPathUp ::
(MonadIO m,MonadThrow m)
=> (([Path Abs Dir],[Path Abs File]) -> [Path Abs t])
-- ^ Choose path type from pair.
-> Path Abs Dir
-- ^ Start here.
-> (Path Abs t -> Bool)
-- ^ Predicate to match the path.
-> Maybe (Path Abs Dir)
-- ^ Do not ascend above this directory.
-> m (Maybe (Path Abs t))
-- ^ Absolute path.
findPathUp pathType dir p upperBound = do
entries <- listDir dir
case L.find p (pathType entries) of
Expand All @@ -61,14 +64,15 @@ findPathUp pathType dir p upperBound = do
--
-- TODO: write one of these that traverses symbolic links but
-- efficiently ignores loops.
findFiles :: Path Abs Dir
-- ^ Root directory to begin with.
-> (Path Abs File -> Bool)
-- ^ Predicate to match files.
-> (Path Abs Dir -> Bool)
-- ^ Predicate for which directories to traverse.
-> IO [Path Abs File]
-- ^ List of matching files.
findFiles ::
Path Abs Dir
-- ^ Root directory to begin with.
-> (Path Abs File -> Bool)
-- ^ Predicate to match files.
-> (Path Abs Dir -> Bool)
-- ^ Predicate for which directories to traverse.
-> IO [Path Abs File]
-- ^ List of matching files.
findFiles dir p traversep = do
(dirs,files) <- catchJust (\ e -> if isPermissionError e
then Just ()
Expand Down
103 changes: 61 additions & 42 deletions src/Stack/Build/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,18 @@ import System.PosixCompat.Files
( getFileStatus, modificationTime, setFileTimes )

-- | Directory containing files to mark an executable as installed
exeInstalledDir :: (HasEnvConfig env)
=> InstallLocation -> RIO env (Path Abs Dir)
exeInstalledDir ::
(HasEnvConfig env)
=> InstallLocation
-> RIO env (Path Abs Dir)
exeInstalledDir Snap = (</> relDirInstalledPackages) <$> installationRootDeps
exeInstalledDir Local = (</> relDirInstalledPackages) <$> installationRootLocal

-- | Get all of the installed executables
getInstalledExes :: (HasEnvConfig env)
=> InstallLocation -> RIO env [PackageIdentifier]
getInstalledExes ::
(HasEnvConfig env)
=> InstallLocation
-> RIO env [PackageIdentifier]
getInstalledExes loc = do
dir <- exeInstalledDir loc
(_, files) <- liftIO $ handleIO (const $ pure ([], [])) $ listDir dir
Expand All @@ -104,8 +108,11 @@ getInstalledExes loc = do
mapMaybe (parsePackageIdentifier . toFilePath . filename) files

-- | Mark the given executable as installed
markExeInstalled :: (HasEnvConfig env)
=> InstallLocation -> PackageIdentifier -> RIO env ()
markExeInstalled ::
(HasEnvConfig env)
=> InstallLocation
-> PackageIdentifier
-> RIO env ()
markExeInstalled loc ident = do
dir <- exeInstalledDir loc
ensureDir dir
Expand All @@ -121,17 +128,21 @@ markExeInstalled loc ident = do
writeBinaryFileAtomic fp "Installed"

-- | Mark the given executable as not installed
markExeNotInstalled :: (HasEnvConfig env)
=> InstallLocation -> PackageIdentifier -> RIO env ()
markExeNotInstalled ::
(HasEnvConfig env)
=> InstallLocation
-> PackageIdentifier
-> RIO env ()
markExeNotInstalled loc ident = do
dir <- exeInstalledDir loc
ident' <- parseRelFile $ packageIdentifierString ident
liftIO $ ignoringAbsence (removeFile $ dir </> ident')

buildCacheFile :: (HasEnvConfig env, MonadReader env m, MonadThrow m)
=> Path Abs Dir
-> NamedComponent
-> m (Path Abs File)
buildCacheFile ::
(HasEnvConfig env, MonadReader env m, MonadThrow m)
=> Path Abs Dir
-> NamedComponent
-> m (Path Abs File)
buildCacheFile dir component = do
cachesDir <- buildCachesDir dir
smh <- view $ envConfigL . to (.sourceMapHash)
Expand All @@ -140,10 +151,11 @@ buildCacheFile dir component = do
pure $ cachesDir </> smDirName </> cacheFileName

-- | Try to read the dirtiness cache for the given package directory.
tryGetBuildCache :: HasEnvConfig env
=> Path Abs Dir
-> NamedComponent
-> RIO env (Maybe (Map FilePath FileCacheInfo))
tryGetBuildCache ::
HasEnvConfig env
=> Path Abs Dir
-> NamedComponent
-> RIO env (Maybe (Map FilePath FileCacheInfo))
tryGetBuildCache dir component = do
fp <- buildCacheFile dir component
ensureDir $ parent fp
Expand Down Expand Up @@ -197,27 +209,30 @@ tryReadFileBinary fp =
tryIO (readFileBinary fp)

-- | Write the dirtiness cache for this package's files.
writeBuildCache :: HasEnvConfig env
=> Path Abs Dir
-> NamedComponent
-> Map FilePath FileCacheInfo -> RIO env ()
writeBuildCache ::
HasEnvConfig env
=> Path Abs Dir
-> NamedComponent
-> Map FilePath FileCacheInfo -> RIO env ()
writeBuildCache dir component times = do
fp <- toFilePath <$> buildCacheFile dir component
liftIO $ Yaml.encodeFile fp BuildCache { times = times }

-- | Write the dirtiness cache for this package's configuration.
writeConfigCache :: HasEnvConfig env
=> Path Abs Dir
-> ConfigCache
-> RIO env ()
writeConfigCache ::
HasEnvConfig env
=> Path Abs Dir
-> ConfigCache
-> RIO env ()
writeConfigCache dir =
saveConfigCache (configCacheKey dir ConfigCacheTypeConfig)

-- | See 'tryGetCabalMod'
writeCabalMod :: HasEnvConfig env
=> Path Abs Dir
-> CTime
-> RIO env ()
writeCabalMod ::
HasEnvConfig env
=> Path Abs Dir
-> CTime
-> RIO env ()
writeCabalMod dir x = do
fp <- configCabalMod dir
writeBinaryFileAtomic fp "Just used for its modification time"
Expand Down Expand Up @@ -267,17 +282,19 @@ flagCacheKey installed = do
configCacheKey installationRoot (ConfigCacheTypeFlagExecutable ident)

-- | Loads the flag cache for the given installed extra-deps
tryGetFlagCache :: HasEnvConfig env
=> Installed
-> RIO env (Maybe ConfigCache)
tryGetFlagCache ::
HasEnvConfig env
=> Installed
-> RIO env (Maybe ConfigCache)
tryGetFlagCache gid = do
key <- flagCacheKey gid
loadConfigCache key

writeFlagCache :: HasEnvConfig env
=> Installed
-> ConfigCache
-> RIO env ()
writeFlagCache ::
HasEnvConfig env
=> Installed
-> ConfigCache
-> RIO env ()
writeFlagCache gid cache = do
key <- flagCacheKey gid
saveConfigCache key cache
Expand All @@ -294,10 +311,11 @@ data TestStatus
| TSUnknown

-- | Mark test suite status
setTestStatus :: HasEnvConfig env
=> Path Abs Dir
-> TestStatus
-> RIO env ()
setTestStatus ::
HasEnvConfig env
=> Path Abs Dir
-> TestStatus
-> RIO env ()
setTestStatus dir status = do
fp <- testSuccessFile dir
writeBinaryFileAtomic fp $
Expand All @@ -307,9 +325,10 @@ setTestStatus dir status = do
TSUnknown -> unknownBS

-- | Check if the test suite already passed
getTestStatus :: HasEnvConfig env
=> Path Abs Dir
-> RIO env TestStatus
getTestStatus ::
HasEnvConfig env
=> Path Abs Dir
-> RIO env TestStatus
getTestStatus dir = do
fp <- testSuccessFile dir
-- we could ensure the file is the right size first, but we're not expected an
Expand Down
16 changes: 9 additions & 7 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,11 @@ tellExecutablesPackage loc p = do

-- | Given a 'PackageSource' and perhaps an 'Installed' value, adds build
-- 'Task's for the package and its dependencies.
installPackage :: PackageName
-> PackageSource
-> Maybe Installed
-> M (Either ConstructPlanException AddDepRes)
installPackage ::
PackageName
-> PackageSource
-> Maybe Installed
-> M (Either ConstructPlanException AddDepRes)
installPackage name ps minstalled = do
ctx <- ask
case ps of
Expand Down Expand Up @@ -1234,9 +1235,10 @@ logDebugPlanS s msg = do
-- value; and (2) a pair of an 'InstallLocation' value and an 'Installed' value.
-- Checks that the version of the 'PackageSource' value and the version of the
-- `Installed` value are the same.
combineSourceInstalled :: PackageSource
-> (InstallLocation, Installed)
-> PackageInfo
combineSourceInstalled ::
PackageSource
-> (InstallLocation, Installed)
-> PackageInfo
combineSourceInstalled ps (location, installed) =
assert (psVersion ps == installedVersion installed) $
case location of
Expand Down
Loading

0 comments on commit 0cf403e

Please sign in to comment.