aboutsummaryrefslogtreecommitdiff
path: root/src/CabalHelper
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2019-01-22 01:14:10 +0100
committerDaniel Gröber <dxld@darkboxed.org>2019-01-26 02:59:27 +0100
commitec0067142368dbf1ac92f8ba056043d52e41af8b (patch)
tree9089db0b980dbdafb838e1ea139c15f56334b5c7 /src/CabalHelper
parent541d219dbcf097c0c50b4ee0216f270c9c8c1342 (diff)
Add Stack version check for `stack ide packages --cabal-file`
Diffstat (limited to 'src/CabalHelper')
-rw-r--r--src/CabalHelper/Compiletime/Program/Stack.hs26
-rw-r--r--src/CabalHelper/Shared/Common.hs16
2 files changed, 38 insertions, 4 deletions
diff --git a/src/CabalHelper/Compiletime/Program/Stack.hs b/src/CabalHelper/Compiletime/Program/Stack.hs
index 33ba031..518e7f9 100644
--- a/src/CabalHelper/Compiletime/Program/Stack.hs
+++ b/src/CabalHelper/Compiletime/Program/Stack.hs
@@ -83,11 +83,35 @@ paths qe@QueryEnv{qeProjLoc=ProjLocStackYaml stack_yaml} cwd
split l = let (key, ' ' : val) = span (not . isSpace) l in (key, val)
listPackageCabalFiles :: QueryEnvI c 'Stack -> IO [CabalFile]
-listPackageCabalFiles qe@QueryEnv{qeProjLoc=ProjLocStackYaml stack_yaml} = do
+listPackageCabalFiles qe@QueryEnv{qeProjLoc=ProjLocStackYaml stack_yaml}
+ = handle ioerror $ do
let projdir = takeDirectory stack_yaml
out <- readStackCmd qe (Just projdir)
[ "ide", "packages", "--cabal-files", "--stdout" ]
return $ map CabalFile $ lines out
+ where
+ ioerror :: IOError -> IO a
+ ioerror ioe = (=<<) (fromMaybe (throwIO ioe)) $ runMaybeT $ do
+ stack_exe <- MaybeT $ findExecutable $ stackProgram $ qePrograms qe
+ stack_ver_str
+ <- liftIO $ trim <$> readStackCmd qe Nothing ["--numeric-version"]
+ stack_ver <- MaybeT $ return $ parseVerMay stack_ver_str
+ guard $ stack_ver < makeVersion [1,9,4]
+
+ let prog_cfg = ppShow $ qePrograms qe
+
+ liftIO $ hPutStrLn stderr $ printf
+ "\nerror: stack version too old!\
+ \\n\n\
+ \You have '%s' installed but cabal-helper needs at least\n\
+ \stack version 1.9.4+.\n\
+ \\n\
+ \FYI cabal-helper is using the following `stack` executable:\n\
+ \ %s\n\
+ \\n\
+ \Additional debugging info: QueryEnv qePrograms =\n\
+ \ %s\n" stack_ver_str stack_exe prog_cfg
+ mzero
workdirArg :: QueryEnvI c 'Stack -> [String]
workdirArg QueryEnv{qeDistDir=DistDirStack mworkdir} =
diff --git a/src/CabalHelper/Shared/Common.hs b/src/CabalHelper/Shared/Common.hs
index 4165ab0..2d4b037 100644
--- a/src/CabalHelper/Shared/Common.hs
+++ b/src/CabalHelper/Shared/Common.hs
@@ -104,6 +104,9 @@ parsePkgId bs =
parseVer :: String -> Version
parseVer vers = runReadP parseVersion vers
+parseVerMay :: String -> Maybe Version
+parseVerMay vers = runReadPMay parseVersion vers
+
trim :: String -> String
trim = dropWhileEnd isSpace
@@ -114,9 +117,16 @@ sameMajorVersionAs :: Version -> Version -> Bool
sameMajorVersionAs a b = majorVer a == majorVer b
runReadP :: ReadP t -> String -> t
-runReadP p i = case filter ((=="") . snd) $ readP_to_S p i of
- (a,""):[] -> a
- _ -> error $ "Error parsing: " ++ show i
+runReadP p i =
+ case runReadPMay p i of
+ Just x -> x
+ Nothing -> error $ "Error parsing version: " ++ show i
+
+runReadPMay :: ReadP t -> String -> Maybe t
+runReadPMay p i = case filter ((=="") . snd) $ readP_to_S p i of
+ (a,""):[] -> Just a
+ _ -> Nothing
+
appCacheDir :: IO FilePath
appCacheDir =