Created
March 17, 2018 17:51
-
-
Save DanBurton/31773dce004751706fdc7b74b29aa3c2 to your computer and use it in GitHub Desktop.
Parses stackage-curator output (on stderr, saved in "scheck.txt") and transforms this into package removals for build-constraints.yaml (printed to "removalizer.txt")
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
{- stack | |
script | |
--resolver lts-10.2 | |
-} | |
module Main where | |
import qualified Data.Char as Char | |
import Data.Semigroup ((<>)) | |
import Data.Text (Text) | |
import qualified Data.Text as Text | |
import qualified Data.Text.IO as TextIO | |
notStartNum :: Text -> Bool | |
notStartNum t = not $ Char.isNumber $ Text.head t | |
processChunk :: [Text] -> Text | |
processChunk (depLine:pkgsLines) = Text.unlines $ map toRemoval pkgsLines | |
where | |
toRemoval :: Text -> Text | |
toRemoval pkgLine = Text.pack " - " | |
<> pkgName pkgLine | |
<> Text.pack " < 0 # GHC 8.4 via " | |
<> dep | |
pkgName :: Text -> Text | |
pkgName pkgLine = Text.intercalate (Text.pack "-") | |
$ takeWhile notStartNum | |
$ Text.splitOn (Text.pack "-") (pkgAndVer pkgLine) | |
pkgAndVer :: Text -> Text | |
pkgAndVer pkgLine = Text.words pkgLine !! 3 | |
dep :: Text | |
dep = head (Text.words depLine) | |
processChunks :: [Text] -> Text | |
processChunks [] = Text.empty | |
processChunks (l:ls) | l == Text.empty = processChunks ls | |
processChunks ls = processChunk firstChunk <> processChunks restChunks | |
where (firstChunk, restChunks) = span (/= Text.empty) ls | |
process :: Text -> Text | |
process file = processChunks (drop 1 $ Text.lines file) | |
main :: IO () | |
main = do | |
file <- TextIO.readFile "scheck.txt" | |
TextIO.writeFile "removalizer.txt" (process file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment