Skip to content

Commit

Permalink
Exclude wanted local targets from -package specs
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdone committed Jul 15, 2015
1 parent 36be008 commit c3284b4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
17 changes: 13 additions & 4 deletions src/Stack/Ide.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) $
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
19 changes: 10 additions & 9 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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 -> []
Expand Down
30 changes: 17 additions & 13 deletions src/Stack/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,26 +60,24 @@ 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 = []
| otherwise = concatMap (map toFilePath . _3) pkgs
$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")
Expand Down

0 comments on commit c3284b4

Please sign in to comment.