diff --git a/src/Pantry.hs b/src/Pantry.hs index 9218969d..7e98ed66 100644 --- a/src/Pantry.hs +++ b/src/Pantry.hs @@ -1,7 +1,9 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE LambdaCase #-} -- | Content addressable Haskell package management, providing for -- secure, reproducible acquisition of Haskell package contents and -- metadata. @@ -188,6 +190,9 @@ module Pantry import Database.Persist (entityKey) import RIO +#if !MIN_VERSION_rio(0,1,17) +import Data.Bifunctor (bimap) +#endif import Conduit import Control.Arrow (right) import Control.Monad.State.Strict (State, execState, get, modify') @@ -227,6 +232,16 @@ import Pantry.HTTP import Data.Char (isHexDigit) import Data.Time (getCurrentTime, diffUTCTime) +import Data.Yaml.Include (decodeFileWithWarnings) +import Hpack.Yaml (formatWarning) +import Hpack.Error (formatHpackError) + +decodeYaml :: FilePath -> IO (Either String ([String], Value)) +decodeYaml file = do + bimap displayException (first formatWarnings) <$> decodeFileWithWarnings file + where + formatWarnings = map (formatWarning file) + -- | Create a new 'PantryConfig' with the given settings. -- -- For something easier to use in simple cases, see 'runPantryApp'. @@ -741,15 +756,17 @@ hpack progName pkgDir = do he <- view $ pantryConfigL.to pcHpackExecutable case he of - HpackBundled -> do - r <- catchAny - ( liftIO - $ Hpack.hpackResult + HpackBundled -> + liftIO + ( Hpack.hpackResultWithError $ mHpackProgName + $ Hpack.setDecode decodeYaml $ Hpack.setTarget (toFilePath hpackFile) Hpack.defaultOptions - ) - ( throwIO . HpackLibraryException hpackFile ) + ) + >>= \ case + Left err -> throwIO (HpackLibraryException hpackFile $ formatHpackError (fromMaybe "hpack" progName) err) + Right r -> do forM_ (Hpack.resultWarnings r) (logWarn . fromString) let cabalFile = fromString . Hpack.resultCabalFile $ r case Hpack.resultStatus r of diff --git a/src/Pantry/Types.hs b/src/Pantry/Types.hs index 45fd914d..9a904d2e 100644 --- a/src/Pantry/Types.hs +++ b/src/Pantry/Types.hs @@ -970,7 +970,7 @@ data PantryException | MigrationFailure !Text !(Path Abs File) !SomeException | InvalidTreeFromCasa !BlobKey !ByteString | ParseSnapNameException !Text - | HpackLibraryException !(Path Abs File) !SomeException + | HpackLibraryException !(Path Abs File) !String | HpackExeException !FilePath !(Path Abs Dir) !SomeException deriving Typeable @@ -1279,13 +1279,13 @@ instance Display PantryException where "Error: [S-994]\n" <> "Invalid snapshot name: " <> display t - display (HpackLibraryException file e) = + display (HpackLibraryException file err) = "Error: [S-305]\n" <> "Failed to generate a Cabal file using the Hpack library on file:\n" <> fromString (toFilePath file) <> "\n\n" - <> "The exception encountered was:\n\n" - <> fromString (show e) + <> "The error encountered was:\n\n" + <> fromString err display (HpackExeException fp dir e) = "Error: [S-720]\n" <> "Failed to generate a Cabal file using the Hpack executable:\n" diff --git a/stack-cabal-3.4.yaml b/stack-cabal-3.4.yaml index da962f70..b1aa500d 100644 --- a/stack-cabal-3.4.yaml +++ b/stack-cabal-3.4.yaml @@ -4,6 +4,9 @@ resolver: lts-18.28 extra-deps: # lts-18.28 provides Cabal-3.2.1.0 - Cabal-3.4.0.0 +# Modified hpack +- git: https://github.com/sol/hpack + commit: beef09faa9fac949be56766a6de788d4cb948115 ghc-options: "$locals": -fhide-source-paths diff --git a/stack-cabal-3.4.yaml.lock b/stack-cabal-3.4.yaml.lock index c0524753..26274674 100644 --- a/stack-cabal-3.4.yaml.lock +++ b/stack-cabal-3.4.yaml.lock @@ -11,6 +11,17 @@ packages: size: 45845 original: hackage: Cabal-3.4.0.0 +- completed: + commit: beef09faa9fac949be56766a6de788d4cb948115 + git: https://github.com/sol/hpack + name: hpack + pantry-tree: + sha256: 77a0e107e2c263971811f9230835212b3ae6a45777148fa4c6c3a7f24ab482a4 + size: 4379 + version: 0.35.0 + original: + commit: beef09faa9fac949be56766a6de788d4cb948115 + git: https://github.com/sol/hpack snapshots: - completed: sha256: 428ec8d5ce932190d3cbe266b9eb3c175cd81e984babf876b64019e2cbe4ea68 diff --git a/stack-ghc-8.6.5.yaml b/stack-ghc-8.6.5.yaml index f34e9a67..d979dc66 100644 --- a/stack-ghc-8.6.5.yaml +++ b/stack-ghc-8.6.5.yaml @@ -3,7 +3,10 @@ resolver: lts-14.27 extra-deps: - Cabal-3.0.0.0 -- hpack-0.35.0 +# Modified hpack +- git: https://github.com/sol/hpack + commit: beef09faa9fac949be56766a6de788d4cb948115 +# - hpack-0.35.0 - casa-client-0.0.1 - casa-types-0.0.1 diff --git a/stack-ghc-8.6.5.yaml.lock b/stack-ghc-8.6.5.yaml.lock index 0d0a3ce3..56ed0338 100644 --- a/stack-ghc-8.6.5.yaml.lock +++ b/stack-ghc-8.6.5.yaml.lock @@ -12,12 +12,16 @@ packages: original: hackage: Cabal-3.0.0.0 - completed: - hackage: hpack-0.35.0@sha256:8cd6146fae269390f41dc7237ebd2c479074d4163806d349a41f5a7751d6cea5,4726 + commit: beef09faa9fac949be56766a6de788d4cb948115 + git: https://github.com/sol/hpack + name: hpack pantry-tree: - sha256: f143c1cb86d6ae954be5b3cc04629fb00631290c8eb9e3c795f65e10d6ccf220 - size: 3615 + sha256: 77a0e107e2c263971811f9230835212b3ae6a45777148fa4c6c3a7f24ab482a4 + size: 4379 + version: 0.35.0 original: - hackage: hpack-0.35.0 + commit: beef09faa9fac949be56766a6de788d4cb948115 + git: https://github.com/sol/hpack - completed: hackage: casa-client-0.0.1@sha256:7c254d0f21fa96c1e64fff027a479ba2e93b2d53bb1938b62dc63dc6018f12a1,892 pantry-tree: diff --git a/stack-ghc-8.8.4.yaml b/stack-ghc-8.8.4.yaml index 1162d189..246c05bb 100644 --- a/stack-ghc-8.8.4.yaml +++ b/stack-ghc-8.8.4.yaml @@ -3,7 +3,10 @@ resolver: lts-16.31 extra-deps: - Cabal-3.0.0.0 -- hpack-0.35.0 +# Modified hpack +- git: https://github.com/sol/hpack + commit: beef09faa9fac949be56766a6de788d4cb948115 +# - hpack-0.35.0 ghc-options: "$locals": -fhide-source-paths diff --git a/stack-ghc-8.8.4.yaml.lock b/stack-ghc-8.8.4.yaml.lock index e671be98..fcb8b0b8 100644 --- a/stack-ghc-8.8.4.yaml.lock +++ b/stack-ghc-8.8.4.yaml.lock @@ -12,12 +12,16 @@ packages: original: hackage: Cabal-3.0.0.0 - completed: - hackage: hpack-0.35.0@sha256:8cd6146fae269390f41dc7237ebd2c479074d4163806d349a41f5a7751d6cea5,4726 + commit: beef09faa9fac949be56766a6de788d4cb948115 + git: https://github.com/sol/hpack + name: hpack pantry-tree: - sha256: f143c1cb86d6ae954be5b3cc04629fb00631290c8eb9e3c795f65e10d6ccf220 - size: 3615 + sha256: 77a0e107e2c263971811f9230835212b3ae6a45777148fa4c6c3a7f24ab482a4 + size: 4379 + version: 0.35.0 original: - hackage: hpack-0.35.0 + commit: beef09faa9fac949be56766a6de788d4cb948115 + git: https://github.com/sol/hpack snapshots: - completed: sha256: 637fb77049b25560622a224845b7acfe81a09fdb6a96a3c75997a10b651667f6 diff --git a/stack-ghc-9.2.5.yaml b/stack-ghc-9.2.5.yaml index c0c14536..904dc5c4 100644 --- a/stack-ghc-9.2.5.yaml +++ b/stack-ghc-9.2.5.yaml @@ -1,5 +1,10 @@ # GHC 9.2.5 resolver: lts-20.0 +extra-deps: +# Modified hpack +- git: https://github.com/sol/hpack + commit: beef09faa9fac949be56766a6de788d4cb948115 + ghc-options: "$locals": -fhide-source-paths diff --git a/stack-ghc-9.2.5.yaml.lock b/stack-ghc-9.2.5.yaml.lock index c4546456..66cbbfd6 100644 --- a/stack-ghc-9.2.5.yaml.lock +++ b/stack-ghc-9.2.5.yaml.lock @@ -3,7 +3,18 @@ # For more information, please see the documentation at: # https://docs.haskellstack.org/en/stable/lock_files -packages: [] +packages: +- completed: + commit: beef09faa9fac949be56766a6de788d4cb948115 + git: https://github.com/sol/hpack + name: hpack + pantry-tree: + sha256: 77a0e107e2c263971811f9230835212b3ae6a45777148fa4c6c3a7f24ab482a4 + size: 4379 + version: 0.35.0 + original: + commit: beef09faa9fac949be56766a6de788d4cb948115 + git: https://github.com/sol/hpack snapshots: - completed: sha256: a2cbcd2f37010a64c4ef74c21fd7e55982a07b49840d2bed306f9bac9981a9c3 diff --git a/stack-ghc-9.4.2.yaml b/stack-ghc-9.4.2.yaml index ff7b018b..c9fc3b51 100644 --- a/stack-ghc-9.4.2.yaml +++ b/stack-ghc-9.4.2.yaml @@ -70,7 +70,10 @@ extra-deps: - haskell-lexer-1.1@sha256:9e0a7633f6bdb59004c6f3144ebfad1edb9e440fc6a94215c3a1d11bcd8656ef,915 - hedgehog-1.2@sha256:b7abfb2db7638c50eb8ee76186ee627ea7ab187220e4ea966b5738a1bde3b22a,4496 - hourglass-0.2.12@sha256:e083f5e030dfebe432e30a9c0fa07a99a54eac992f622442646be561fd7a44e8,3085 -- hpack-0.35.0@sha256:8cd6146fae269390f41dc7237ebd2c479074d4163806d349a41f5a7751d6cea5,4726 +# Modified hpack +- git: https://github.com/sol/hpack + commit: beef09faa9fac949be56766a6de788d4cb948115 +# - hpack-0.35.0@sha256:8cd6146fae269390f41dc7237ebd2c479074d4163806d349a41f5a7751d6cea5,4726 - hspec-2.10.1@sha256:a0fefe1a9e013de8a849120393a3ffcd734590ed9bc8875880d041e6968261be,1712 - hspec-core-2.10.1@sha256:7dd95622fd3423ef37268495eb5dfb59e21bfb21ad668a5aee82be36ccca2510,6617 - hspec-discover-2.10.1@sha256:c34af877176d1c6c8fc580fd100c5d6c3eb087899438777d18ff615fb9cb0f3c,2166 diff --git a/stack-ghc-9.4.2.yaml.lock b/stack-ghc-9.4.2.yaml.lock index ac1de330..b5a7d1ba 100644 --- a/stack-ghc-9.4.2.yaml.lock +++ b/stack-ghc-9.4.2.yaml.lock @@ -446,12 +446,16 @@ packages: original: hackage: hourglass-0.2.12@sha256:e083f5e030dfebe432e30a9c0fa07a99a54eac992f622442646be561fd7a44e8,3085 - completed: - hackage: hpack-0.35.0@sha256:8cd6146fae269390f41dc7237ebd2c479074d4163806d349a41f5a7751d6cea5,4726 + commit: beef09faa9fac949be56766a6de788d4cb948115 + git: https://github.com/sol/hpack + name: hpack pantry-tree: - sha256: f143c1cb86d6ae954be5b3cc04629fb00631290c8eb9e3c795f65e10d6ccf220 - size: 3615 + sha256: 77a0e107e2c263971811f9230835212b3ae6a45777148fa4c6c3a7f24ab482a4 + size: 4379 + version: 0.35.0 original: - hackage: hpack-0.35.0@sha256:8cd6146fae269390f41dc7237ebd2c479074d4163806d349a41f5a7751d6cea5,4726 + commit: beef09faa9fac949be56766a6de788d4cb948115 + git: https://github.com/sol/hpack - completed: hackage: hspec-2.10.1@sha256:a0fefe1a9e013de8a849120393a3ffcd734590ed9bc8875880d041e6968261be,1712 pantry-tree: diff --git a/stack-persistent-2.11.yaml b/stack-persistent-2.11.yaml index 4f91251f..c31ea190 100644 --- a/stack-persistent-2.11.yaml +++ b/stack-persistent-2.11.yaml @@ -2,6 +2,9 @@ resolver: lts-16.31 extra-deps: +# Modified hpack +- git: https://github.com/sol/hpack + commit: beef09faa9fac949be56766a6de788d4cb948115 - persistent-2.11.0.4@rev:0 - persistent-sqlite-2.11.1.0@rev:0 - persistent-template-2.9.1.0@rev:0 diff --git a/stack-persistent-2.11.yaml.lock b/stack-persistent-2.11.yaml.lock index b13d2f02..20b487c4 100644 --- a/stack-persistent-2.11.yaml.lock +++ b/stack-persistent-2.11.yaml.lock @@ -4,6 +4,17 @@ # https://docs.haskellstack.org/en/stable/lock_files packages: +- completed: + commit: beef09faa9fac949be56766a6de788d4cb948115 + git: https://github.com/sol/hpack + name: hpack + pantry-tree: + sha256: 77a0e107e2c263971811f9230835212b3ae6a45777148fa4c6c3a7f24ab482a4 + size: 4379 + version: 0.35.0 + original: + commit: beef09faa9fac949be56766a6de788d4cb948115 + git: https://github.com/sol/hpack - completed: hackage: persistent-2.11.0.4@sha256:a55a9a30d663407d77e2ea0e65b1e29e3aa2ecf531d7d758ded31c415875e216,4735 pantry-tree: diff --git a/stack.yaml b/stack.yaml index 8094e228..6b9bfa02 100644 --- a/stack.yaml +++ b/stack.yaml @@ -2,7 +2,9 @@ resolver: lts-18.28 extra-deps: -- hpack-0.35.0 +# Modified hpack +- git: https://github.com/sol/hpack + commit: beef09faa9fac949be56766a6de788d4cb948115 ghc-options: "$locals": -fhide-source-paths diff --git a/stack.yaml.lock b/stack.yaml.lock index 9b70b2d6..aa7b40d9 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -5,12 +5,16 @@ packages: - completed: - hackage: hpack-0.35.0@sha256:8cd6146fae269390f41dc7237ebd2c479074d4163806d349a41f5a7751d6cea5,4726 + commit: 1ecc4158bdfc03609c88d0b1908fa9f41fdfbf5c + git: https://github.com/sol/hpack + name: hpack pantry-tree: - sha256: f143c1cb86d6ae954be5b3cc04629fb00631290c8eb9e3c795f65e10d6ccf220 - size: 3615 + sha256: 48c9aaf36bb594e3893b4730e4862dd6d84da49713b7fa8985451df29582e1cf + size: 4378 + version: 0.35.0 original: - hackage: hpack-0.35.0 + commit: 1ecc4158bdfc03609c88d0b1908fa9f41fdfbf5c + git: https://github.com/sol/hpack snapshots: - completed: sha256: 428ec8d5ce932190d3cbe266b9eb3c175cd81e984babf876b64019e2cbe4ea68