Skip to content

Commit

Permalink
Migrate some remains of code to use Cabal types/functions
Browse files Browse the repository at this point in the history
  • Loading branch information
qrilka committed Aug 23, 2018
1 parent 903b5b8 commit 3211dd5
Show file tree
Hide file tree
Showing 26 changed files with 157 additions and 271 deletions.
2 changes: 0 additions & 2 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,12 @@ library:
- Stack.Types.Config
- Stack.Types.Config.Build
- Stack.Types.Docker
- Stack.Types.FlagName
- Stack.Types.GhcPkgId
- Stack.Types.Image
- Stack.Types.NamedComponent
- Stack.Types.Nix
- Stack.Types.Package
- Stack.Types.PackageDump
- Stack.Types.PackageIdentifier
- Stack.Types.PackageName
- Stack.Types.PrettyPrint
- Stack.Types.Resolver
Expand Down
6 changes: 3 additions & 3 deletions src/Stack/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import qualified Data.Text.IO as TIO
import Data.Text.Read (decimal)
import qualified Data.Vector as V
import qualified Data.Yaml as Yaml
import Distribution.Version (mkVersion)
import Path (parent)
import Stack.Build.ConstructPlan
import Stack.Build.Execute
Expand All @@ -48,7 +49,6 @@ import Stack.Types.Build
import Stack.Types.Config
import Stack.Types.NamedComponent
import Stack.Types.Package
import Stack.Types.Version

import Stack.Types.Compiler (compilerVersionText
#ifdef WINDOWS
Expand Down Expand Up @@ -152,7 +152,7 @@ checkCabalVersion = do
allowNewer <- view $ configL.to configAllowNewer
cabalVer <- view cabalVersionL
-- https://github.com/haskell/cabal/issues/2023
when (allowNewer && cabalVer < $(mkVersion "1.22")) $ throwM $
when (allowNewer && cabalVer < mkVersion [1, 22]) $ throwM $
CabalVersionException $
"Error: --allow-newer requires at least Cabal version 1.22, but version " ++
versionString cabalVer ++
Expand Down Expand Up @@ -293,7 +293,7 @@ fixCodePage :: HasEnvConfig env => RIO env a -> RIO env a
fixCodePage inner = do
mcp <- view $ configL.to configModifyCodePage
ghcVersion <- view $ actualCompilerVersionL.to getGhcVersion
if mcp && ghcVersion < $(mkVersion "7.10.3")
if mcp && ghcVersion < mkVersion [7, 10, 3]
then fixCodePage'
-- GHC >=7.10.3 doesn't need this code page hack.
else inner
Expand Down
9 changes: 5 additions & 4 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import Data.Text.Encoding.Error (lenientDecode)
import qualified Distribution.Text as Cabal
import qualified Distribution.Version as Cabal
import Distribution.Types.BuildType (BuildType (Configure))
import Distribution.Types.PackageName (mkPackageName)
import Distribution.Version (mkVersion)
import Generics.Deriving.Monoid (memptydefault, mappenddefault)
import Path (parent)
import qualified RIO
Expand All @@ -50,7 +52,6 @@ import Stack.Types.Config
import Stack.Types.GhcPkgId
import Stack.Types.NamedComponent
import Stack.Types.Package
import Stack.Types.PackageName
import Stack.Types.Runner
import Stack.Types.Version
import System.IO (putStrLn)
Expand Down Expand Up @@ -225,7 +226,7 @@ constructPlan ls0 baseConfigOpts0 locals extraToBuild0 localDumpPkgs loadPackage
throwM $ ConstructPlanFailed "Plan construction failed."
where
hasBaseInDeps bconfig =
$(mkPackageName "base") `elem`
mkPackageName "base" `elem`
[n | (PLImmutable (PLIHackage (PackageIdentifierRevision n _ _) _)) <- bcDependencies bconfig]

mkCtx econfig = Ctx
Expand Down Expand Up @@ -956,7 +957,7 @@ pprintExceptions exceptions stackYaml stackRoot parentMap wanted =

addExtraDepsRecommendations
| Map.null extras = []
| (Just _) <- Map.lookup $(mkPackageName "base") extras =
| (Just _) <- Map.lookup (mkPackageName "base") extras =
[ " *" <+> align (flow "Build requires unattainable version of base. Since base is a part of GHC, you most likely need to use a different GHC version with the matching base.")
, line
]
Expand Down Expand Up @@ -1097,7 +1098,7 @@ getShortestDepsPath (MonoidMap parentsMap) wanted name =
-- search of dependencies.
findShortest :: Int -> Map PackageName DepsPath -> [PackageIdentifier]
findShortest fuel _ | fuel <= 0 =
[PackageIdentifier $(mkPackageName "stack-ran-out-of-jet-fuel") $(mkVersion "0")]
[PackageIdentifier (mkPackageName "stack-ran-out-of-jet-fuel") (mkVersion [0])]
findShortest _ paths | M.null paths = []
findShortest fuel paths =
case targets of
Expand Down
15 changes: 8 additions & 7 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import qualified Distribution.Simple.Build.Macros as C
import Distribution.System (OS (Windows),
Platform (Platform))
import qualified Distribution.Text as C
import Distribution.Types.PackageName (mkPackageName)
import Distribution.Version (mkVersion)
import Path
import Path.CheckInstall
import Path.Extra (toFilePathNoTrailingSep, rejectMissingFile)
Expand All @@ -82,7 +84,6 @@ import Stack.Types.Config
import Stack.Types.GhcPkgId
import Stack.Types.NamedComponent
import Stack.Types.Package
import Stack.Types.PackageName
import Stack.Types.Runner
import Stack.Types.Version
import qualified System.Directory as D
Expand Down Expand Up @@ -838,7 +839,7 @@ ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task =
deleteCaches pkgDir
announce
let programNames =
if eeCabalPkgVer < $(mkVersion "1.22")
if eeCabalPkgVer < mkVersion [1, 22]
then ["ghc", "ghc-pkg"]
else ["ghc", "ghc-pkg", "ghcjs", "ghcjs-pkg"]
exes <- forM programNames $ \name -> do
Expand Down Expand Up @@ -1024,7 +1025,7 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} mdeps msuffi
-- Omit cabal package dependency when building
-- Cabal. See
-- https://github.com/commercialhaskell/stack/issues/1356
| packageName package == $(mkPackageName "Cabal") = []
| packageName package == mkPackageName "Cabal" = []
| otherwise =
["-package=" ++ packageIdentifierString
(PackageIdentifier cabalPackageName
Expand Down Expand Up @@ -1059,7 +1060,7 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} mdeps msuffi
-- explicit list of dependencies, and we
-- should simply use all of them.
(Just customSetupDeps, _) -> do
unless (Map.member $(mkPackageName "Cabal") customSetupDeps) $
unless (Map.member (mkPackageName "Cabal") customSetupDeps) $
prettyWarnL
[ fromString $ packageNameString $ packageName package
, "has a setup-depends field, but it does not mention a Cabal dependency. This is likely to cause build errors."
Expand Down Expand Up @@ -1525,7 +1526,7 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap
let quickjump =
case actualCompiler of
ACGhc ghcVer
| ghcVer >= $(mkVersion "8.4") -> ["--haddock-option=--quickjump"]
| ghcVer >= mkVersion [8, 4] -> ["--haddock-option=--quickjump"]
_ -> []

cabal KeepTHLoading $ concat
Expand Down Expand Up @@ -1928,7 +1929,7 @@ mungeBuildOutput excludeTHLoading makeAbsolute pkgDir compilerVer = void $
filterLinkerWarnings
-- Check for ghc 7.8 since it's the only one prone to producing
-- linker warnings on Windows x64
| getGhcVersion compilerVer >= $(mkVersion "7.8") = doNothing
| getGhcVersion compilerVer >= mkVersion [7, 8] = doNothing
| otherwise = CL.filter (not . isLinkerWarning)

isLinkerWarning :: Text -> Bool
Expand Down Expand Up @@ -2101,7 +2102,7 @@ addGlobalPackages deps globals0 =
----------------------------------

-- Is the given package identifier for any version of Cabal
isCabal (PackageIdentifier name _) = name == $(mkPackageName "Cabal")
isCabal (PackageIdentifier name _) = name == mkPackageName "Cabal"

-- Is the given package name provided by the package dependencies?
isDep dp = pkgName (dpPackageIdent dp) `Set.member` depNames
Expand Down
1 change: 0 additions & 1 deletion src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ import Stack.Snapshot
import Stack.Types.Config
import Stack.Types.Docker
import Stack.Types.Nix
import Stack.Types.PackageName (PackageName)
import Stack.Types.Resolver
import Stack.Types.Runner
import Stack.Types.Urls
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ module Stack.Constants

import Data.Char (toUpper)
import qualified Data.Set as Set
import Distribution.Package (mkPackageName)
import Path as FL
import Stack.Prelude
import Stack.Types.Compiler
import Stack.Types.PackageName

-- | Extensions used for Haskell modules. Excludes preprocessor ones.
haskellFileExts :: [Text]
Expand Down Expand Up @@ -164,7 +164,7 @@ ghcjsBootPackages =
-- | Just to avoid repetition and magic strings.
cabalPackageName :: PackageName
cabalPackageName =
$(mkPackageName "Cabal")
mkPackageName "Cabal"

-- | Deprecated implicit global project directory used when outside of a project.
implicitGlobalProjectDirDeprecated :: Path Abs Dir -- ^ Stack root.
Expand Down
8 changes: 4 additions & 4 deletions src/Stack/Coverage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Lazy as LT
import Distribution.Version (mkVersion)
import Path
import Path.Extra (toFilePathNoTrailingSep)
import Path.IO
Expand All @@ -42,7 +43,6 @@ import Stack.Types.Config
import Stack.Types.NamedComponent
import Stack.Types.Package
import Stack.Types.Runner
import Stack.Types.Version
import System.FilePath (isPathSeparator)
import qualified RIO
import RIO.Process
Expand Down Expand Up @@ -110,15 +110,15 @@ generateHpcReport pkgDir package tests = do
internalLibs = packageInternalLibraries package
eincludeName <-
-- Pre-7.8 uses plain PKG-version in tix files.
if ghcVersion < $(mkVersion "7.10") then return $ Right $ Just [pkgId]
if ghcVersion < mkVersion [7, 10] then return $ Right $ Just [pkgId]
-- We don't expect to find a package key if there is no library.
else if not hasLibrary && Set.null internalLibs then return $ Right Nothing
-- Look in the inplace DB for the package key.
-- See https://github.com/commercialhaskell/stack/issues/1181#issuecomment-148968986
else do
-- GHC 8.0 uses package id instead of package key.
-- See https://github.com/commercialhaskell/stack/issues/2424
let hpcNameField = if ghcVersion >= $(mkVersion "8.0") then "id" else "key"
let hpcNameField = if ghcVersion >= mkVersion [8, 0] then "id" else "key"
eincludeName <- findPackageFieldForBuiltPackage pkgDir (packageIdentifier package) internalLibs hpcNameField
case eincludeName of
Left err -> do
Expand Down Expand Up @@ -440,7 +440,7 @@ findPackageFieldForBuiltPackage pkgDir pkgId internalLibs field = do
Just result -> return $ Right result
Nothing -> notFoundErr
cabalVer <- view cabalVersionL
if cabalVer < $(mkVersion "1.24")
if cabalVer < mkVersion [1, 24]
then do
-- here we don't need to handle internal libs
path <- liftM (inplaceDir </>) $ parseRelFile (pkgIdStr ++ "-inplace.conf")
Expand Down
3 changes: 2 additions & 1 deletion src/Stack/Docker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Data.Time (UTCTime,LocalTime(..),diffDays,utcToLocalTime,getZonedTime,ZonedTime(..))
import Data.Version (showVersion)
import Distribution.Version (mkVersion)
import GHC.Exts (sortWith)
import Path
import Path.Extra (toFilePathNoTrailingSep)
Expand Down Expand Up @@ -706,7 +707,7 @@ checkDockerVersion docker =
return ()
_ -> throwIO InvalidVersionOutputException
_ -> throwIO InvalidVersionOutputException
where minimumDockerVersion = $(mkVersion "1.6.0")
where minimumDockerVersion = mkVersion [1, 6, 0]
prohibitedDockerVersions = []
stripVersion v = takeWhile (/= '-') (dropWhileEnd (not . isDigit) v)

Expand Down
4 changes: 2 additions & 2 deletions src/Stack/Dot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import qualified Data.Traversable as T
import Distribution.Text (display)
import qualified Distribution.SPDX.License as SPDX
import Distribution.License (License(BSD3), licenseFromSPDX)
import Distribution.Types.PackageName (mkPackageName)
import Stack.Build (loadPackage)
import Stack.Build.Installed (getInstalled, GetInstalledOpts(..))
import Stack.Build.Source
Expand All @@ -38,7 +39,6 @@ import Stack.Types.Build
import Stack.Types.Config
import Stack.Types.GhcPkgId
import Stack.Types.Package
import Stack.Types.PackageName

-- | Options record for @stack dot@
data DotOpts = DotOpts
Expand Down Expand Up @@ -123,7 +123,7 @@ createDependencyGraph dotOpts = do
loadPackageDeps name version loc flags ghcOptions
-- Skip packages that can't be loaded - see
-- https://github.com/commercialhaskell/stack/issues/2967
| name `elem` [$(mkPackageName "rts"), $(mkPackageName "ghc")] =
| name `elem` [mkPackageName "rts", mkPackageName "ghc"] =
return (Set.empty, DotPayload (Just version) (Just $ Right BSD3))
| otherwise = fmap (packageAllDeps &&& makePayload) (loadPackage loc flags ghcOptions)
resolveDependencies (dotDependencyDepth dotOpts) graph depLoader
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/GhcPkg.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import qualified Data.ByteString.Lazy as BL
import Data.List
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Distribution.Version (mkVersion)
import Path (parent, mkRelFile, (</>))
import Path.Extra (toFilePathNoTrailingSep)
import Path.IO
import Stack.Constants
import Stack.Types.Build
import Stack.Types.GhcPkgId
import Stack.Types.Compiler
import Stack.Types.Version
import System.FilePath (searchPathSeparator)
import RIO.Process

Expand Down Expand Up @@ -167,7 +167,7 @@ unregisterGhcPkgId wc cv pkgDb gid ident = do
-- TODO ideally we'd tell ghc-pkg a GhcPkgId instead
args = "unregister" : "--user" : "--force" :
(case cv of
ACGhc v | v < $(mkVersion "7.9") ->
ACGhc v | v < mkVersion [7, 9] ->
[packageIdentifierString ident]
_ -> ["--ipid", ghcPkgIdString gid])

Expand Down
8 changes: 4 additions & 4 deletions src/Stack/Hoogle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import Stack.Prelude
import qualified Data.ByteString.Lazy.Char8 as BL8
import Data.Char (isSpace)
import qualified Data.Text as T
import Distribution.Types.PackageName (mkPackageName)
import Distribution.Version (mkVersion)
import Path (parseAbsFile)
import Path.IO hiding (findExecutable)
import qualified Stack.Build
import Stack.Runners
import Stack.Types.Config
import Stack.Types.PackageName
import Stack.Types.Version
import System.Exit
import RIO.Process

Expand Down Expand Up @@ -74,8 +74,8 @@ hoogleCmd (args,setup,rebuild,startServer) go = withBuildConfig go $ do
defaultBuildOptsCLI))
(\(_ :: ExitCode) ->
return ()))
hooglePackageName = $(mkPackageName "hoogle")
hoogleMinVersion = $(mkVersion "5.0")
hooglePackageName = mkPackageName "hoogle"
hoogleMinVersion = mkVersion [5, 0]
hoogleMinIdent =
PackageIdentifier hooglePackageName hoogleMinVersion
installHoogle :: RIO EnvConfig ()
Expand Down
7 changes: 4 additions & 3 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import qualified Distribution.Types.LegacyExeDependency as Cabal
import Distribution.Types.MungedPackageName
import qualified Distribution.Types.UnqualComponentName as Cabal
import qualified Distribution.Verbosity as D
import Distribution.Version (mkVersion)
import Lens.Micro (lens)
import qualified Hpack.Config as Hpack
import Path as FL
Expand Down Expand Up @@ -498,7 +499,7 @@ makeObjectFilePathFromC cabalDir namedComponent distDir cFilePath = do
-- | Make the global autogen dir if Cabal version is new enough.
packageAutogenDir :: Version -> Path Abs Dir -> Maybe (Path Abs Dir)
packageAutogenDir cabalVer distDir
| cabalVer < $(mkVersion "2.0") = Nothing
| cabalVer < mkVersion [2, 0] = Nothing
| otherwise = Just $ buildDir distDir </> $(mkRelDir "global-autogen")

-- | Make the autogen dir.
Expand All @@ -509,7 +510,7 @@ componentAutogenDir cabalVer component distDir =
-- | See 'Distribution.Simple.LocalBuildInfo.componentBuildDir'
componentBuildDir :: Version -> NamedComponent -> Path Abs Dir -> Path Abs Dir
componentBuildDir cabalVer component distDir
| cabalVer < $(mkVersion "2.0") = buildDir distDir
| cabalVer < mkVersion [2, 0] = buildDir distDir
| otherwise =
case component of
CLib -> buildDir distDir
Expand Down Expand Up @@ -562,7 +563,7 @@ packageDependencies pkgConfig pkg' =
maybe [] setupDepends (setupBuildInfo pkg)
where
pkg
| getGhcVersion (packageConfigCompilerVersion pkgConfig) >= $(mkVersion "8.0") = pkg'
| getGhcVersion (packageConfigCompilerVersion pkgConfig) >= mkVersion [8, 0] = pkg'
-- Set all components to buildable. Only need to worry about
-- library, exe, test, and bench, since others didn't exist in
-- older Cabal versions
Expand Down
4 changes: 1 addition & 3 deletions src/Stack/SDist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import qualified Distribution.PackageDescription.Check as Check
import qualified Distribution.PackageDescription.Parsec as Cabal
import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription)
import qualified Distribution.Types.UnqualComponentName as Cabal
import qualified Distribution.Text as Cabal
import Distribution.Version (simplifyVersionRange, orLaterVersion, earlierVersion, hasUpperBound, hasLowerBound)
import Lens.Micro (set)
import Path
Expand All @@ -59,7 +58,6 @@ import Stack.Package
import Stack.Types.Build
import Stack.Types.Config
import Stack.Types.Package
import Stack.Types.PackageIdentifier
import Stack.Types.Runner
import Stack.Types.Version
import System.Directory (getModificationTime, getPermissions)
Expand Down Expand Up @@ -195,7 +193,7 @@ getCabalLbs pvpBounds mrev cabalfp = do
$ Cabal.packageDescription gpd'
}
}
ident <- parsePackageIdentifierThrowing $ Cabal.display $ Cabal.package $ Cabal.packageDescription gpd''
ident = Cabal.package $ Cabal.packageDescription gpd''
-- Sanity rendering and reparsing the input, to ensure there are no
-- cabal bugs, since there have been bugs here before, and currently
-- are at the time of writing:
Expand Down
Loading

0 comments on commit 3211dd5

Please sign in to comment.