From ba35daaa25986ce0e5df97737085c9e2d6174162 Mon Sep 17 00:00:00 2001 From: Mathieu Boespflug Date: Sat, 4 Jun 2016 23:07:43 +0200 Subject: [PATCH 1/2] 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 From e11c78c0ceb801db2b2904a693565924417da672 Mon Sep 17 00:00:00 2001 From: Mathieu Boespflug Date: Sat, 4 Jun 2016 23:48:46 +0200 Subject: [PATCH 2/2] Support .buildinfo files in stack ghci. `Distribution.Simple` based `Setup.hs` sometimes create `.buildinfo` files as an artifact of the configure phase. This is the case in particular when using the autoconf hooks. Since this is an internal detail private to any given package's `Setup.hs`, Stack shouldn't (and doesn't) need to care or be aware of this. But `stack ghci` does, since in that use case we're not using Cabal to build - we're taking care of the build ourselves. In particular, ignoring the ` buildinfofp) + let mbuildinfofp + | hasDotBuildinfo = Just (parent cabalfp buildinfofp) + | otherwise = Nothing + mbuildinfo <- forM mbuildinfofp readDotBuildinfo + let pkg = + packageFromPackageDescription config gpkgdesc $ + maybe id (updatePackageDescription) mbuildinfo $ + resolvePackageDescription config gpkgdesc + mapM_ (printCabalFileWarning cabalfp) warnings (mods,files,opts) <- getPackageOpts (packageOpts pkg) sourceMap installedMap locals addPkgs cabalfp let filteredOpts = filterWanted opts diff --git a/src/Stack/Package.hs b/src/Stack/Package.hs index 62b69a3801..b96addbde8 100644 --- a/src/Stack/Package.hs +++ b/src/Stack/Package.hs @@ -18,6 +18,7 @@ module Stack.Package (readPackage ,readPackageBS ,readPackageDescriptionDir + ,readDotBuildinfo ,readPackageUnresolved ,readPackageUnresolvedBS ,resolvePackage @@ -147,6 +148,17 @@ readPackageDescriptionDir config pkgDir = do gdesc <- liftM snd (readPackageUnresolved cabalfp) return (gdesc, resolvePackageDescription config gdesc) +-- | Read @.buildinfo@ ancillary files produced by some Setup.hs hooks. +-- The file includes Cabal file syntax to be merged into the package description +-- derived from the package's .cabal file. +-- +-- NOTE: not to be confused with BuildInfo, an Stack-internal datatype. +readDotBuildinfo :: MonadIO m + => Path Abs File + -> m HookedBuildInfo +readDotBuildinfo buildinfofp = + liftIO $ readHookedBuildInfo D.silent (toFilePath buildinfofp) + -- | Print cabal file warnings. printCabalFileWarning :: (MonadLogger m)