-
Notifications
You must be signed in to change notification settings - Fork 175
Explicit project (Was: #585) #806
Changes from all commits
2ce8c98
23e5f88
319587d
e50639d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,6 @@ import Exception | |
import Language.Haskell.GhcMod.Convert | ||
import Language.Haskell.GhcMod.Gap | ||
import Language.Haskell.GhcMod.Monad | ||
import Language.Haskell.GhcMod.Output | ||
import Language.Haskell.GhcMod.Types | ||
import Language.Haskell.GhcMod.Utils | ||
import Language.Haskell.GhcMod.World | ||
|
@@ -120,26 +119,23 @@ loadSymbolDb' = do | |
return db | ||
doLoad =<< liftIO (doesFileExist cache) | ||
|
||
-- | Loading a file and creates 'SymbolDb'. | ||
loadSymbolDb :: IOish m => GhcModT m SymbolDb | ||
loadSymbolDb = do | ||
ghcMod <- liftIO ghcModExecutable | ||
readProc <- gmReadProcess' | ||
out <- liftIO $ readProc ghcMod ["--verbose", "error", "dumpsym"] "" | ||
return $!! decode out | ||
ts <- liftIO getCurrentModTime | ||
st <- runGmPkgGhc getGlobalSymbolTable | ||
return SymbolDb { | ||
sdTable = st | ||
, sdTimestamp = ts | ||
} | ||
|
||
---------------------------------------------------------------- | ||
-- used 'ghc-mod dumpsym' | ||
|
||
-- | Dumps a 'Binary' representation of 'SymbolDb' to stdout | ||
dumpSymbol :: IOish m => GhcModT m () | ||
dumpSymbol = do | ||
ts <- liftIO getCurrentModTime | ||
st <- runGmPkgGhc $ getGlobalSymbolTable | ||
liftIO . LBS.putStr $ encode SymbolDb { | ||
sdTable = st | ||
, sdTimestamp = ts | ||
} | ||
symbolDb <- loadSymbolDb | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here obviously. |
||
liftIO . LBS.putStr $ encode symbolDb | ||
|
||
-- | Check whether given file is older than any file from the given set. | ||
-- Returns True if given file does not exist. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ import GHC | |
#if __GLASGOW_HASKELL__ >= 800 | ||
import GHC.LanguageExtensions | ||
#endif | ||
import GHC.Paths (libdir) | ||
import SysTools | ||
import DynFlags | ||
import HscTypes | ||
|
@@ -106,7 +105,7 @@ initSession opts mdf = do | |
putNewSession s = do | ||
crdl <- cradle | ||
nhsc_env_ref <- liftIO . newIORef =<< newLightEnv (initDF crdl) | ||
runLightGhc' nhsc_env_ref $ setSessionDynFlags =<< getSessionDynFlags | ||
void $ runLightGhc' nhsc_env_ref $ setSessionDynFlags =<< getSessionDynFlags | ||
gmsPut s { gmGhcSession = Just $ GmGhcSession nhsc_env_ref } | ||
|
||
|
||
|
@@ -188,12 +187,22 @@ targetGhcOptions crdl sefnmn = do | |
when (Set.null sefnmn) $ error "targetGhcOptions: no targets given" | ||
|
||
case cradleProject crdl of | ||
proj | ||
| isCabalHelperProject proj -> cabalOpts crdl | ||
| otherwise -> sandboxOpts crdl | ||
proj | isCabalHelperProject proj -> cabalOpts crdl | ||
ExplicitProject -> do | ||
opts <- explicitOpts crdl | ||
dbStack <- maybe [] id <$> getCustomPkgDbStack | ||
return $ opts ++ ghcDbStackOpts dbStack | ||
_ -> sandboxOpts crdl | ||
where | ||
zipMap f l = l `zip` (f `map` l) | ||
|
||
explicitOpts :: Cradle -> GhcModT m [String] | ||
explicitOpts Cradle {..} = case cradleCabalFile of | ||
Nothing -> return [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain what you're doing here? Looking at what Also maybe you could put the optionsFile in the ExplicitProject constructor like we do with the StackEnv stuff? |
||
Just optionsFile -> do | ||
contents <- liftIO $ readFile optionsFile | ||
return $ lines contents | ||
|
||
cabalOpts :: Cradle -> GhcModT m [String] | ||
cabalOpts Cradle{..} = do | ||
mcs <- cabalResolvedComponents | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,8 +94,12 @@ Extra-Source-Files: ChangeLog | |
test/data/stack-project/app/*.hs | ||
test/data/stack-project/src/*.hs | ||
test/data/stack-project/test/*.hs | ||
bench/data/simple-cabal/simple-cabal.cabal | ||
bench/data/simple-cabal/*.hs | ||
test/data/options-cradle/ghc-mod.options | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you removing these? Are they no longer used? |
||
test/data/options-cradle/ghc-mod.package-db-stack | ||
test/data/options-cradle/package-db-a/package.cache | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so you don't want to check in package.cache into repo, since it's ghc-specific binary format which can (and will) change, and your tests will fail for no good reason with something like |
||
test/data/options-cradle/package-db-b/package.cache | ||
test/data/options-cradle/package-db-c/package.cache | ||
test/data/options-cradle/src/*.hs | ||
|
||
Custom-Setup | ||
Setup-Depends: base | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ module TestUtils ( | |
, shouldReturnError | ||
, isPkgDbAt | ||
, isPkgConfDAt | ||
, bracketTagged | ||
, module Language.Haskell.GhcMod.Monad | ||
, module Language.Haskell.GhcMod.Types | ||
) where | ||
|
@@ -22,13 +23,16 @@ import Language.Haskell.GhcMod.Types | |
import Control.Arrow | ||
import Control.Category | ||
import Control.Applicative | ||
import Control.Monad | ||
import Control.Monad.Error (ErrorT, runErrorT) | ||
import Control.Monad.Trans.Journal | ||
import Data.List.Split | ||
import Data.Label | ||
import Data.String | ||
import Dir | ||
import System.FilePath | ||
import System.Directory | ||
import System.Process | ||
import Test.Hspec | ||
import Prelude hiding ((.)) | ||
|
||
|
@@ -122,3 +126,16 @@ isPkgDbAt _ _ = False | |
|
||
instance IsString ModuleName where | ||
fromString = mkModuleName | ||
|
||
-- | Bracketing function for test/data/options-cradle environment to install tagged in package-db-a | ||
bracketTagged :: IO a -> IO a | ||
bracketTagged m = do | ||
withDirectory_ "test/data/options-cradle" $ do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hiding the directory in here is confusing, just took me more than 30sec to find that :p |
||
void $ system "cabal install --global --package-db=package-db-a --prefix=$(pwd) tagged" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly I'd rather the tests didn't start installing stuff with cabal, is there a particular reason you need to install a package rather than just, say using one of the boot packages like |
||
putStrLn "start" | ||
void $ system "ghc-pkg list --global --user --package-db=package-db-a tagged" | ||
putStrLn "stop" | ||
res <- m | ||
void $ system "ghc-pkg --package-db=package-db-a unregister tagged" | ||
-- void $ system "cabal sandbox delete" | ||
return res |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
global | ||
user | ||
package-db-a | ||
package-db-b | ||
package-db-c |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-isrc | ||
-DINTERPRETED |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
global | ||
user | ||
package-db-a | ||
package-db-b | ||
package-db-c |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Main | ||
( main | ||
, foo | ||
) where | ||
|
||
import Data.Tagged | ||
|
||
main :: IO () | ||
main = return () | ||
|
||
foo :: Int | ||
foo = 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Main2 | ||
( main | ||
, foo | ||
) where | ||
|
||
main :: IO () | ||
main = return () | ||
|
||
foo :: Int | ||
foo = 0 + id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no good, there is a reason we do this in another process (memory usage). Please revert.