diff --git a/src/Stack/Ide.hs b/src/Stack/Ide.hs index b76672eee0..22c563c90e 100644 --- a/src/Stack/Ide.hs +++ b/src/Stack/Ide.hs @@ -49,6 +49,15 @@ ide targets useropts = do econfig <- asks getEnvConfig bconfig <- asks getBuildConfig pwd <- getWorkingDir + locals <- + liftM catMaybes $ + forM (M.toList (bcPackages bconfig)) $ + \(dir,validWanted) -> + do cabalfp <- getCabalFileName dir + name <- parsePackageNameFromFilePath cabalfp + if validWanted && wanted pwd cabalfp name + then return (Just (name, cabalfp)) + else return Nothing pkgs <- liftM catMaybes $ forM (M.toList (bcPackages bconfig)) $ @@ -65,9 +74,9 @@ ide targets useropts = do (getConfig bconfig) } pkg <- readPackage config cabalfp - if validWanted && wanted pwd cabalfp pkg + if validWanted && wanted pwd cabalfp name then do - pkgOpts <- getPackageOpts (packageOpts pkg) cabalfp + pkgOpts <- getPackageOpts (packageOpts pkg) (map fst locals) cabalfp srcfiles <- getPackageFiles (packageFiles pkg) Modules cabalfp dist <- distDirFromDir dir @@ -103,9 +112,9 @@ ide targets useropts = do map ("--ghc-option=" ++) (filter (not . badForGhci) useropts) <> pkgopts <> pkgdbs) (encode (initialRequest srcfiles)) where - wanted pwd cabalfp pkg = isInWantedList || targetsEmptyAndInDir + wanted pwd cabalfp name = isInWantedList || targetsEmptyAndInDir where - isInWantedList = elem (packageNameText (packageName pkg)) targets + isInWantedList = elem (packageNameText name) targets targetsEmptyAndInDir = null targets || isParentOf (parent cabalfp) pwd badForGhci x = isPrefixOf "-O" x || elem x (words "-debug -threaded -ticky") diff --git a/src/Stack/Package.hs b/src/Stack/Package.hs index 4098638982..0a4dc14858 100644 --- a/src/Stack/Package.hs +++ b/src/Stack/Package.hs @@ -132,7 +132,8 @@ data Package = -- Argument is the location of the .cabal file newtype GetPackageOpts = GetPackageOpts { getPackageOpts :: forall env m. (MonadIO m,HasEnvConfig env, HasPlatform env, MonadThrow m, MonadReader env m) - => Path Abs File + => [PackageName] + -> Path Abs File -> m [String] } instance Show GetPackageOpts where @@ -254,8 +255,8 @@ resolvePackage packageConfig gpkg = Package , packageTests = S.fromList $ [ T.pack (testName t) | t <- testSuites pkg, buildable (testBuildInfo t)] , packageBenchmarks = S.fromList $ [ T.pack (benchmarkName b) | b <- benchmarks pkg, buildable (benchmarkBuildInfo b)] , packageExes = S.fromList $ [ T.pack (exeName b) | b <- executables pkg, buildable (buildInfo b)] - , packageOpts = GetPackageOpts $ \cabalfp -> - generatePkgDescOpts cabalfp pkg + , packageOpts = GetPackageOpts $ \locals cabalfp -> + generatePkgDescOpts locals cabalfp pkg , packageHasExposedModules = maybe False (not . null . exposedModules) (library pkg) , packageSimpleType = buildType (packageDescription gpkg) == Just Simple } @@ -268,8 +269,8 @@ resolvePackage packageConfig gpkg = Package -- | Generate GHC options for the package. generatePkgDescOpts :: (HasEnvConfig env, HasPlatform env, MonadThrow m, MonadReader env m, MonadIO m) - => Path Abs File -> PackageDescription -> m [String] -generatePkgDescOpts cabalfp pkg = do + => [PackageName] -> Path Abs File -> PackageDescription -> m [String] +generatePkgDescOpts locals cabalfp pkg = do distDir <- distDirFromDir cabalDir let cabalmacros = autogenDir distDir $(mkRelFile "cabal_macros.h") exists <- fileExists cabalmacros @@ -282,7 +283,7 @@ generatePkgDescOpts cabalfp pkg = do (["-hide-all-packages"] ++ concatMap (concatMap - (generateBuildInfoOpts mcabalmacros cabalDir distDir)) + (generateBuildInfoOpts mcabalmacros cabalDir distDir locals)) [ maybe [] (return . libBuildInfo) (library pkg) , map buildInfo (executables pkg) , map benchmarkBuildInfo (benchmarks pkg) @@ -291,14 +292,14 @@ generatePkgDescOpts cabalfp pkg = do cabalDir = parent cabalfp -- | Generate GHC options for the target. -generateBuildInfoOpts :: Maybe (Path Abs File) -> Path Abs Dir -> Path Abs Dir -> BuildInfo -> [String] -generateBuildInfoOpts mcabalmacros cabalDir distDir b = +generateBuildInfoOpts :: Maybe (Path Abs File) -> Path Abs Dir -> Path Abs Dir -> [PackageName] -> BuildInfo -> [String] +generateBuildInfoOpts mcabalmacros cabalDir distDir locals b = nub (concat [ghcOpts b, extOpts b, srcOpts, includeOpts b, macros, deps]) where deps = concat [ ["-package=" <> display name] - | Dependency name _ <- targetBuildDepends b] + | Dependency name _ <- targetBuildDepends b, not (elem name (map toCabalPackageName locals))] macros = case mcabalmacros of Nothing -> [] diff --git a/src/Stack/Repl.hs b/src/Stack/Repl.hs index addca298a9..35658b22b9 100644 --- a/src/Stack/Repl.hs +++ b/src/Stack/Repl.hs @@ -38,13 +38,19 @@ repl targets useropts ghciPath noload = do econfig <- asks getEnvConfig bconfig <- asks getBuildConfig pwd <- getWorkingDir - pkgs <- + locals <- liftM catMaybes $ forM (M.toList (bcPackages bconfig)) $ \(dir,validWanted) -> do cabalfp <- getCabalFileName dir name <- parsePackageNameFromFilePath cabalfp - let config = + if validWanted && wanted pwd cabalfp name + then return (Just (name, cabalfp)) + else return Nothing + pkgs <- + forM locals $ + \(name,cabalfp) -> + do let config = PackageConfig { packageConfigEnableTests = True , packageConfigEnableBenchmarks = True @@ -54,14 +60,9 @@ repl targets useropts ghciPath noload = do (getConfig bconfig) } pkg <- readPackage config cabalfp - if validWanted && wanted pwd cabalfp pkg - then do - pkgOpts <- getPackageOpts (packageOpts pkg) cabalfp - srcfiles <- - getPackageFiles (packageFiles pkg) Modules cabalfp - return - (Just (packageName pkg, pkgOpts, S.toList srcfiles)) - else return Nothing + pkgOpts <- getPackageOpts (packageOpts pkg) (map fst locals) cabalfp + srcfiles <- getPackageFiles (packageFiles pkg) Modules cabalfp + return (packageName pkg, pkgOpts, S.toList srcfiles) let pkgopts = filter (not . badForGhci) (concat (map _2 pkgs)) srcfiles | noload = [] @@ -69,11 +70,14 @@ repl targets useropts ghciPath noload = do $logInfo ("Configuring GHCi with the following packages: " <> T.intercalate ", " (map packageNameText (map _1 pkgs))) - exec defaultEnvSettings ghciPath ("--interactive" : pkgopts <> srcfiles <> useropts) + exec + defaultEnvSettings + ghciPath + ("--interactive" : pkgopts <> srcfiles <> useropts) where - wanted pwd cabalfp pkg = isInWantedList || targetsEmptyAndInDir + wanted pwd cabalfp name = isInWantedList || targetsEmptyAndInDir where - isInWantedList = elem (packageNameText (packageName pkg)) targets + isInWantedList = elem (packageNameText name) targets targetsEmptyAndInDir = null targets || isParentOf (parent cabalfp) pwd badForGhci x = isPrefixOf "-O" x || elem x (words "-debug -threaded -ticky")