diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2019-03-31 23:31:44 +0200 |
---|---|---|
committer | Daniel Gröber <dxld@darkboxed.org> | 2019-04-01 20:37:54 +0200 |
commit | e7ff295ff2f2ed1e7682bd1d33738e7b2b0b78fd (patch) | |
tree | b9f0fd8b74f61032ae7f27a542bae273a987ecde /src/CabalHelper/Shared | |
parent | 2f9523feb2e108dcb731e08ec467ad06edecdd39 (diff) |
Make compilerVersion accessor project-scope for V1 projects
Diffstat (limited to 'src/CabalHelper/Shared')
-rw-r--r-- | src/CabalHelper/Shared/Common.hs | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/src/CabalHelper/Shared/Common.hs b/src/CabalHelper/Shared/Common.hs index 2d4b037..d65722b 100644 --- a/src/CabalHelper/Shared/Common.hs +++ b/src/CabalHelper/Shared/Common.hs @@ -81,24 +81,18 @@ errMsg str = do prog <- getProgName hPutStrLn stderr $ prog ++ ": " ++ str --- | @getCabalConfigHeader "dist/setup-config"@ returns the cabal version and --- compiler version -getCabalConfigHeader :: FilePath -> IO (Maybe (Version, (ByteString, Version))) -getCabalConfigHeader file = bracket (openFile file ReadMode) hClose $ \h -> do - parseHeader <$> BS.hGetLine h - -parseHeader :: ByteString -> Maybe (Version, (ByteString, Version)) -parseHeader header = case BS8.words header of - ["Saved", "package", "config", "for", _pkgId , - "written", "by", cabalId, - "using", compId] - -> liftM2 (,) (snd <$> parsePkgId cabalId) (parsePkgId compId) - _ -> Nothing - -parsePkgId :: ByteString -> Maybe (ByteString, Version) -parsePkgId bs = - case BS8.split '-' bs of - [pkg, vers] -> Just (pkg, parseVer $ BS8.unpack vers) +parsePkgId :: String -> Maybe (String, Version) +parsePkgId s = + case span (/='-') (reverse s) of + (vers, '-':pkg) -> Just (reverse pkg, parseVer (reverse vers)) + _ -> Nothing + +parsePkgIdBS :: ByteString -> Maybe (ByteString, Version) +parsePkgIdBS bs = + case BS8.span (/='-') (BS.reverse bs) of + (vers, pkg') -> + Just ( BS.reverse $ BS.tail pkg' + , parseVer (BS8.unpack (BS.reverse vers))) _ -> Nothing parseVer :: String -> Version |