Fix all the stack related things
This commit is contained in:
parent
d660e7cd85
commit
78bdf86a95
@ -16,6 +16,7 @@ cache:
|
|||||||
directories:
|
directories:
|
||||||
- ~/.cabal
|
- ~/.cabal
|
||||||
- ~/.ghc
|
- ~/.ghc
|
||||||
|
- ~/.stack
|
||||||
|
|
||||||
before_cache:
|
before_cache:
|
||||||
- rm -f $HOME/.cabal/logs $HOME/.cabal/packages/*/build-reports.log
|
- rm -f $HOME/.cabal/logs $HOME/.cabal/packages/*/build-reports.log
|
||||||
|
@ -53,24 +53,24 @@ import Paths_ghc_mod as GhcMod
|
|||||||
-- access home modules
|
-- access home modules
|
||||||
getGhcMergedPkgOptions :: (Applicative m, IOish m, GmEnv m, GmState m, GmLog m)
|
getGhcMergedPkgOptions :: (Applicative m, IOish m, GmEnv m, GmState m, GmLog m)
|
||||||
=> m [GHCOption]
|
=> m [GHCOption]
|
||||||
getGhcMergedPkgOptions = chCached $ \distDir -> Cached {
|
getGhcMergedPkgOptions = chCached $ \distdir -> Cached {
|
||||||
cacheLens = Just (lGmcMergedPkgOptions . lGmCaches),
|
cacheLens = Just (lGmcMergedPkgOptions . lGmCaches),
|
||||||
cacheFile = distDir </> mergedPkgOptsCacheFile,
|
cacheFile = mergedPkgOptsCacheFile distdir,
|
||||||
cachedAction = \ _tcf (progs, rootdir, distdir, _) _ma -> do
|
cachedAction = \ _tcf (progs, rootdir, _) _ma -> do
|
||||||
readProc <- gmReadProcess
|
readProc <- gmReadProcess
|
||||||
opts <- withCabal $ runQuery'' readProc progs rootdir distdir $
|
opts <- withCabal $ runQuery'' readProc progs rootdir distdir $
|
||||||
ghcMergedPkgOptions
|
ghcMergedPkgOptions
|
||||||
return ([distDir </> setupConfigPath], opts)
|
return ([setupConfigPath distdir], opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
getCabalPackageDbStack :: (IOish m, GmEnv m, GmState m, GmLog m) => m [GhcPkgDb]
|
getCabalPackageDbStack :: (IOish m, GmEnv m, GmState m, GmLog m) => m [GhcPkgDb]
|
||||||
getCabalPackageDbStack = chCached $ \distDir -> Cached {
|
getCabalPackageDbStack = chCached $ \distdir -> Cached {
|
||||||
cacheLens = Just (lGmcPackageDbStack . lGmCaches),
|
cacheLens = Just (lGmcPackageDbStack . lGmCaches),
|
||||||
cacheFile = distDir </> pkgDbStackCacheFile,
|
cacheFile = pkgDbStackCacheFile distdir,
|
||||||
cachedAction = \ _tcf (progs, rootdir, distdir, _) _ma -> do
|
cachedAction = \ _tcf (progs, rootdir, _) _ma -> do
|
||||||
readProc <- gmReadProcess
|
readProc <- gmReadProcess
|
||||||
dbs <- withCabal $ map chPkgToGhcPkg <$> runQuery'' readProc progs rootdir distdir packageDbStack
|
dbs <- withCabal $ map chPkgToGhcPkg <$> runQuery'' readProc progs rootdir distdir packageDbStack
|
||||||
return ([distDir </> setupConfigPath, sandboxConfigFile], dbs)
|
return ([setupConfigPath distdir, sandboxConfigFile], dbs)
|
||||||
}
|
}
|
||||||
|
|
||||||
chPkgToGhcPkg :: ChPkgDb -> GhcPkgDb
|
chPkgToGhcPkg :: ChPkgDb -> GhcPkgDb
|
||||||
@ -85,10 +85,10 @@ chPkgToGhcPkg (ChPkgSpecific f) = PackageDb f
|
|||||||
-- 'resolveGmComponents'.
|
-- 'resolveGmComponents'.
|
||||||
getComponents :: (Applicative m, IOish m, GmEnv m, GmState m, GmLog m)
|
getComponents :: (Applicative m, IOish m, GmEnv m, GmState m, GmLog m)
|
||||||
=> m [GmComponent 'GMCRaw ChEntrypoint]
|
=> m [GmComponent 'GMCRaw ChEntrypoint]
|
||||||
getComponents = chCached$ \distDir -> Cached {
|
getComponents = chCached$ \distdir -> Cached {
|
||||||
cacheLens = Just (lGmcComponents . lGmCaches),
|
cacheLens = Just (lGmcComponents . lGmCaches),
|
||||||
cacheFile = distDir </> cabalHelperCacheFile,
|
cacheFile = cabalHelperCacheFile distdir,
|
||||||
cachedAction = \ _tcf (progs, rootdir, distdir, _vers) _ma -> do
|
cachedAction = \ _tcf (progs, rootdir, _vers) _ma -> do
|
||||||
readProc <- gmReadProcess
|
readProc <- gmReadProcess
|
||||||
runQuery'' readProc progs rootdir distdir $ do
|
runQuery'' readProc progs rootdir distdir $ do
|
||||||
q <- join7
|
q <- join7
|
||||||
@ -100,7 +100,7 @@ getComponents = chCached$ \distDir -> Cached {
|
|||||||
<*> entrypoints
|
<*> entrypoints
|
||||||
<*> sourceDirs
|
<*> sourceDirs
|
||||||
let cs = flip map q $ curry8 (GmComponent mempty)
|
let cs = flip map q $ curry8 (GmComponent mempty)
|
||||||
return ([distDir </> setupConfigPath], cs)
|
return ([setupConfigPath distdir], cs)
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
curry8 fn (a, (b, (c, (d, (e, (f, (g, h))))))) = fn a b c d e f g h
|
curry8 fn (a, (b, (c, (d, (e, (f, (g, h))))))) = fn a b c d e f g h
|
||||||
@ -226,14 +226,15 @@ chCached :: (Applicative m, IOish m, GmEnv m, GmState m, GmLog m, Serialize a)
|
|||||||
chCached c = do
|
chCached c = do
|
||||||
root <- cradleRootDir <$> cradle
|
root <- cradleRootDir <$> cradle
|
||||||
dist <- cradleDistDir <$> cradle
|
dist <- cradleDistDir <$> cradle
|
||||||
d <- cacheInputData root dist
|
d <- cacheInputData root
|
||||||
withCabal $ cached root (c dist) d
|
withCabal $ cached root (c dist) d
|
||||||
where
|
where
|
||||||
cacheInputData root dist = do
|
-- we don't need to include the disdir in the cache input because when it
|
||||||
|
-- changes the cache files will be gone anyways ;)
|
||||||
|
cacheInputData root = do
|
||||||
opt <- options
|
opt <- options
|
||||||
return $ ( helperProgs opt
|
return $ ( helperProgs opt
|
||||||
, root
|
, root
|
||||||
, root </> dist
|
|
||||||
, (gmVer, chVer)
|
, (gmVer, chVer)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -49,4 +49,4 @@ data TimedCacheFiles = TimedCacheFiles {
|
|||||||
-- ^ Timestamped files returned by the cached action
|
-- ^ Timestamped files returned by the cached action
|
||||||
} deriving (Eq, Ord, Show)
|
} deriving (Eq, Ord, Show)
|
||||||
|
|
||||||
type ChCacheData = (Programs, FilePath, FilePath, (Version, [Char]))
|
type ChCacheData = (Programs, FilePath, (Version, [Char]))
|
||||||
|
@ -75,7 +75,7 @@ stackCradle wdir = do
|
|||||||
let cabalDir = takeDirectory cabalFile
|
let cabalDir = takeDirectory cabalFile
|
||||||
|
|
||||||
_stackConfigFile <- MaybeT $ findStackConfigFile cabalDir
|
_stackConfigFile <- MaybeT $ findStackConfigFile cabalDir
|
||||||
distDir <- liftIO $ findStackDistDir cabalDir
|
distDir <- MaybeT $ getStackDistDir cabalDir
|
||||||
|
|
||||||
return Cradle {
|
return Cradle {
|
||||||
cradleProjectType = StackProject
|
cradleProjectType = StackProject
|
||||||
|
@ -22,6 +22,7 @@ module Language.Haskell.GhcMod.PathsAndFiles (
|
|||||||
import Config (cProjectVersion)
|
import Config (cProjectVersion)
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
import Control.Monad.Trans.Maybe
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Char
|
import Data.Char
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
@ -74,13 +75,10 @@ findCabalFile dir = do
|
|||||||
findStackConfigFile :: FilePath -> IO (Maybe FilePath)
|
findStackConfigFile :: FilePath -> IO (Maybe FilePath)
|
||||||
findStackConfigFile dir = mightExist (dir </> "stack.yaml")
|
findStackConfigFile dir = mightExist (dir </> "stack.yaml")
|
||||||
|
|
||||||
findStackDistDir :: FilePath -> IO FilePath
|
getStackDistDir :: FilePath -> IO (Maybe FilePath)
|
||||||
findStackDistDir dir = U.withDirectory_ dir $ do
|
getStackDistDir dir = U.withDirectory_ dir $ runMaybeT $ do
|
||||||
mstack <- liftIO $ findExecutable "stack"
|
stack <- MaybeT $ findExecutable "stack"
|
||||||
case mstack of
|
liftIO $ takeWhile (/='\n') <$> readProcess stack ["path", "--dist-dir"] ""
|
||||||
Nothing -> return "dist"
|
|
||||||
Just stack ->
|
|
||||||
takeWhile (/='\n') <$> readProcess stack ["path", "--dist-dir"] ""
|
|
||||||
|
|
||||||
-- | Get path to sandbox config file
|
-- | Get path to sandbox config file
|
||||||
getSandboxDb :: FilePath
|
getSandboxDb :: FilePath
|
||||||
@ -190,14 +188,16 @@ parents dir' =
|
|||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
setupConfigFile :: Cradle -> FilePath
|
setupConfigFile :: Cradle -> FilePath
|
||||||
setupConfigFile crdl = cradleRootDir crdl </> cradleDistDir crdl </> setupConfigPath
|
setupConfigFile crdl =
|
||||||
|
cradleRootDir crdl </> setupConfigPath (cradleDistDir crdl)
|
||||||
|
|
||||||
sandboxConfigFile :: FilePath
|
sandboxConfigFile :: FilePath
|
||||||
sandboxConfigFile = "cabal.sandbox.config"
|
sandboxConfigFile = "cabal.sandbox.config"
|
||||||
|
|
||||||
-- | Path to 'LocalBuildInfo' file, usually @dist/setup-config@
|
-- | Path to 'LocalBuildInfo' file, usually @dist/setup-config@
|
||||||
setupConfigPath :: FilePath
|
setupConfigPath :: FilePath -> FilePath
|
||||||
setupConfigPath = "setup-config" -- localBuildInfoFile defaultDistPref
|
setupConfigPath dist = dist </> "setup-config"
|
||||||
|
-- localBuildInfoFile defaultDistPref
|
||||||
|
|
||||||
macrosHeaderPath :: FilePath
|
macrosHeaderPath :: FilePath
|
||||||
macrosHeaderPath = "build/autogen/cabal_macros.h"
|
macrosHeaderPath = "build/autogen/cabal_macros.h"
|
||||||
@ -216,17 +216,21 @@ symbolCache crdl = cradleTempDir crdl </> symbolCacheFile
|
|||||||
symbolCacheFile :: String
|
symbolCacheFile :: String
|
||||||
symbolCacheFile = "ghc-mod.symbol-cache"
|
symbolCacheFile = "ghc-mod.symbol-cache"
|
||||||
|
|
||||||
resolvedComponentsCacheFile :: String
|
resolvedComponentsCacheFile :: FilePath -> FilePath
|
||||||
resolvedComponentsCacheFile = setupConfigPath <.> "ghc-mod.resolved-components"
|
resolvedComponentsCacheFile dist =
|
||||||
|
setupConfigPath dist <.> "ghc-mod.resolved-components"
|
||||||
|
|
||||||
cabalHelperCacheFile :: String
|
cabalHelperCacheFile :: FilePath -> FilePath
|
||||||
cabalHelperCacheFile = setupConfigPath <.> "ghc-mod.cabal-components"
|
cabalHelperCacheFile dist =
|
||||||
|
setupConfigPath dist <.> "ghc-mod.cabal-components"
|
||||||
|
|
||||||
mergedPkgOptsCacheFile :: String
|
mergedPkgOptsCacheFile :: FilePath -> FilePath
|
||||||
mergedPkgOptsCacheFile = setupConfigPath <.> "ghc-mod.package-options"
|
mergedPkgOptsCacheFile dist =
|
||||||
|
setupConfigPath dist <.> "ghc-mod.package-options"
|
||||||
|
|
||||||
pkgDbStackCacheFile :: String
|
pkgDbStackCacheFile :: FilePath -> FilePath
|
||||||
pkgDbStackCacheFile = setupConfigPath <.> "ghc-mod.package-db-stack"
|
pkgDbStackCacheFile dist =
|
||||||
|
setupConfigPath dist <.> "ghc-mod.package-db-stack"
|
||||||
|
|
||||||
-- | @findCustomPackageDbFile dir@. Searches for a @.ghc-mod.cradle@ file in @dir@.
|
-- | @findCustomPackageDbFile dir@. Searches for a @.ghc-mod.cradle@ file in @dir@.
|
||||||
-- If it exists in the given directory it is returned otherwise @findCradleFile@ returns @Nothing@
|
-- If it exists in the given directory it is returned otherwise @findCradleFile@ returns @Nothing@
|
||||||
|
@ -182,9 +182,9 @@ resolvedComponentsCache :: IOish m => FilePath ->
|
|||||||
Cached (GhcModT m) GhcModState
|
Cached (GhcModT m) GhcModState
|
||||||
[GmComponent 'GMCRaw (Set.Set ModulePath)]
|
[GmComponent 'GMCRaw (Set.Set ModulePath)]
|
||||||
(Map.Map ChComponentName (GmComponent 'GMCResolved (Set.Set ModulePath)))
|
(Map.Map ChComponentName (GmComponent 'GMCResolved (Set.Set ModulePath)))
|
||||||
resolvedComponentsCache distDir = Cached {
|
resolvedComponentsCache distdir = Cached {
|
||||||
cacheLens = Just (lGmcResolvedComponents . lGmCaches),
|
cacheLens = Just (lGmcResolvedComponents . lGmCaches),
|
||||||
cacheFile = distDir </> resolvedComponentsCacheFile,
|
cacheFile = resolvedComponentsCacheFile distdir,
|
||||||
cachedAction = \tcfs comps ma -> do
|
cachedAction = \tcfs comps ma -> do
|
||||||
Cradle {..} <- cradle
|
Cradle {..} <- cradle
|
||||||
let iifsM = invalidatingInputFiles tcfs
|
let iifsM = invalidatingInputFiles tcfs
|
||||||
@ -195,13 +195,13 @@ resolvedComponentsCache distDir = Cached {
|
|||||||
Just iifs ->
|
Just iifs ->
|
||||||
let
|
let
|
||||||
filterOutSetupCfg =
|
filterOutSetupCfg =
|
||||||
filter (/= cradleRootDir </> cradleDistDir </> setupConfigPath)
|
filter (/= cradleRootDir </> setupConfigPath distdir)
|
||||||
changedFiles = filterOutSetupCfg iifs
|
changedFiles = filterOutSetupCfg iifs
|
||||||
in if null changedFiles
|
in if null changedFiles
|
||||||
then Nothing
|
then Nothing
|
||||||
else Just $ map Left changedFiles
|
else Just $ map Left changedFiles
|
||||||
setupChanged = maybe False
|
setupChanged = maybe False
|
||||||
(elem $ cradleRootDir </> cradleDistDir </> setupConfigPath)
|
(elem $ cradleRootDir </> setupConfigPath distdir)
|
||||||
iifsM
|
iifsM
|
||||||
case (setupChanged, ma) of
|
case (setupChanged, ma) of
|
||||||
(False, Just mcs) -> gmsGet >>= \s -> gmsPut s { gmComponents = mcs }
|
(False, Just mcs) -> gmsGet >>= \s -> gmsPut s { gmComponents = mcs }
|
||||||
@ -218,7 +218,7 @@ resolvedComponentsCache distDir = Cached {
|
|||||||
text "files changed" <+>: changedDoc
|
text "files changed" <+>: changedDoc
|
||||||
|
|
||||||
mcs <- resolveGmComponents mums comps
|
mcs <- resolveGmComponents mums comps
|
||||||
return ((cradleDistDir </> setupConfigPath) : flatten mcs , mcs)
|
return (setupConfigPath distdir : flatten mcs , mcs)
|
||||||
}
|
}
|
||||||
|
|
||||||
where
|
where
|
||||||
|
@ -85,11 +85,12 @@ Extra-Source-Files: ChangeLog
|
|||||||
test/data/file-mapping/preprocessor/*.hs
|
test/data/file-mapping/preprocessor/*.hs
|
||||||
test/data/file-mapping/lhs/*.lhs
|
test/data/file-mapping/lhs/*.lhs
|
||||||
test/data/nice-qualification/*.hs
|
test/data/nice-qualification/*.hs
|
||||||
|
test/data/stack-project/stack.yaml
|
||||||
test/data/stack-project/new-template.cabal
|
test/data/stack-project/new-template.cabal
|
||||||
test/data/stack-project/Setup.hs
|
test/data/stack-project/*.hs
|
||||||
test/data/stack-project/app/Main.hs
|
test/data/stack-project/app/*.hs
|
||||||
test/data/stack-project/src/Lib.hs
|
test/data/stack-project/src/*.hs
|
||||||
test/data/stack-project/test/Spec.hs
|
test/data/stack-project/test/*.hs
|
||||||
|
|
||||||
Library
|
Library
|
||||||
Default-Language: Haskell2010
|
Default-Language: Haskell2010
|
||||||
|
@ -58,10 +58,9 @@ spec = do
|
|||||||
|
|
||||||
it "handles stack project" $ do
|
it "handles stack project" $ do
|
||||||
let tdir = "test/data/stack-project"
|
let tdir = "test/data/stack-project"
|
||||||
opts <- map gmcGhcOpts <$> runD' tdir getComponents
|
[ghcOpts] <- map gmcGhcOpts . filter ((==ChExeName "new-template-exe") . gmcName) <$> runD' tdir getComponents
|
||||||
let ghcOpts = head opts
|
let pkgs = pkgOptions ghcOpts
|
||||||
pkgs = pkgOptions ghcOpts
|
pkgs `shouldBe` ["base", "bytestring"]
|
||||||
pkgs `shouldBe` ["Cabal","base","new-template"]
|
|
||||||
|
|
||||||
it "extracts build dependencies" $ do
|
it "extracts build dependencies" $ do
|
||||||
let tdir = "test/data/cabal-project"
|
let tdir = "test/data/cabal-project"
|
||||||
|
22
test/Main.hs
22
test/Main.hs
@ -28,12 +28,6 @@ main = do
|
|||||||
genSandboxCfg `mapM_` sandboxes
|
genSandboxCfg `mapM_` sandboxes
|
||||||
genGhcPkgCache `mapM_` pkgDirs
|
genGhcPkgCache `mapM_` pkgDirs
|
||||||
|
|
||||||
let stackDir = "test/data/stack-project"
|
|
||||||
void $ withDirectory_ stackDir $ do
|
|
||||||
void $ system "stack init --force"
|
|
||||||
void $ system "stack setup"
|
|
||||||
void $ system "stack build"
|
|
||||||
|
|
||||||
let caches = [ "setup-config"
|
let caches = [ "setup-config"
|
||||||
, "setup-config.ghc-mod.cabal-helper"
|
, "setup-config.ghc-mod.cabal-helper"
|
||||||
, "setup-config.ghc-mod.cabal-components"
|
, "setup-config.ghc-mod.cabal-components"
|
||||||
@ -42,16 +36,26 @@ main = do
|
|||||||
, "setup-config.ghc-mod.package-db-stack"
|
, "setup-config.ghc-mod.package-db-stack"
|
||||||
, "ghc-mod.cache"
|
, "ghc-mod.cache"
|
||||||
]
|
]
|
||||||
cachesFindExp :: String
|
findExp = unwords $ intersperse "-o " $ concat [
|
||||||
cachesFindExp = unwords $ intersperse "-o " $ map ("-name "++) caches
|
stackWorkFindExp,
|
||||||
|
cachesFindExp
|
||||||
|
]
|
||||||
|
cachesFindExp = map ("-name "++) caches
|
||||||
|
stackWorkFindExp = ["-name .stack-work -type d"]
|
||||||
|
|
||||||
cleanCmd = "find test \\( "++ cachesFindExp ++" \\) -exec rm {} \\;"
|
cleanCmd = "find test \\( "++ findExp ++" \\) -exec rm -r {} \\;"
|
||||||
|
|
||||||
putStrLn $ "$ " ++ cleanCmd
|
putStrLn $ "$ " ++ cleanCmd
|
||||||
void $ system cleanCmd
|
void $ system cleanCmd
|
||||||
void $ system "cabal --version"
|
void $ system "cabal --version"
|
||||||
void $ system "ghc --version"
|
void $ system "ghc --version"
|
||||||
|
|
||||||
|
let stackDir = "test/data/stack-project"
|
||||||
|
void $ withDirectory_ stackDir $ do
|
||||||
|
-- void $ system "stack init --force"
|
||||||
|
void $ system "stack setup"
|
||||||
|
void $ system "stack build"
|
||||||
|
|
||||||
(putStrLn =<< runD debugInfo)
|
(putStrLn =<< runD debugInfo)
|
||||||
`E.catch` (\(_ :: E.SomeException) -> return () )
|
`E.catch` (\(_ :: E.SomeException) -> return () )
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ executable new-template-exe
|
|||||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
||||||
build-depends: base
|
build-depends: base
|
||||||
, new-template
|
, new-template
|
||||||
|
, bytestring
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
test-suite new-template-test
|
test-suite new-template-test
|
||||||
|
5
test/data/stack-project/stack.yaml
Normal file
5
test/data/stack-project/stack.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
flags: {}
|
||||||
|
packages:
|
||||||
|
- '.'
|
||||||
|
extra-deps: []
|
||||||
|
resolver: lts-2.17
|
Loading…
Reference in New Issue
Block a user