From d98e54a74358658d78b062f298abdc6e3ad9ac6d Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 30 Aug 2021 23:04:28 +0200 Subject: [PATCH] Drop yaml/libyaml --- app/ghcup-gen/Main.hs | 6 +++--- app/ghcup/Main.hs | 9 +++------ cabal.ghc8107.project.freeze | 11 +++-------- cabal.ghc901.project.freeze | 11 +++-------- ghcup.cabal | 6 +++--- lib/GHCup/Download.hs | 13 ++++++------- lib/GHCup/Utils/Dirs.hs | 4 ++-- 7 files changed, 23 insertions(+), 37 deletions(-) diff --git a/app/ghcup-gen/Main.hs b/app/ghcup-gen/Main.hs index 11a2fe0..c676bd3 100644 --- a/app/ghcup-gen/Main.hs +++ b/app/ghcup-gen/Main.hs @@ -35,7 +35,7 @@ import Text.PrettyPrint.HughesPJClass ( prettyShow ) import qualified Data.Text.IO as T import qualified Data.Text as T import qualified Data.ByteString as B -import qualified Data.Yaml as Y +import qualified Data.YAML.Aeson as Y data Options = Options @@ -146,8 +146,8 @@ main = do ValidateYAMLOpts { vInput = Just (FileInput file) } -> B.readFile file >>= valAndExit f valAndExit f contents = do - (GHCupInfo _ av gt) <- case Y.decodeEither' contents of + (GHCupInfo _ av gt) <- case Y.decode1Strict contents of Right r -> pure r - Left e -> die (color Red $ show e) + Left (_, e) -> die (color Red $ show e) f av gt >>= exitWith diff --git a/app/ghcup/Main.hs b/app/ghcup/Main.hs index bf4470e..95efee3 100644 --- a/app/ghcup/Main.hs +++ b/app/ghcup/Main.hs @@ -77,8 +77,7 @@ import qualified Data.Map.Strict as M import qualified Data.Text as T import qualified Data.Text.IO as T import qualified Data.Text.Encoding as E -import qualified Data.Yaml as Y -import qualified Data.Yaml.Pretty as YP +import qualified Data.YAML.Aeson as Y import qualified Text.Megaparsec as MP import qualified Text.Megaparsec.Char as MPC @@ -1318,7 +1317,7 @@ toSettings options = do updateSettings :: Monad m => UTF8.ByteString -> Settings -> Excepts '[JSONError] m Settings updateSettings config settings = do - settings' <- lE' JSONDecodeError . first show . Y.decodeEither' $ config + settings' <- lE' JSONDecodeError . first snd . Y.decode1Strict $ config pure $ mergeConf settings' settings where mergeConf :: UserSettings -> Settings -> Settings @@ -1377,9 +1376,7 @@ plan_json = $( LitE . StringL <$> formatConfig :: UserSettings -> String formatConfig settings - = UTF8.toString . YP.encodePretty yamlConfig $ settings - where - yamlConfig = YP.setConfCompare compare YP.defConfig + = UTF8.toString . Y.encode1Strict $ settings main :: IO () main = do diff --git a/cabal.ghc8107.project.freeze b/cabal.ghc8107.project.freeze index eda9164..1eacbbf 100644 --- a/cabal.ghc8107.project.freeze +++ b/cabal.ghc8107.project.freeze @@ -3,6 +3,9 @@ constraints: any.Cabal ==3.2.1.0, any.HUnit ==1.6.2.0, any.HsOpenSSL ==0.11.7.1, HsOpenSSL -fast-bignum -homebrew-openssl -macports-openssl -use-pkg-config, + any.HsYAML ==0.2.1.0, + HsYAML -exe, + any.HsYAML-aeson ==0.2.0.0, any.QuickCheck ==2.14.2, QuickCheck -old-random +templatehaskell, any.StateVar ==1.2.2, @@ -55,7 +58,6 @@ constraints: any.Cabal ==3.2.1.0, any.composition-prelude ==3.0.0.2, composition-prelude -development, any.concurrent-output ==1.10.12, - any.conduit ==1.3.4.1, any.config-ini ==0.2.4.0, config-ini -enable-doctests, any.containers ==0.6.5.1, @@ -109,15 +111,12 @@ constraints: any.Cabal ==3.2.1.0, language-c -allwarnings +iecfpextension +usebytestrings, any.libarchive ==3.0.2.2, libarchive -cross -low-memory -system-libarchive, - any.libyaml ==0.1.2, - libyaml -no-unicode -system-libyaml, any.lzma-static ==5.2.5.4, any.megaparsec ==9.0.1, megaparsec -dev, any.microlens ==0.4.12.0, any.microlens-mtl ==0.2.0.1, any.microlens-th ==0.4.3.10, - any.mono-traversable ==1.0.15.1, any.mtl ==2.2.2, any.network ==3.1.2.2, network -devel, @@ -203,15 +202,11 @@ constraints: any.Cabal ==3.2.1.0, any.uuid-types ==1.0.5, any.vector ==0.12.3.0, vector +boundschecks -internalchecks -unsafechecks -wall, - any.vector-algorithms ==0.8.0.4, - vector-algorithms +bench +boundschecks -internalchecks -llvm +properties -unsafechecks, any.versions ==5.0.0, any.vty ==5.33, any.word-wrap ==0.4.1, any.word8 ==0.1.3, any.xor ==0.0.1.0, - any.yaml ==0.11.5.0, - yaml +no-examples +no-exe, any.zlib ==0.6.2.3, zlib -bundled-c-zlib -non-blocking-ffi -pkg-config, any.zlib-bindings ==0.1.1.5 diff --git a/cabal.ghc901.project.freeze b/cabal.ghc901.project.freeze index 7499c46..f5f9cbc 100644 --- a/cabal.ghc901.project.freeze +++ b/cabal.ghc901.project.freeze @@ -3,6 +3,9 @@ constraints: any.Cabal ==3.4.0.0, any.HUnit ==1.6.2.0, any.HsOpenSSL ==0.11.7.1, HsOpenSSL -fast-bignum -homebrew-openssl -macports-openssl -use-pkg-config, + any.HsYAML ==0.2.1.0, + HsYAML -exe, + any.HsYAML-aeson ==0.2.0.0, any.QuickCheck ==2.14.2, QuickCheck -old-random +templatehaskell, any.StateVar ==1.2.2, @@ -55,7 +58,6 @@ constraints: any.Cabal ==3.4.0.0, any.composition-prelude ==3.0.0.2, composition-prelude -development, any.concurrent-output ==1.10.12, - any.conduit ==1.3.4.1, any.config-ini ==0.2.4.0, config-ini -enable-doctests, any.containers ==0.6.4.1, @@ -109,15 +111,12 @@ constraints: any.Cabal ==3.4.0.0, language-c -allwarnings +iecfpextension +usebytestrings, any.libarchive ==3.0.2.2, libarchive -cross -low-memory -system-libarchive, - any.libyaml ==0.1.2, - libyaml -no-unicode -system-libyaml, any.lzma-static ==5.2.5.4, any.megaparsec ==9.0.1, megaparsec -dev, any.microlens ==0.4.12.0, any.microlens-mtl ==0.2.0.1, any.microlens-th ==0.4.3.10, - any.mono-traversable ==1.0.15.1, any.mtl ==2.2.2, any.network ==3.1.2.2, network -devel, @@ -203,15 +202,11 @@ constraints: any.Cabal ==3.4.0.0, any.uuid-types ==1.0.5, any.vector ==0.12.3.0, vector +boundschecks -internalchecks -unsafechecks -wall, - any.vector-algorithms ==0.8.0.4, - vector-algorithms +bench +boundschecks -internalchecks -llvm +properties -unsafechecks, any.versions ==5.0.0, any.vty ==5.33, any.word-wrap ==0.4.1, any.word8 ==0.1.3, any.xor ==0.0.1.0, - any.yaml ==0.11.5.0, - yaml +no-examples +no-exe, any.zlib ==0.6.2.3, zlib -bundled-c-zlib -non-blocking-ffi -pkg-config, any.zlib-bindings ==0.1.1.5 diff --git a/ghcup.cabal b/ghcup.cabal index ec28d51..0933614 100644 --- a/ghcup.cabal +++ b/ghcup.cabal @@ -132,7 +132,7 @@ library , vector ^>=0.12 , versions >=4.0.1 && <5.1 , word8 ^>=0.1.3 - , yaml ^>=0.11.4.0 + , HsYAML-aeson ^>=0.2.0.0 , zlib ^>=0.6.2.2 if (flag(internal-downloader) && !os(windows)) @@ -208,7 +208,7 @@ executable ghcup , uri-bytestring ^>=0.3.2.2 , utf8-string ^>=1.0 , versions >=4.0.1 && <5.1 - , yaml ^>=0.11.4.0 + , HsYAML-aeson ^>=0.2.0.0 if flag(internal-downloader) cpp-options: -DINTERNAL_DOWNLOADER @@ -268,7 +268,7 @@ executable ghcup-gen , text ^>=1.2.4.0 , transformers ^>=0.5 , versions >=4.0.1 && <5.1 - , yaml ^>=0.11.4.0 + , HsYAML-aeson ^>=0.2.0.0 test-suite ghcup-test type: exitcode-stdio-1.0 diff --git a/lib/GHCup/Download.hs b/lib/GHCup/Download.hs index e0b16f5..1bff833 100644 --- a/lib/GHCup/Download.hs +++ b/lib/GHCup/Download.hs @@ -86,7 +86,7 @@ import qualified Data.Map.Strict as M import qualified Data.Text as T import qualified Data.Text.IO as T import qualified Data.Text.Encoding as E -import qualified Data.Yaml as Y +import qualified Data.YAML.Aeson as Y @@ -183,16 +183,15 @@ getBase uri = do -- if we didn't get a filepath from the download, use the cached yaml actualYaml <- maybe (lift $ yamlFromCache uri) pure mYaml + yamlContents <- liftIO $ L.readFile actualYaml lift $ logDebug $ "Decoding yaml at: " <> T.pack actualYaml liftE . onE_ (onError actualYaml) - . lEM' @_ @_ @'[JSONError] JSONDecodeError - . fmap (first (\e -> unlines [displayException e - ,"Consider removing " <> actualYaml <> " manually."])) - . liftIO - . Y.decodeFileEither - $ actualYaml + . lE' @_ @_ @'[JSONError] JSONDecodeError + . first (\(_, e) -> unlines [e, "Consider removing " <> actualYaml <> " manually."]) + . Y.decode1 + $ yamlContents where -- On error, remove the etags file and set access time to 0. This should ensure the next invocation -- may re-download and succeed. diff --git a/lib/GHCup/Utils/Dirs.hs b/lib/GHCup/Utils/Dirs.hs index 45732a1..d5f04f1 100644 --- a/lib/GHCup/Utils/Dirs.hs +++ b/lib/GHCup/Utils/Dirs.hs @@ -58,7 +58,7 @@ import System.IO.Temp import qualified Data.ByteString as BS import qualified Data.Text as T -import qualified Data.Yaml as Y +import qualified Data.YAML.Aeson as Y import qualified Text.Megaparsec as MP import Control.Concurrent (threadDelay) @@ -221,7 +221,7 @@ ghcupConfigFile = do contents <- liftIO $ handleIO' NoSuchThing (\_ -> pure Nothing) $ Just <$> BS.readFile filepath case contents of Nothing -> pure defaultUserSettings - Just contents' -> lE' JSONDecodeError . first show . Y.decodeEither' $ contents' + Just contents' -> lE' JSONDecodeError . first snd . Y.decode1Strict $ contents' -------------------------