Skip to content

Commit aa5003a

Browse files
authored
Merge pull request #3288 from commercialhaskell/cabal-2
Upgrade to Cabal 2.0
2 parents 4fd1284 + b1f9dcf commit aa5003a

23 files changed

+169
-152
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Major changes:
1111
details, please see
1212
[the writeup on these changes](https://www.fpcomplete.com/blog/2017/07/stacks-new-extensible-snapshots). [PR #3249](https://github.com/commercialhaskell/stack/pull/3249),
1313
see the PR description for a number of related issues.
14+
* Upgraded to version 2.0 of the Cabal library.
1415

1516
Behavior changes:
1617

Setup.hs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ module Main (main) where
33

44
import Data.List ( nub, sortBy )
55
import Data.Ord ( comparing )
6-
import Data.Version ( showVersion )
7-
import Distribution.Package ( PackageName(PackageName), PackageId, InstalledPackageId, packageVersion, packageName )
6+
import Distribution.Package ( PackageId, InstalledPackageId, packageVersion, packageName )
87
import Distribution.PackageDescription ( PackageDescription(), Executable(..) )
98
import Distribution.InstalledPackageInfo (sourcePackageId, installedPackageId)
109
import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )
@@ -13,7 +12,10 @@ import Distribution.Simple.BuildPaths ( autogenModulesDir )
1312
import Distribution.Simple.PackageIndex (allPackages, dependencyClosure)
1413
import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), fromFlag )
1514
import Distribution.Simple.LocalBuildInfo ( installedPkgs, withLibLBI, withExeLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )
15+
import Distribution.Types.PackageName (PackageName, unPackageName)
16+
import Distribution.Types.UnqualComponentName (unUnqualComponentName)
1617
import Distribution.Verbosity ( Verbosity )
18+
import Distribution.Version ( showVersion )
1719
import System.FilePath ( (</>) )
1820

1921
main :: IO ()
@@ -29,27 +31,28 @@ generateBuildModule verbosity pkg lbi = do
2931
createDirectoryIfMissingVerbose verbosity True dir
3032
withLibLBI pkg lbi $ \_ libcfg -> do
3133
withExeLBI pkg lbi $ \exe clbi ->
32-
rewriteFile (dir </> "Build_" ++ exeName exe ++ ".hs") $ unlines
33-
[ "module Build_" ++ exeName exe ++ " where"
34+
rewriteFile (dir </> "Build_" ++ exeName' exe ++ ".hs") $ unlines
35+
[ "module Build_" ++ exeName' exe ++ " where"
3436
, ""
3537
, "deps :: [String]"
3638
, "deps = " ++ (show $ formatdeps (transDeps libcfg clbi))
3739
]
3840
where
41+
exeName' = unUnqualComponentName . exeName
3942
formatdeps = map formatone . sortBy (comparing unPackageName')
4043
formatone p = unPackageName' p ++ "-" ++ showVersion (packageVersion p)
41-
unPackageName' p = case packageName p of PackageName n -> n
44+
unPackageName' = unPackageName . packageName
4245
transDeps xs ys =
4346
either (map sourcePackageId . allPackages) handleDepClosureFailure $ dependencyClosure allInstPkgsIdx availInstPkgIds
4447
where
4548
allInstPkgsIdx = installedPkgs lbi
4649
allInstPkgIds = map installedPackageId $ allPackages allInstPkgsIdx
4750
-- instPkgIds includes `stack-X.X.X`, which is not a depedency hence is missing from allInstPkgsIdx. Filter that out.
48-
availInstPkgIds = filter (`elem` allInstPkgIds) . map fst $ testDeps xs ys
51+
availInstPkgIds = filter (`elem` allInstPkgIds) $ testDeps xs ys
4952
handleDepClosureFailure unsatisfied =
5053
error $
5154
"Computation of transitive dependencies failed." ++
5255
if null unsatisfied then "" else " Unresolved dependencies: " ++ show unsatisfied
5356

54-
testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]
55-
testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys
57+
testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [InstalledPackageId]
58+
testDeps xs ys = map fst $ nub $ componentPackageDeps xs ++ componentPackageDeps ys

src/Stack/Build/ConstructPlan.hs

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import qualified Data.Set as Set
3030
import qualified Data.Text as T
3131
import Data.Text.Encoding (decodeUtf8With)
3232
import Data.Text.Encoding.Error (lenientDecode)
33-
import qualified Distribution.Package as Cabal
3433
import qualified Distribution.Text as Cabal
3534
import qualified Distribution.Version as Cabal
3635
import Generics.Deriving.Monoid (memptydefault, mappenddefault)
@@ -129,7 +128,7 @@ data Ctx = Ctx
129128
, baseConfigOpts :: !BaseConfigOpts
130129
, loadPackage :: !(PackageLocationIndex FilePath -> Map FlagName Bool -> [Text] -> IO Package)
131130
, combinedMap :: !CombinedMap
132-
, toolToPackages :: !(Cabal.Dependency -> Map PackageName VersionRange)
131+
, toolToPackages :: !(ExeName -> Map PackageName VersionRange)
133132
, ctxEnvConfig :: !EnvConfig
134133
, callStack :: ![PackageName]
135134
, extraToBuild :: !(Set PackageName)
@@ -224,18 +223,18 @@ constructPlan ls0 baseConfigOpts0 locals extraToBuild0 localDumpPkgs loadPackage
224223
, baseConfigOpts = baseConfigOpts0
225224
, loadPackage = loadPackage0
226225
, combinedMap = combineMap sourceMap installedMap
227-
, toolToPackages = \(Cabal.Dependency name _) ->
226+
, toolToPackages = \name ->
228227
maybe Map.empty (Map.fromSet (const Cabal.anyVersion)) $
229-
Map.lookup (T.pack . packageNameString . fromCabalPackageName $ name) (toolMap lp)
228+
Map.lookup name toolMap
230229
, ctxEnvConfig = econfig
231230
, callStack = []
232231
, extraToBuild = extraToBuild0
233232
, getVersions = getVersions0
234233
, wanted = wantedLocalPackages locals <> extraToBuild0
235234
, localNames = Set.fromList $ map (packageName . lpPackage) locals
236235
}
237-
238-
toolMap = getToolMap ls0
236+
where
237+
toolMap = getToolMap ls0 lp
239238

240239
-- | State to be maintained during the calculation of local packages
241240
-- to unregister.
@@ -795,58 +794,49 @@ packageDepsWithTools p = do
795794
ctx <- ask
796795
-- TODO: it would be cool to defer these warnings until there's an
797796
-- actual issue building the package.
798-
let toEither (Cabal.Dependency (Cabal.PackageName name) _) mp =
797+
let toEither name mp =
799798
case Map.toList mp of
800-
[] -> Left (NoToolFound name (packageName p))
799+
[] -> Left (ToolWarning name (packageName p) Nothing)
801800
[_] -> Right mp
802-
xs -> Left (AmbiguousToolsFound name (packageName p) (map fst xs))
801+
((x, _):(y, _):zs) ->
802+
Left (ToolWarning name (packageName p) (Just (x, y, map fst zs)))
803803
(warnings0, toolDeps) =
804804
partitionEithers $
805-
map (\dep -> toEither dep (toolToPackages ctx dep)) (packageTools p)
805+
map (\dep -> toEither dep (toolToPackages ctx dep)) (Map.keys (packageTools p))
806806
-- Check whether the tool is on the PATH before warning about it.
807-
warnings <- fmap catMaybes $ forM warnings0 $ \warning -> do
808-
let toolName = case warning of
809-
NoToolFound tool _ -> tool
810-
AmbiguousToolsFound tool _ _ -> tool
807+
warnings <- fmap catMaybes $ forM warnings0 $ \warning@(ToolWarning (ExeName toolName) _ _) -> do
811808
config <- view configL
812809
menv <- liftIO $ configEnvOverride config minimalEnvSettings { esIncludeLocals = True }
813-
mfound <- findExecutable menv toolName
810+
mfound <- findExecutable menv $ T.unpack toolName
814811
case mfound of
815812
Nothing -> return (Just warning)
816813
Just _ -> return Nothing
817814
tell mempty { wWarnings = (map toolWarningText warnings ++) }
818-
when (any isNoToolFound warnings) $ do
819-
let msg = T.unlines
820-
[ "Missing build-tools may be caused by dependencies of the build-tool being overridden by extra-deps."
821-
, "This should be fixed soon - see this issue https://github.com/commercialhaskell/stack/issues/595"
822-
]
823-
tell mempty { wWarnings = (msg:) }
824815
return $ Map.unionsWith intersectVersionRanges
825816
$ packageDeps p
826817
: toolDeps
827818

828-
data ToolWarning
829-
= NoToolFound String PackageName
830-
| AmbiguousToolsFound String PackageName [PackageName]
831-
832-
isNoToolFound :: ToolWarning -> Bool
833-
isNoToolFound NoToolFound{} = True
834-
isNoToolFound _ = False
819+
-- | Warn about tools in the snapshot definition. States the tool name
820+
-- expected, the package name using it, and found packages. If the
821+
-- last value is Nothing, it means the tool was not found
822+
-- anywhere. For a Just value, it was found in at least two packages.
823+
data ToolWarning = ToolWarning ExeName PackageName (Maybe (PackageName, PackageName, [PackageName]))
824+
deriving Show
835825

836826
toolWarningText :: ToolWarning -> Text
837-
toolWarningText (NoToolFound toolName pkgName) =
827+
toolWarningText (ToolWarning (ExeName toolName) pkgName Nothing) =
838828
"No packages found in snapshot which provide a " <>
839829
T.pack (show toolName) <>
840830
" executable, which is a build-tool dependency of " <>
841831
T.pack (show (packageNameString pkgName))
842-
toolWarningText (AmbiguousToolsFound toolName pkgName options) =
832+
toolWarningText (ToolWarning (ExeName toolName) pkgName (Just (option1, option2, options))) =
843833
"Multiple packages found in snapshot which provide a " <>
844834
T.pack (show toolName) <>
845835
" exeuctable, which is a build-tool dependency of " <>
846836
T.pack (show (packageNameString pkgName)) <>
847837
", so none will be installed.\n" <>
848838
"Here's the list of packages which provide it: " <>
849-
T.intercalate ", " (map packageNameText options) <>
839+
T.intercalate ", " (map packageNameText (option1:option2:options)) <>
850840
"\nSince there's no good way to choose, you may need to install it manually."
851841

852842
-- | Strip out anything from the @Plan@ intended for the local database

src/Stack/Build/Source.hs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module Stack.Build.Source
1313
, getLocalFlags
1414
, getGhcOptions
1515
, addUnlistedToBuildCache
16-
, getDefaultPackageConfig
1716
) where
1817

1918
import Stack.Prelude
@@ -471,20 +470,6 @@ checkComponentsBuildable lps =
471470
, c <- Set.toList (lpUnbuildable lp)
472471
]
473472

474-
getDefaultPackageConfig :: (MonadIO m, MonadReader env m, HasEnvConfig env)
475-
=> m PackageConfig
476-
getDefaultPackageConfig = do
477-
platform <- view platformL
478-
compilerVersion <- view actualCompilerVersionL
479-
return PackageConfig
480-
{ packageConfigEnableTests = False
481-
, packageConfigEnableBenchmarks = False
482-
, packageConfigFlags = M.empty
483-
, packageConfigGhcOptions = []
484-
, packageConfigCompilerVersion = compilerVersion
485-
, packageConfigPlatform = platform
486-
}
487-
488473
-- | Get 'PackageConfig' for package given its name.
489474
getPackageConfig :: (MonadIO m, MonadReader env m, HasEnvConfig env)
490475
=> BuildOptsCLI

src/Stack/BuildPlan.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import Distribution.PackageDescription (GenericPackageDescription,
4444
flagName, genPackageFlags,
4545
condExecutables)
4646
import qualified Distribution.PackageDescription as C
47+
import qualified Distribution.Types.UnqualComponentName as C
4748
import Distribution.System (Platform)
4849
import Distribution.Text (display)
4950
import qualified Distribution.Version as C
@@ -151,7 +152,7 @@ instance Show BuildPlanException where
151152
-- both snapshot and local packages (deps and project packages).
152153
getToolMap :: LoadedSnapshot
153154
-> LocalPackages
154-
-> Map Text (Set PackageName)
155+
-> Map ExeName (Set PackageName)
155156
getToolMap ls locals =
156157

157158
{- We no longer do this, following discussion at:
@@ -170,13 +171,13 @@ getToolMap ls locals =
170171
]
171172
where
172173
goSnap (pname, lpi) =
173-
map (flip Map.singleton (Set.singleton pname) . unExeName)
174+
map (flip Map.singleton (Set.singleton pname))
174175
$ Set.toList
175176
$ lpiProvidedExes lpi
176177

177178
goLocalProj (pname, lpv) =
178179
map (flip Map.singleton (Set.singleton pname))
179-
[t | CExe t <- Set.toList (lpvComponents lpv)]
180+
[ExeName t | CExe t <- Set.toList (lpvComponents lpv)]
180181

181182
goLocalDep (pname, (gpd, _loc)) =
182183
map (flip Map.singleton (Set.singleton pname))
@@ -185,8 +186,8 @@ getToolMap ls locals =
185186
-- TODO consider doing buildable checking. Not a big deal though:
186187
-- worse case scenario is we build an extra package that wasn't
187188
-- strictly needed.
188-
gpdExes :: GenericPackageDescription -> [Text]
189-
gpdExes = map (T.pack . fst) . condExecutables
189+
gpdExes :: GenericPackageDescription -> [ExeName]
190+
gpdExes = map (ExeName . T.pack . C.unUnqualComponentName . fst) . condExecutables
190191

191192
gpdPackages :: [GenericPackageDescription] -> Map PackageName Version
192193
gpdPackages gpds = Map.fromList $

src/Stack/Config.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ import qualified Data.Text as T
5959
import Data.Text.Encoding (encodeUtf8)
6060
import qualified Data.Yaml as Yaml
6161
import qualified Distribution.PackageDescription as C
62+
import qualified Distribution.Types.UnqualComponentName as C
6263
import Distribution.System (OS (..), Platform (..), buildPlatform, Arch(OtherArch))
6364
import qualified Distribution.Text
64-
import Distribution.Version (simplifyVersionRange)
65+
import Distribution.Version (simplifyVersionRange, mkVersion')
6566
import GHC.Conc (getNumProcessors)
6667
import Lens.Micro (lens)
6768
import Network.HTTP.Client (parseUrlThrow)
@@ -473,7 +474,7 @@ loadConfigMaybeProject configArgs mresolver mproject = do
473474
LCSNoConfig _ -> configNoLocalConfig stackRoot mresolver configArgs
474475
LCSProject project -> loadHelper $ Just project
475476
LCSNoProject -> loadHelper Nothing
476-
unless (fromCabalVersion Meta.version `withinRange` configRequireStackVersion config)
477+
unless (fromCabalVersion (mkVersion' Meta.version) `withinRange` configRequireStackVersion config)
477478
(throwM (BadStackVersionException (configRequireStackVersion config)))
478479

479480
let mprojectRoot = fmap (\(_, fp, _) -> parent fp) mproject
@@ -708,9 +709,9 @@ getNamedComponents gpkg = Set.fromList $ concat
708709
]
709710
where
710711
go :: (T.Text -> NamedComponent)
711-
-> (C.GenericPackageDescription -> [String])
712+
-> (C.GenericPackageDescription -> [C.UnqualComponentName])
712713
-> [NamedComponent]
713-
go wrapper f = map (wrapper . T.pack) $ f gpkg
714+
go wrapper f = map (wrapper . T.pack . C.unUnqualComponentName) $ f gpkg
714715

715716
-- | Check if there are any duplicate package names and, if so, throw an
716717
-- exception.

src/Stack/Init.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ renderStackYaml p ignoredPackages dupPackages =
293293

294294
footerHelp =
295295
let major = toCabalVersion
296-
$ toMajorVersion $ fromCabalVersion Meta.version
296+
$ toMajorVersion $ fromCabalVersion $ C.mkVersion' Meta.version
297297
in commentHelp
298298
[ "Control whether we use the GHC we find on the path"
299299
, "system-ghc: true"

src/Stack/Options/Completion.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Data.Maybe
1818
import qualified Data.Set as Set
1919
import qualified Data.Text as T
2020
import qualified Distribution.PackageDescription as C
21+
import qualified Distribution.Types.UnqualComponentName as C
2122
import Options.Applicative
2223
import Options.Applicative.Builder.Extra
2324
import Stack.Config (getLocalPackages)
@@ -89,8 +90,8 @@ flagCompleter = buildConfigCompleter $ \input -> do
8990
(C.genPackageFlags (lpvGPD lpv)))
9091
$ Map.toList lpvs
9192
flagString name fl =
92-
case C.flagName fl of
93-
C.FlagName flname -> (if flagEnabled name fl then "-" else "") ++ flname
93+
let flname = C.unFlagName $ C.flagName fl
94+
in (if flagEnabled name fl then "-" else "") ++ flname
9495
flagEnabled name fl =
9596
fromMaybe (C.flagDefault fl) $
9697
Map.lookup (fromCabalFlagName (C.flagName fl)) $
@@ -107,5 +108,5 @@ projectExeCompleter = buildConfigCompleter $ \input -> do
107108
return $
108109
filter (input `isPrefixOf`) $
109110
nubOrd $
110-
concatMap (\(_, lpv) -> map fst (C.condExecutables (lpvGPD lpv))) $
111+
concatMap (\(_, lpv) -> map (C.unUnqualComponentName . fst) (C.condExecutables (lpvGPD lpv))) $
111112
Map.toList lpvs

0 commit comments

Comments
 (0)