From e9c335eeccb30b0f2fa4d8ce1ba2764bf9b7269b Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Fri, 27 Aug 2021 14:37:44 +0200 Subject: [PATCH] Add --cabal-plan --- app/ghcup/Main.hs | 18 +++++++++++++++++- cabal.project | 6 ++++++ ghcup.cabal | 3 +++ stack.yaml | 6 ++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/ghcup/Main.hs b/app/ghcup/Main.hs index ccba203..65be04e 100644 --- a/app/ghcup/Main.hs +++ b/app/ghcup/Main.hs @@ -30,6 +30,7 @@ import GHCup.Utils.Prelude import GHCup.Utils.String.QQ import GHCup.Version +import Cabal.Plan ( findPlanJson, SearchPlanJson(..) ) import Codec.Archive import Control.Concurrent import Control.Concurrent.Async @@ -42,6 +43,8 @@ import Control.Monad.Fail ( MonadFail ) import Control.Monad.Logger import Control.Monad.Reader import Control.Monad.Trans.Resource +import Data.Aeson ( decodeStrict', Value ) +import Data.Aeson.Encode.Pretty ( encodePretty ) import Data.Bifunctor import Data.Char import Data.Either @@ -1363,6 +1366,16 @@ describe_result = $( LitE . StringL <$> ) ) +plan_json :: String +plan_json = $( LitE . StringL <$> + runIO (handleIO (\_ -> pure "") $ do + fp <- findPlanJson (ProjectRelativeToDir ".") + c <- B.readFile fp + (Just res) <- pure $ decodeStrict' @Value c + pure $ T.unpack $ decUTF8Safe' $ encodePretty res + ) + ) + formatConfig :: UserSettings -> String formatConfig settings = UTF8.toString . YP.encodePretty yamlConfig $ settings @@ -1381,6 +1394,9 @@ main = do (head . lines $ describe_result) ) (long "version" <> help "Show version" <> hidden) + let planJson = infoOption + plan_json + (long "plan-json" <> help "Show the build-time configuration" <> internal) let numericVersionHelp = infoOption numericVer ( long "numeric-version" @@ -1408,7 +1424,7 @@ Report bugs at |] customExecParser (prefs showHelpOnError) - (info (opts <**> helper <**> versionHelp <**> numericVersionHelp <**> listCommands) + (info (opts <**> helper <**> versionHelp <**> numericVersionHelp <**> planJson <**> listCommands) (footerDoc (Just $ text main_footer)) ) >>= \opt@Options {..} -> do diff --git a/cabal.project b/cabal.project index da42548..bbc95b2 100644 --- a/cabal.project +++ b/cabal.project @@ -23,4 +23,10 @@ constraints: http-io-streams -brotli package libarchive flags: -system-libarchive +package aeson-pretty + flags: +lib-only + +package cabal-plan + flags: -exe + allow-newer: base, ghc-prim, template-haskell, language-c diff --git a/ghcup.cabal b/ghcup.cabal index 207aae3..4c1d676 100644 --- a/ghcup.cabal +++ b/ghcup.cabal @@ -186,9 +186,12 @@ executable ghcup -fwarn-incomplete-record-updates -threaded build-depends: + , aeson >=1.4 && <1.6 + , aeson-pretty ^>=0.8.8 , async ^>=2.2.3 , base >=4.13 && <5 , bytestring ^>=0.10 + , cabal-plan ^>=0.7.2 , containers ^>=0.6 , deepseq ^>=1.4 , filepath ^>=1.4.2.1 diff --git a/stack.yaml b/stack.yaml index 2b83e7e..fcef979 100644 --- a/stack.yaml +++ b/stack.yaml @@ -53,6 +53,12 @@ flags: regex-posix: _regex-posix-clib: true + aeson-pretty: + lib-only: true + + cabal-plan: + exe: false + ghc-options: "$locals": -O2 streamly: -O2 -fspec-constr-recursive=16 -fmax-worker-args=16