From ba35daaa25986ce0e5df97737085c9e2d6174162 Mon Sep 17 00:00:00 2001 From: Mathieu Boespflug Date: Sat, 4 Jun 2016 23:07:43 +0200 Subject: [PATCH] Split resolvePackage into two functions. The gruntwork is now done by `packageFromPackageDescription`. The idea is that if you already have a resolved `GenericPackageDescription`, i.e. a `PackageDescription`, then you should still be able to get a `Package` out of it. --- src/Stack/Package.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Stack/Package.hs b/src/Stack/Package.hs index 1720b50907..62b69a3801 100644 --- a/src/Stack/Package.hs +++ b/src/Stack/Package.hs @@ -21,6 +21,7 @@ module Stack.Package ,readPackageUnresolved ,readPackageUnresolvedBS ,resolvePackage + ,packageFromPackageDescription ,findOrGenerateCabalFile ,hpack ,Package(..) @@ -179,6 +180,16 @@ resolvePackage :: PackageConfig -> GenericPackageDescription -> Package resolvePackage packageConfig gpkg = + packageFromPackageDescription + packageConfig + gpkg + (resolvePackageDescription packageConfig gpkg) + +packageFromPackageDescription :: PackageConfig + -> GenericPackageDescription + -> PackageDescription + -> Package +packageFromPackageDescription packageConfig gpkg pkg = Package { packageName = name , packageVersion = fromCabalVersion (pkgVersion pkgId) @@ -210,7 +221,7 @@ resolvePackage packageConfig gpkg = False (not . null . exposedModules) (library pkg) - , packageSimpleType = buildType (packageDescription gpkg) == Just Simple + , packageSimpleType = buildType pkg == Just Simple } where pkgFiles = GetPackageFiles $ @@ -236,9 +247,8 @@ resolvePackage packageConfig gpkg = hpackExists <- doesFileExist hpackPath return $ if hpackExists then S.singleton hpackPath else S.empty return (componentModules, componentFiles, buildFiles <> dataFiles', warnings) - pkgId = package (packageDescription gpkg) + pkgId = package pkg name = fromCabalPackageName (pkgName pkgId) - pkg = resolvePackageDescription packageConfig gpkg deps = M.filterWithKey (const . (/= name)) (packageDependencies pkg) -- | Generate GHC options for the package's components, and a list of