Skip to content

Commit

Permalink
Merge pull request #2242 from mboes/buildinfo
Browse files Browse the repository at this point in the history
Support .buildinfo files in stack ghci.
  • Loading branch information
mgsloan committed Jun 7, 2016
2 parents 7669717 + e11c78c commit 96fc303
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
25 changes: 21 additions & 4 deletions src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ module Stack.Ghci

import Control.Applicative
import Control.Exception.Enclosed (tryAny)
import Control.Monad
import Control.Monad hiding (forM)
import Control.Monad.Catch
import Control.Monad.IO.Class
import Control.Monad.Logger
import Control.Monad.RWS.Strict
import Control.Monad.State.Strict
import Control.Monad.State.Strict (State, execState, get, modify)
import Control.Monad.Reader (MonadReader, asks)
import Control.Monad.Trans.Unlift (MonadBaseUnlift)
import qualified Data.ByteString.Char8 as S8
import Data.Either
Expand All @@ -35,12 +35,15 @@ import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Maybe.Extra (forMaybeM)
import Data.Monoid
import Data.Set (Set)
import qualified Data.Set as S
import Data.Traversable (forM)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Typeable (Typeable)
import Distribution.ModuleName (ModuleName)
import Distribution.PackageDescription (updatePackageDescription)
import Distribution.Text (display)
import Network.HTTP.Client.Conduit
import Path
Expand Down Expand Up @@ -379,7 +382,21 @@ makeGhciPkgInfo boptsCli sourceMap installedMap locals addPkgs name cabalfp targ
, packageConfigCompilerVersion = envConfigCompilerVersion econfig
, packageConfigPlatform = configPlatform (getConfig bconfig)
}
(warnings,pkg) <- readPackage config cabalfp
(warnings,gpkgdesc) <- readPackageUnresolved cabalfp

-- Source the package's *.buildinfo file created by configure if any. See
-- https://www.haskell.org/cabal/users-guide/developing-packages.html#system-dependent-parameters
buildinfofp <- parseRelFile (T.unpack (packageNameText name) ++ ".buildinfo")
hasDotBuildinfo <- doesFileExist (parent cabalfp </> 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
Expand Down
28 changes: 25 additions & 3 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ module Stack.Package
(readPackage
,readPackageBS
,readPackageDescriptionDir
,readDotBuildinfo
,readPackageUnresolved
,readPackageUnresolvedBS
,resolvePackage
,packageFromPackageDescription
,findOrGenerateCabalFile
,hpack
,Package(..)
Expand Down Expand Up @@ -146,6 +148,17 @@ readPackageDescriptionDir config pkgDir = do
gdesc <- liftM snd (readPackageUnresolved cabalfp)
return (gdesc, resolvePackageDescription config gdesc)

-- | Read @<package>.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)
Expand Down Expand Up @@ -179,6 +192,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)
Expand Down Expand Up @@ -210,7 +233,7 @@ resolvePackage packageConfig gpkg =
False
(not . null . exposedModules)
(library pkg)
, packageSimpleType = buildType (packageDescription gpkg) == Just Simple
, packageSimpleType = buildType pkg == Just Simple
}
where
pkgFiles = GetPackageFiles $
Expand All @@ -236,9 +259,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
Expand Down

0 comments on commit 96fc303

Please sign in to comment.