Skip to content

Commit

Permalink
Pass -package-id to ghci (closes #867)
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Sep 30, 2015
1 parent 9c60d92 commit 0a1a2f7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Bug fixes:
* Fix quoting of output failed command line arguments
* Mark executable-only packages as installed when copied from cache [#1043](https://github.com/commercialhaskell/stack/pull/1043)
* Canonicalize temporary directory paths [#1047](https://github.com/commercialhaskell/stack/pull/1047)
* Pass -package-id to ghci [#867](https://github.com/commercialhaskell/stack/issues/867)

## 0.1.5.0

Expand Down
2 changes: 0 additions & 2 deletions src/Stack/Build/Installed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ data LoadHelper = LoadHelper
}
deriving Show

type InstalledMap = Map PackageName (Version, InstallLocation, Installed) -- TODO Version is now redundant and can be gleaned from Installed

-- | Options for 'getInstalled'.
data GetInstalledOpts = GetInstalledOpts
{ getInstalledProfiling :: !Bool
Expand Down
16 changes: 13 additions & 3 deletions src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Network.HTTP.Client.Conduit
import Path
import Prelude
import Stack.Build
import Stack.Build.Installed
import Stack.Build.Source
import Stack.Build.Target
import Stack.Constants
Expand Down Expand Up @@ -177,6 +178,14 @@ ghciSetup mainIs stringTargets = do
let bopts = makeBuildOpts targets
econfig <- asks getEnvConfig
(realTargets,_,_,_,sourceMap) <- loadSourceMap AllowNoTargets bopts
menv <- getMinimalEnvOverride
(installedMap, _, _) <- getInstalled
menv
GetInstalledOpts
{ getInstalledProfiling = False
, getInstalledHaddock = False
}
sourceMap
locals <-
liftM catMaybes $
forM (M.toList (envConfigPackages econfig)) $
Expand All @@ -192,7 +201,7 @@ ghciSetup mainIs stringTargets = do
infos <-
forM locals $
\(name,(cabalfp,components)) ->
makeGhciPkgInfo sourceMap (map fst locals) name cabalfp components
makeGhciPkgInfo sourceMap installedMap (map fst locals) name cabalfp components
unless (M.null realTargets) (build (const (return ())) Nothing bopts)
return (realTargets, mainIsTargets, infos)
where
Expand Down Expand Up @@ -231,12 +240,13 @@ ghciSetup mainIs stringTargets = do
makeGhciPkgInfo
:: (MonadReader r m, HasEnvConfig r, MonadLogger m, MonadIO m, MonadCatch m)
=> SourceMap
-> InstalledMap
-> [PackageName]
-> PackageName
-> Path Abs File
-> SimpleTarget
-> m GhciPkgInfo
makeGhciPkgInfo sourceMap locals name cabalfp components = do
makeGhciPkgInfo sourceMap installedMap locals name cabalfp components = do
econfig <- asks getEnvConfig
bconfig <- asks getBuildConfig
let config =
Expand All @@ -250,7 +260,7 @@ makeGhciPkgInfo sourceMap locals name cabalfp components = do
(warnings,pkg) <- readPackage config cabalfp
mapM_ (printCabalFileWarning cabalfp) warnings
(componentsModules,componentFiles,componentsOpts,generalOpts) <-
getPackageOpts (packageOpts pkg) sourceMap locals cabalfp
getPackageOpts (packageOpts pkg) sourceMap installedMap locals cabalfp
let filterWithinWantedComponents m =
M.elems
(M.filterWithKey
Expand Down
18 changes: 12 additions & 6 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import Path.Find
import Path.IO
import Prelude
import Safe (headDef, tailSafe)
import Stack.Build.Installed
import Stack.Constants
import Stack.Types
import qualified Stack.Types.PackageIdentifier
Expand Down Expand Up @@ -194,10 +195,10 @@ resolvePackage packageConfig gpkg =
[T.pack (exeName b) | b <- executables pkg
, buildable (buildInfo b)]
, packageOpts = GetPackageOpts $
\sourceMap locals cabalfp ->
\sourceMap installedMap locals cabalfp ->
do (componentsModules,componentFiles,_,_) <- getPackageFiles pkgFiles cabalfp
(componentsOpts,generalOpts) <-
generatePkgDescOpts sourceMap locals cabalfp pkg componentFiles
generatePkgDescOpts sourceMap installedMap locals cabalfp pkg componentFiles
return (componentsModules,componentFiles,componentsOpts,generalOpts)
, packageHasExposedModules = maybe
False
Expand Down Expand Up @@ -227,12 +228,13 @@ resolvePackage packageConfig gpkg =
generatePkgDescOpts
:: (HasEnvConfig env, HasPlatform env, MonadThrow m, MonadReader env m, MonadIO m)
=> SourceMap
-> InstalledMap
-> [PackageName]
-> Path Abs File
-> PackageDescription
-> Map NamedComponent (Set DotCabalPath)
-> m (Map NamedComponent [String],[String])
generatePkgDescOpts sourceMap locals cabalfp pkg componentPaths = do
generatePkgDescOpts sourceMap installedMap locals cabalfp pkg componentPaths = do
distDir <- distDirFromDir cabalDir
let cabalmacros = autogenDir distDir </> $(mkRelFile "cabal_macros.h")
exists <- fileExists cabalmacros
Expand All @@ -244,6 +246,7 @@ generatePkgDescOpts sourceMap locals cabalfp pkg componentPaths = do
( namedComponent
, generateBuildInfoOpts
sourceMap
installedMap
mcabalmacros
cabalDir
distDir
Expand Down Expand Up @@ -283,6 +286,7 @@ generatePkgDescOpts sourceMap locals cabalfp pkg componentPaths = do
-- | Generate GHC options for the target.
generateBuildInfoOpts
:: SourceMap
-> InstalledMap
-> Maybe (Path Abs File)
-> Path Abs Dir
-> Path Abs Dir
Expand All @@ -291,7 +295,7 @@ generateBuildInfoOpts
-> Set DotCabalPath
-> NamedComponent
-> [String]
generateBuildInfoOpts sourceMap mcabalmacros cabalDir distDir locals b dotCabalPaths componentName =
generateBuildInfoOpts sourceMap installedMap mcabalmacros cabalDir distDir locals b dotCabalPaths componentName =
nubOrd (concat [ghcOpts b, extOpts b, srcOpts, includeOpts, macros, deps, extra b, extraDirs, fworks b, cObjectFiles])
where
cObjectFiles =
Expand All @@ -301,8 +305,10 @@ generateBuildInfoOpts sourceMap mcabalmacros cabalDir distDir locals b dotCabalP
cfiles = mapMaybe dotCabalCFilePath (S.toList dotCabalPaths)
deps =
concat
[ ["-package=" <> display name <>
maybe "" -- This empty case applies to e.g. base.
[ case M.lookup (fromCabalPackageName name) installedMap of
Just (_, _, Stack.Types.Library _ident ipid) -> ["-package-id=" <> ghcPkgIdString ipid]
_ -> ["-package=" <> display name <>
maybe "" -- This empty case applies to e.g. base.
((("-" <>) . versionString) . sourceVersion)
(M.lookup (fromCabalPackageName name) sourceMap)]
| Dependency name _ <- targetBuildDepends b
Expand Down
3 changes: 0 additions & 3 deletions src/Stack/Types/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,6 @@ modTime x =
, toRational
(utctDayTime x))

data Installed = Library PackageIdentifier GhcPkgId | Executable PackageIdentifier
deriving (Show, Eq, Ord)

-- | Configure options to be sent to Setup.hs configure
data ConfigureOpts = ConfigureOpts
{ coDirs :: ![String]
Expand Down
8 changes: 8 additions & 0 deletions src/Stack/Types/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import Prelude
import Stack.Types.Compiler
import Stack.Types.Config
import Stack.Types.FlagName
import Stack.Types.GhcPkgId
import Stack.Types.PackageName
import Stack.Types.PackageIdentifier
import Stack.Types.Version

-- | All exceptions thrown by the library.
Expand Down Expand Up @@ -98,6 +100,7 @@ data Package =
newtype GetPackageOpts = GetPackageOpts
{ getPackageOpts :: forall env m. (MonadIO m,HasEnvConfig env, HasPlatform env, MonadThrow m, MonadReader env m, MonadLogger m, MonadCatch m)
=> SourceMap
-> InstalledMap
-> [PackageName]
-> Path Abs File
-> m (Map NamedComponent (Set ModuleName)
Expand Down Expand Up @@ -322,3 +325,8 @@ dotCabalGetPath dcp =
DotCabalMainPath fp -> fp
DotCabalFilePath fp -> fp
DotCabalCFilePath fp -> fp

type InstalledMap = Map PackageName (Version, InstallLocation, Installed) -- TODO Version is now redundant and can be gleaned from Installed

data Installed = Library PackageIdentifier GhcPkgId | Executable PackageIdentifier
deriving (Show, Eq, Ord)

0 comments on commit 0a1a2f7

Please sign in to comment.