Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack ghci build #726

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/Stack/Build/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,15 @@ loadLocals bopts latestVersion = do
name <- parsePackageNameFromFilePath cabalfp
let wanted = validWanted && isWanted' dir name
config = PackageConfig
{ packageConfigEnableTests = False
, packageConfigEnableBenchmarks = False
{ packageConfigEnableTests = wanted && boptsEnableTests bopts
, packageConfigEnableBenchmarks = wanted && boptsEnableBenchmarks bopts
, packageConfigFlags = localFlags (boptsFlags bopts) bconfig name
, packageConfigGhcVersion = envConfigGhcVersion econfig
, packageConfigPlatform = configPlatform $ getConfig bconfig
}
configFinal = config
{ packageConfigEnableTests =
case boptsFinalAction bopts of
DoTests _ -> wanted
_ -> False
, packageConfigEnableBenchmarks = wanted && case boptsFinalAction bopts of
(DoBenchmarks _) -> True
_ -> False
{ packageConfigEnableTests = wanted && boptsEnableTests bopts
, packageConfigEnableBenchmarks = wanted && boptsEnableBenchmarks bopts
}
pkg <- readPackage config cabalfp
pkgFinal <- readPackage configFinal cabalfp
Expand Down
4 changes: 4 additions & 0 deletions src/Stack/Build/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ data BuildOpts =
,boptsLibProfile :: !Bool
,boptsExeProfile :: !Bool
,boptsEnableOptimizations :: !(Maybe Bool)
,boptsEnableTests :: !Bool
,boptsEnableBenchmarks :: !Bool
,boptsHaddock :: !Bool
-- ^ Build haddocks?
,boptsHaddockDeps :: !(Maybe Bool)
Expand Down Expand Up @@ -379,6 +381,8 @@ defaultBuildOpts = BuildOpts
, boptsFileWatch = False
, boptsKeepGoing = Nothing
, boptsForceDirty = False
, boptsEnableBenchmarks = False
, boptsEnableTests = False
}

-- | Options for the 'FinalAction' 'DoTests'
Expand Down
25 changes: 21 additions & 4 deletions src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ import qualified Data.Set as S
import Data.Text (Text)
import qualified Data.Text as T
import Data.Typeable
import Network.HTTP.Client.Conduit
import Path
import Path.IO
import Stack.Build (build)
import Stack.Build.Source
import Stack.Exec
import Stack.Package
import Stack.Types
import Stack.Build.Types
import Stack.Types.Internal

-- | Launch a GHCi session for the given local project targets with the
-- given options and configure it with the load paths and extensions
-- of those targets.
ghci
:: (HasConfig r, HasBuildConfig r, HasEnvConfig r, MonadReader r m, MonadIO m, MonadThrow m, MonadLogger m, MonadCatch m, MonadBaseControl IO m)
:: (HasConfig r, HasBuildConfig r, HasEnvConfig r, MonadReader r m, MonadIO m, MonadThrow m, MonadLogger m, MonadCatch m, MonadBaseControl IO m, HasTerminal r, HasHttpManager r, MonadMask m , HasLogLevel r)
=> [Text] -- ^ Targets.
-> [String] -- ^ GHC options.
-> FilePath
Expand All @@ -59,8 +63,7 @@ data GhciPkgInfo = GhciPkgInfo
, ghciPkgModules :: [Path Abs File]
}

ghciSetup :: (HasConfig r, HasBuildConfig r, HasEnvConfig r, MonadReader r m, MonadIO m, MonadThrow m, MonadLogger m, MonadCatch m)
=> [Text] -> m [GhciPkgInfo]
ghciSetup :: (HasConfig r, HasBuildConfig r, HasEnvConfig r, MonadReader r m, MonadIO m, MonadThrow m, MonadLogger m, MonadCatch m, MonadBaseControl IO m, HasTerminal r, HasHttpManager r, MonadMask m, HasLogLevel r) => [Text] -> m [GhciPkgInfo]
ghciSetup targets = do
econfig <- asks getEnvConfig
bconfig <- asks getBuildConfig
Expand All @@ -77,7 +80,8 @@ ghciSetup targets = do
let findTarget x = find ((x ==) . packageNameText . fst) locals
unmetTargets = filter (isNothing . findTarget) targets
when (not (null unmetTargets)) $ throwM (TargetsNotFound unmetTargets)
forM locals $
infos <-
forM locals $
\(name,cabalfp) ->
do let config =
PackageConfig
Expand All @@ -99,6 +103,19 @@ ghciSetup targets = do
, ghciPkgDir = parent cabalfp
, ghciPkgModules = S.toList srcfiles
}
let lock = Nothing -- I'm not sure this lock business is a good
-- idea, it complicates things.
-- We build the necessary targets, including any dependencies,
-- with tests and benchmarks enabled, before launching GHCi.
build
(const (return ()))
lock
(defaultBuildOpts
{ boptsTargets = targets
, boptsEnableTests = True
, boptsEnableBenchmarks = True
} :: BuildOpts)
return infos
where
wanted pwd cabalfp name = isInWantedList || targetsEmptyAndInDir
where
Expand Down
8 changes: 6 additions & 2 deletions src/Stack/Ide.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}

-- | Run a IDE configured with the user's project(s).
Expand All @@ -13,6 +14,7 @@ import Control.Monad.Catch
import Control.Monad.IO.Class
import Control.Monad.Logger
import Control.Monad.Reader
import Control.Monad.Trans.Control (MonadBaseControl)
import Data.Aeson
import qualified Data.ByteString as S
import qualified Data.ByteString.Char8 as S8
Expand All @@ -23,13 +25,15 @@ import Data.Maybe
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as T
import Network.HTTP.Client.Conduit
import Path
import Path.IO
import Stack.Constants
import Stack.Exec (defaultEnvSettings)
import Stack.Package
import Stack.Ghci (GhciPkgInfo(..), ghciSetup)
import Stack.Package
import Stack.Types
import Stack.Types.Internal
import System.Directory (doesFileExist)
import System.Environment (lookupEnv)
import System.Exit
Expand All @@ -41,7 +45,7 @@ import System.Process.Read
-- given options and configure it with the load paths and extensions
-- of those targets.
ide
:: (HasConfig r, HasBuildConfig r, HasEnvConfig r, MonadReader r m, MonadIO m, MonadThrow m, MonadLogger m, MonadCatch m)
:: (HasConfig r, HasBuildConfig r, HasEnvConfig r, MonadReader r m, MonadIO m, MonadThrow m, MonadLogger m, MonadCatch m, MonadBaseControl IO m, HasTerminal r, HasHttpManager r, MonadMask m, HasLogLevel r)
=> [Text] -- ^ Targets.
-> [String] -- ^ GHC options.
-> m ()
Expand Down
4 changes: 3 additions & 1 deletion src/Stack/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ buildOptsParser :: Command
-> Parser BuildOpts
buildOptsParser cmd defCopyBins =
BuildOpts <$> target <*> libProfiling <*> exeProfiling <*>
optimize <*> haddock <*> haddockDeps <*> finalAction <*> dryRun <*> ghcOpts <*>
optimize <*> enableTests <*> enableBench <*> haddock <*> haddockDeps <*> finalAction <*> dryRun <*> ghcOpts <*>
flags <*> copyBins <*> preFetch <*>
((||) <$> onlySnapshot <*> onlyDependencies) <*>
fileWatch' <*> keepGoing <*> forceDirty
where optimize =
maybeBoolFlags "optimizations" "optimizations for TARGETs and all its dependencies" idm
enableTests = pure False
enableBench = pure False
target =
fmap (map T.pack)
(many (strArgument
Expand Down
14 changes: 13 additions & 1 deletion src/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,19 @@ buildCmdHelper beforeBuild finalAction opts go
where
inner setLocalFiles = withBuildConfigAndLock go $ \lk -> do
beforeBuild
Stack.Build.build setLocalFiles (Just lk) opts { boptsFinalAction = finalAction }
Stack.Build.build
setLocalFiles
(Just lk)
opts { boptsFinalAction = finalAction
, boptsEnableTests =
case finalAction of
DoTests{} -> True
_ -> False
, boptsEnableBenchmarks =
case finalAction of
DoBenchmarks{} -> True
_ -> False
}

-- | Build the project.
buildCmd :: FinalAction -> BuildOpts -> GlobalOpts -> IO ()
Expand Down