Skip to content

Commit

Permalink
Merge pull request #7743 from peterbecich/type-annotations
Browse files Browse the repository at this point in the history
Type annotations
  • Loading branch information
mergify[bot] authored Oct 12, 2021
2 parents 69f6228 + f07c922 commit 69dbf54
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 9 deletions.
6 changes: 6 additions & 0 deletions cabal-install/src/Distribution/Client/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,13 @@ planLocalPackage verbosity comp platform configFlags configExFlags
srcpkgDescrOverride = Nothing
}

testsEnabled :: Bool
testsEnabled = fromFlagOrDefault False $ configTests configFlags
benchmarksEnabled :: Bool
benchmarksEnabled =
fromFlagOrDefault False $ configBenchmarks configFlags

resolverParams :: DepResolverParams
resolverParams =
removeLowerBounds
(fromMaybe (AllowOlder mempty) $ configAllowOlder configExFlags)
Expand Down Expand Up @@ -392,7 +395,9 @@ configurePackage verbosity platform comp scriptOptions configFlags
scriptOptions (Just pkg) configureCommand configureFlags (const extraArgs)

where
gpkg :: PkgDesc.GenericPackageDescription
gpkg = srcpkgDescription spkg
configureFlags :: Version -> ConfigFlags
configureFlags = filterConfigureFlags configFlags {
configIPID = if isJust (flagToMaybe (configIPID configFlags))
-- Make sure cabal configure --ipid works.
Expand Down Expand Up @@ -420,6 +425,7 @@ configurePackage verbosity platform comp scriptOptions configFlags
`mappend` configTests configFlags
}

pkg :: PkgDesc.PackageDescription
pkg = case finalizePD flags (enableStanzas stanzas)
(const True)
platform comp [] gpkg of
Expand Down
36 changes: 35 additions & 1 deletion cabal-install/src/Distribution/Client/DistDirLayout.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Prelude ()
import System.FilePath

import Distribution.Package
( PackageId, ComponentId, UnitId )
( PackageId, PackageIdentifier, ComponentId, UnitId )
import Distribution.Compiler
import Distribution.Simple.Compiler
( PackageDB(..), PackageDBStack, OptimisationLevel(..) )
Expand Down Expand Up @@ -182,14 +182,21 @@ defaultDistDirLayout projectRoot mdistDirectory =
ProjectRootImplicit dir -> (dir, dir </> "cabal.project")
ProjectRootExplicit dir file -> (dir, dir </> file)

distProjectRootDirectory :: FilePath
distProjectRootDirectory = projectRootDir

distProjectFile :: String -> FilePath
distProjectFile ext = projectFile <.> ext

distDirectory :: FilePath
distDirectory = distProjectRootDirectory
</> fromMaybe "dist-newstyle" mdistDirectory
--TODO: switch to just dist at some point, or some other new name

distBuildRootDirectory :: FilePath
distBuildRootDirectory = distDirectory </> "build"

distBuildDirectory :: DistDirParams -> FilePath
distBuildDirectory params =
distBuildRootDirectory </>
prettyShow (distParamPlatform params) </>
Expand All @@ -212,52 +219,76 @@ defaultDistDirLayout projectRoot mdistDirectory =
then ""
else uid_str)

distUnpackedSrcRootDirectory :: FilePath
distUnpackedSrcRootDirectory = distDirectory </> "src"

distUnpackedSrcDirectory :: PackageId -> FilePath
distUnpackedSrcDirectory pkgid = distUnpackedSrcRootDirectory
</> prettyShow pkgid
-- we shouldn't get name clashes so this should be fine:
distDownloadSrcDirectory :: FilePath
distDownloadSrcDirectory = distUnpackedSrcRootDirectory

distProjectCacheDirectory :: FilePath
distProjectCacheDirectory = distDirectory </> "cache"

distProjectCacheFile :: FilePath -> FilePath
distProjectCacheFile name = distProjectCacheDirectory </> name

distPackageCacheDirectory :: DistDirParams -> FilePath
distPackageCacheDirectory params = distBuildDirectory params </> "cache"

distPackageCacheFile :: DistDirParams -> String -> FilePath
distPackageCacheFile params name = distPackageCacheDirectory params </> name

distSdistFile :: PackageIdentifier -> FilePath
distSdistFile pid = distSdistDirectory </> prettyShow pid <.> "tar.gz"

distSdistDirectory :: FilePath
distSdistDirectory = distDirectory </> "sdist"

distTempDirectory :: FilePath
distTempDirectory = distDirectory </> "tmp"

distBinDirectory :: FilePath
distBinDirectory = distDirectory </> "bin"

distPackageDBPath :: CompilerId -> FilePath
distPackageDBPath compid = distDirectory </> "packagedb" </> prettyShow compid

distPackageDB :: CompilerId -> PackageDB
distPackageDB = SpecificPackageDB . distPackageDBPath


defaultStoreDirLayout :: FilePath -> StoreDirLayout
defaultStoreDirLayout storeRoot =
StoreDirLayout {..}
where
storeDirectory :: CompilerId -> FilePath
storeDirectory compid =
storeRoot </> prettyShow compid

storePackageDirectory :: CompilerId -> UnitId -> FilePath
storePackageDirectory compid ipkgid =
storeDirectory compid </> prettyShow ipkgid

storePackageDBPath :: CompilerId -> FilePath
storePackageDBPath compid =
storeDirectory compid </> "package.db"

storePackageDB :: CompilerId -> PackageDB
storePackageDB compid =
SpecificPackageDB (storePackageDBPath compid)

storePackageDBStack :: CompilerId -> PackageDBStack
storePackageDBStack compid =
[GlobalPackageDB, storePackageDB compid]

storeIncomingDirectory :: CompilerId -> FilePath
storeIncomingDirectory compid =
storeDirectory compid </> "incoming"

storeIncomingLock :: CompilerId -> UnitId -> FilePath
storeIncomingLock compid unitid =
storeIncomingDirectory compid </> prettyShow unitid <.> "lock"

Expand All @@ -273,7 +304,10 @@ mkCabalDirLayout :: FilePath -- ^ Cabal directory
mkCabalDirLayout cabalDir mstoreDir mlogDir =
CabalDirLayout {..}
where
cabalStoreDirLayout :: StoreDirLayout
cabalStoreDirLayout =
defaultStoreDirLayout (fromMaybe (cabalDir </> "store") mstoreDir)
cabalLogsDirectory :: FilePath
cabalLogsDirectory = fromMaybe (cabalDir </> "logs") mlogDir
cabalWorldFile :: FilePath
cabalWorldFile = cabalDir </> "world"
7 changes: 6 additions & 1 deletion cabal-install/src/Distribution/Client/Get.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,19 @@ get verbosity repoCtxt globalFlags getFlags userTargets = do
else unpack pkgs

where
resolverParams :: SourcePackageDb -> [PackageSpecifier UnresolvedSourcePackage] -> DepResolverParams
resolverParams sourcePkgDb pkgSpecifiers =
--TODO: add command-line constraint and preference args for unpack
standardInstallPolicy mempty sourcePkgDb pkgSpecifiers

prefix :: String
prefix = fromFlagOrDefault "" (getDestDir getFlags)

clone :: [UnresolvedSourcePackage] -> IO ()
clone = clonePackagesFromSourceRepo verbosity prefix kind
. map (\pkg -> (packageId pkg, packageSourceRepos pkg))
where
kind :: Maybe RepoKind
kind = fromFlag . getSourceRepository $ getFlags
packageSourceRepos :: SourcePackage loc -> [PD.SourceRepo]
packageSourceRepos = PD.sourceRepos
Expand Down Expand Up @@ -140,6 +143,7 @@ get verbosity repoCtxt globalFlags getFlags userTargets = do
LocalUnpackedPackage _ ->
error "Distribution.Client.Get.unpack: the impossible happened."
where
usePristine :: Bool
usePristine = fromFlagOrDefault False (getPristine getFlags)

checkTarget :: Verbosity -> UserTarget -> IO ()
Expand Down Expand Up @@ -291,7 +295,8 @@ clonePackagesFromSourceRepo verbosity destDirPrefix
Left SourceRepoLocationUnspecified ->
throwIO (ClonePackageNoRepoLocation pkgid repo)

let destDir = destDirPrefix </> prettyShow (packageName pkgid)
let destDir :: FilePath
destDir = destDirPrefix </> prettyShow (packageName pkgid)
destDirExists <- doesDirectoryExist destDir
destFileExists <- doesFileExist destDir
when (destDirExists || destFileExists) $
Expand Down
1 change: 1 addition & 0 deletions cabal-install/src/Distribution/Client/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ regenerateHaddockIndex verbosity pkgs progdb index = do

where
(destDir,destFile) = splitFileName index
pkgs' :: [InstalledPackageInfo]
pkgs' = [ maximumBy (comparing packageVersion) pkgvers'
| (_pname, pkgvers) <- allPackagesByName pkgs
, let pkgvers' = filter exposed pkgvers
Expand Down
10 changes: 10 additions & 0 deletions cabal-install/src/Distribution/Client/ProjectConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,12 @@ resolveBuildTimeSettings verbosity
-- If the user has specified --remote-build-reporting=detailed or
-- --build-log, use more verbose logging.
--
buildSettingLogVerbosity :: Verbosity
buildSettingLogVerbosity
| overrideVerbosity = modifyVerbosity (max verbose) verbosity
| otherwise = verbosity

overrideVerbosity :: Bool
overrideVerbosity
| buildSettingBuildReports == DetailedReports = True
| isJust givenTemplate = True
Expand Down Expand Up @@ -419,6 +421,7 @@ findProjectRoot mstartdir mprojectFile = do
homedir <- getHomeDirectory
probe startdir homedir
where
projectFileName :: String
projectFileName = fromMaybe "cabal.project" mprojectFile

-- Search upwards. If we get to the users home dir or the filesystem root,
Expand Down Expand Up @@ -528,6 +531,7 @@ readProjectLocalConfigOrDefault verbosity distDirLayout = do
return defaultImplicitProjectConfig

where
projectFile :: FilePath
projectFile = distProjectFile distDirLayout ""

defaultImplicitProjectConfig :: ProjectConfig
Expand Down Expand Up @@ -575,13 +579,16 @@ readProjectFile verbosity DistDirLayout{distProjectFile}
else do monitorFiles [monitorNonExistentFile extensionFile]
return mempty
where
extensionFile :: FilePath
extensionFile = distProjectFile extensionName

readExtensionFile :: IO ProjectConfig
readExtensionFile =
reportParseResult verbosity extensionDescription extensionFile
. (parseProjectConfig extensionFile)
=<< BS.readFile extensionFile

addProjectFileProvenance :: ProjectConfig -> ProjectConfig
addProjectFileProvenance config =
config {
projectConfigProvenance =
Expand Down Expand Up @@ -811,6 +818,7 @@ findProjectPackages DistDirLayout{distProjectRootDirectory}

return (concat [requiredPkgs, optionalPkgs, repoPkgs, namedPkgs])
where
findPackageLocations :: Bool -> [String] -> Rebuild [ProjectPackageLocation]
findPackageLocations required pkglocstr = do
(problems, pkglocs) <-
partitionEithers <$> traverse (findPackageLocation required) pkglocstr
Expand Down Expand Up @@ -1110,8 +1118,10 @@ fetchAndReadSourcePackageRemoteTarball verbosity
. uncurry (readSourcePackageCabalFile verbosity)
=<< extractTarballPackageCabalFile tarballFile
where
tarballStem :: FilePath
tarballStem = distDownloadSrcDirectory
</> localFileNameForRemoteTarball tarballUri
tarballFile :: FilePath
tarballFile = tarballStem <.> "tar.gz"

monitor :: FileMonitor URI (PackageSpecifier (SourcePackage UnresolvedPkgLoc))
Expand Down
1 change: 1 addition & 0 deletions cabal-install/src/Distribution/Client/ProjectPlanOutput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
, "install-plan" J..= installPlanToJ elaboratedInstallPlan
]
where
plat :: Platform
plat@(Platform arch os) = pkgConfigPlatform elaboratedSharedConfig

installPlanToJ :: ElaboratedInstallPlan -> [J.Value]
Expand Down
1 change: 1 addition & 0 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ rebuildInstallPlan verbosity
die' verbosity msg
Right plan -> return (plan, pkgConfigDB, tis, ar)
where
corePackageDbs :: [PackageDB]
corePackageDbs = [GlobalPackageDB]
withRepoCtx = projectConfigWithSolverRepoContext verbosity
projectConfigShared
Expand Down
12 changes: 8 additions & 4 deletions cabal-install/src/Distribution/Client/Reconfigure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ reconfigure
-- verbosity should be used if reconfiguring.
checkVerb :: Check (ConfigFlags, b)
checkVerb = Check $ \_ (configFlags, configExFlags) -> do
let configFlags' = configFlags { configVerbosity = toFlag verbosity}
let configFlags' :: ConfigFlags
configFlags' = configFlags { configVerbosity = toFlag verbosity}
return (mempty, (configFlags', configExFlags))

-- Reconfiguration is required if @--build-dir@ changes.
Expand All @@ -148,14 +149,17 @@ reconfigure
-- Always set the chosen @--build-dir@ before saving the flags,
-- or bad things could happen.
savedDist <- findSavedDistPref config (configDistPref configFlags)
let distChanged = dist /= savedDist
let distChanged :: Bool
distChanged = dist /= savedDist
when distChanged $ info verbosity "build directory changed"
let configFlags' = configFlags { configDistPref = toFlag dist }
let configFlags' :: ConfigFlags
configFlags' = configFlags { configDistPref = toFlag dist }
return (Any distChanged, (configFlags', configExFlags))

checkOutdated :: Check (ConfigFlags, b)
checkOutdated = Check $ \_ flags@(configFlags, _) -> do
let buildConfig = localBuildInfoFile dist
let buildConfig :: FilePath
buildConfig = localBuildInfoFile dist

-- Has the package ever been configured? If not, reconfiguration is
-- required.
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/SourceFiles.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ needBuildInfo pkg_descr bi modules = do
findFileMonitored ("." : includeDirs bi) f
>>= maybe (return ()) need
where
findNeededModules :: [String] -> Rebuild ()
findNeededModules exts = traverse_
(findNeededModule exts)
(modules ++ otherModules bi)
findNeededModule :: [String] -> ModuleName -> Rebuild ()
findNeededModule exts m =
findFileWithExtensionMonitored
(ppSuffixes knownSuffixHandlers ++ exts)
Expand Down
4 changes: 3 additions & 1 deletion cabal-install/src/Distribution/Client/SrcDist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ packageDirToSdist verbosity gpd dir = do
thisDie v s = die' v $ "sdist of " <> prettyShow (packageId gpd) ++ ": " ++ s

files' <- listPackageSourcesWithDie verbosity thisDie dir (flattenPackageDescription gpd) knownSuffixHandlers
let files = nub $ sort $ map normalise files'
let files :: [FilePath]
files = nub $ sort $ map normalise files'

let entriesM :: StateT (Set.Set FilePath) (WriterT [Tar.Entry] IO) ()
entriesM = do
Expand Down Expand Up @@ -91,5 +92,6 @@ packageDirToSdist verbosity gpd dir = do
-- Windows; we need a post-1980 date. One gigasecond
-- after the epoch is during 2001-09-09, so that does
-- nicely. See #5596.
setModTime :: Tar.Entry -> Tar.Entry
setModTime entry = entry { Tar.entryTime = 1000000000 }
return . normalize . GZip.compress . Tar.write $ fmap setModTime entries
7 changes: 5 additions & 2 deletions cabal-install/src/Distribution/Client/Targets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ readUserTarget targetstr =
parentDirExists <- case takeDirectory filename of
[] -> return False
dir -> doesDirectoryExist dir
let result
let result :: Maybe (Either UserTargetProblem UserTarget)
result
| isDir
= Just (Right (UserTargetLocalDir filename))

Expand Down Expand Up @@ -239,6 +240,7 @@ readUserTarget targetstr =
Just (Right (UserTargetRemoteTarball uri))
_ -> Nothing

extensionIsTarGz :: FilePath -> Bool
extensionIsTarGz f = takeExtension f == ".gz"
&& takeExtension (dropExtension f) == ".tar"

Expand Down Expand Up @@ -317,10 +319,11 @@ resolveUserTargets verbosity repoCtxt worldFile available userTargets = do

-- users are allowed to give package names case-insensitively, so we must
-- disambiguate named package references
let (problems, packageSpecifiers) =
let (problems, packageSpecifiers) :: ([PackageTargetProblem], [PackageSpecifier UnresolvedSourcePackage]) =
disambiguatePackageTargets available availableExtra packageTargets

-- use any extra specific available packages to help us disambiguate
availableExtra :: [PackageName]
availableExtra = [ packageName pkg
| PackageTargetLocation pkg <- packageTargets ]

Expand Down
Loading

0 comments on commit 69dbf54

Please sign in to comment.