Skip to content

Commit 35185a7

Browse files
committed
pretty printing
1 parent cc4c2ff commit 35185a7

File tree

7 files changed

+98
-49
lines changed

7 files changed

+98
-49
lines changed

Cabal/src/Distribution/Backpack/ModuleShape.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import Distribution.Backpack.ModSubst
1919

2020
import qualified Data.Map as Map
2121
import qualified Data.Set as Set
22+
import Distribution.Pretty
23+
import qualified Text.PrettyPrint as Disp
2224

2325
-----------------------------------------------------------------------
2426
-- Module shapes
@@ -34,6 +36,12 @@ data ModuleShape = ModuleShape
3436

3537
instance Binary ModuleShape
3638
instance Structured ModuleShape
39+
instance Pretty ModuleShape where
40+
pretty (ModuleShape provs reqs) =
41+
Disp.hang (Disp.text "ModuleShape") 2 $ Disp.vcat
42+
[ Disp.hang (Disp.text "provides =") 2 $ dispOpenModuleSubst provs
43+
, Disp.hang (Disp.text "requires =") 2 $ Disp.hsep (map pretty (Set.toList reqs))
44+
]
3745

3846
instance ModSubst ModuleShape where
3947
modSubst subst (ModuleShape provs reqs) =

Cabal/src/Distribution/Simple/Compiler.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ import Language.Haskell.Extension
105105

106106
import qualified Data.Map as Map (lookup)
107107
import System.Directory (canonicalizePath)
108+
import Text.PrettyPrint (text)
108109

109110
data Compiler = Compiler
110111
{ compilerId :: CompilerId
@@ -199,6 +200,11 @@ data PackageDBX fp
199200
SpecificPackageDB fp
200201
deriving (Eq, Generic, Ord, Show, Read, Functor, Foldable, Traversable)
201202

203+
instance Pretty fp => Pretty (PackageDBX fp) where
204+
pretty GlobalPackageDB = text "GlobalPackageDB"
205+
pretty UserPackageDB = text "UserPackageDB"
206+
pretty (SpecificPackageDB db) = text "SpecificPackageDB" <+> pretty db
207+
202208
instance Binary fp => Binary (PackageDBX fp)
203209
instance Structured fp => Structured (PackageDBX fp)
204210

cabal-install/src/Distribution/Client/HashValue.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import qualified Data.ByteString.Char8 as BS
2222
import qualified Data.ByteString.Lazy.Char8 as LBS
2323

2424
import System.IO (IOMode (..), withBinaryFile)
25+
import qualified Text.PrettyPrint as Disp
2526

2627
-----------------------------------------------
2728
-- The specific choice of hash implementation
@@ -48,6 +49,9 @@ newtype HashValue = HashValue BS.ByteString
4849
instance Binary HashValue
4950
instance Structured HashValue
5051

52+
instance Pretty HashValue where
53+
pretty = Disp.text . showHashValue
54+
5155
-- | Hash some data. Currently uses SHA256.
5256
hashValue :: LBS.ByteString -> HashValue
5357
hashValue = HashValue . SHA256.hashlazy

cabal-install/src/Distribution/Client/ProjectPlanning/Types.hs

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -372,36 +372,36 @@ data ElaboratedConfiguredPackage = ElaboratedConfiguredPackage
372372
instance Pretty ElaboratedConfiguredPackage where
373373
pretty elab =
374374
hang (text "ElaboratedConfiguredPackage") 4 $ vcat $
375-
[ text "elabUnitId =" <+> pretty (elabUnitId elab)
376-
, text "elabComponentId =" <+> pretty (elabComponentId elab)
377-
, text "elabIsCanonical =" <+> text (show (elabIsCanonical elab))
378-
, text "elabPkgSourceId =" <+> pretty (elabPkgSourceId elab)
379-
, text "elabModuleShape =" <+> text (show (elabModuleShape elab))
380-
, text "elabFlagAssignment =" <+> Cabal.dispFlagAssignment (elabFlagAssignment elab)
381-
, text "elabFlagDefaults =" <+> Cabal.dispFlagAssignment (elabFlagDefaults elab)
382-
, text "elabPkgDescription =" <+> text "<PackageDescription>"
383-
, text "elabPkgSourceLocation =" <+> text (show (elabPkgSourceLocation elab))
384-
, text "elabPkgSourceHash =" <+> text (show (elabPkgSourceHash elab))
385-
, text "elabLocalToProject =" <+> text (show (elabLocalToProject elab))
386-
, text "elabBuildStyle =" <+> text (show (elabBuildStyle elab))
387-
, text "elabEnabledSpec =" <+> text (show (elabEnabledSpec elab))
375+
[ hang (text "elabUnitId =") 2 $ pretty (elabUnitId elab)
376+
, hang (text "elabComponentId =") 2 $ pretty (elabComponentId elab)
377+
, hang (text "elabIsCanonical =") 2 $ pretty (elabIsCanonical elab)
378+
, hang (text "elabPkgSourceId =") 2 $ pretty (elabPkgSourceId elab)
379+
, hang (text "elabModuleShape =") 2 $ pretty (elabModuleShape elab)
380+
, hang (text "elabFlagAssignment =") 2 $ Cabal.dispFlagAssignment (elabFlagAssignment elab)
381+
, hang (text "elabFlagDefaults =") 2 $ Cabal.dispFlagAssignment (elabFlagDefaults elab)
382+
, hang (text "elabPkgDescription =") 2 $ text "<PackageDescription>"
383+
, hang (text "elabPkgSourceLocation =") 2 $ pretty (maybe mempty text <$> elabPkgSourceLocation elab)
384+
, hang (text "elabPkgSourceHash =") 2 $ maybe mempty pretty (elabPkgSourceHash elab)
385+
, hang (text "elabLocalToProject =") 2 $ text (show (elabLocalToProject elab))
386+
, hang (text "elabBuildStyle =") 2 $ text $ show $ elabBuildStyle elab
387+
, hang (text "elabEnabledSpec =") 2 $ text $ show $ elabEnabledSpec elab
388388
-- , text "elabStanzasAvailable =" <+> text (show (elabStanzasAvailable elab))
389389
-- , text "elabStanzasRequested =" <+> text (show (elabStanzasRequested elab))
390-
, text "elabStage =" <+> text (show (elabStage elab))
391-
-- , text "elabPackageDbs =" <+> text (show (elabPackageDbs elab))
392-
-- , text "elabSetupPackageDBStack =" <+> text (show (elabSetupPackageDBStack elab))
393-
-- , text "elabBuildPackageDBStack =" <+> text (show (elabBuildPackageDBStack elab))
394-
-- , text "elabRegisterPackageDBStack =" <+> text (show (elabRegisterPackageDBStack elab))
390+
, hang (text "elabStage =") 2 $ pretty (elabStage elab)
391+
, hang (text "elabPackageDbs =") 2 $ sep $ map pretty $ fmap text <$> elabPackageDbs elab
392+
, hang (text "elabSetupPackageDBStack =") 2 $ text (show (elabSetupPackageDBStack elab))
393+
, hang (text "elabBuildPackageDBStack =") 2 $ text (show (elabBuildPackageDBStack elab))
394+
, hang (text "elabRegisterPackageDBStack =") 2 $ text (show (elabRegisterPackageDBStack elab))
395395
-- , text "elabInplaceSetupPackageDBStack =" <+> text (show (elabInplaceSetupPackageDBStack elab))
396396
-- , text "elabInplaceBuildPackageDBStack =" <+> text (show (elabInplaceBuildPackageDBStack elab))
397397
-- , text "elabInplaceRegisterPackageDBStack =" <+> text (show (elabInplaceRegisterPackageDBStack elab))
398-
, text "elabPkgDescriptionOverride =" <+> text (show (elabPkgDescriptionOverride elab))
399-
, text "elabBuildOptions =" <+> text "<BuildOptions>"
398+
, hang (text "elabPkgDescriptionOverride =") 2 $ text (show (elabPkgDescriptionOverride elab))
399+
, hang (text "elabBuildOptions =") 2 $ text "<BuildOptions>"
400400
-- , text "elabDumpBuildInfo =" <+> text (show (elabDumpBuildInfo elab))
401401
-- , text "elabProgramPaths =" <+> text (show (elabProgramPaths elab))
402402
-- , text "elabProgramArgs =" <+> text (show (elabProgramArgs elab))
403403
-- , text "elabProgramPathExtra =" <+> text (show (elabProgramPathExtra elab))
404-
, text "elabConfigureScriptArgs =" <+> text (show (elabConfigureScriptArgs elab))
404+
, hang (text "elabConfigureScriptArgs =") 2 $ text (show (elabConfigureScriptArgs elab))
405405
-- , text "elabExtraLibDirs =" <+> text (show (elabExtraLibDirs elab))
406406
-- , text "elabExtraLibDirsStatic =" <+> text (show (elabExtraLibDirsStatic elab))
407407
-- , text "elabExtraFrameworkDirs =" <+> text (show (elabExtraFrameworkDirs elab))
@@ -435,19 +435,19 @@ instance Pretty ElaboratedConfiguredPackage where
435435
-- , text "elabTestWrapper =" <+> text (show (elabTestWrapper elab))
436436
-- , text "elabTestFailWhenNoTestSuites =" <+> text (show (elabTestFailWhenNoTestSuites elab))
437437
-- , text "elabTestTestOptions =" <+> text (show (elabTestTestOptions elab))
438-
, text "elabBenchmarkOptions =" <+> text (show (elabBenchmarkOptions elab))
439-
, text "elabSetupScriptStyle =" <+> text (show (elabSetupScriptStyle elab))
440-
, text "elabSetupScriptCliVersion =" <+> pretty (elabSetupScriptCliVersion elab)
441-
, text "elabConfigureTargets =" <+> text (show (elabConfigureTargets elab))
442-
, text "elabBuildTargets =" <+> text (show (elabBuildTargets elab))
443-
, text "elabTestTargets =" <+> text (show (elabTestTargets elab))
444-
, text "elabBenchTargets =" <+> text (show (elabBenchTargets elab))
445-
, text "elabReplTarget =" <+> text (show (elabReplTarget elab))
446-
, text "elabHaddockTargets =" <+> text (show (elabHaddockTargets elab))
447-
, text "elabBuildHaddocks =" <+> text (show (elabBuildHaddocks elab))
448-
, text "elabPkgOrComp =" <+> pretty (elabPkgOrComp elab)
438+
, hang (text "elabBenchmarkOptions =") 2 $ text (show (elabBenchmarkOptions elab))
439+
, hang (text "elabSetupScriptStyle =") 2 $ text (show (elabSetupScriptStyle elab))
440+
, hang (text "elabSetupScriptCliVersion =") 2 $ pretty (elabSetupScriptCliVersion elab)
441+
, hang (text "elabConfigureTargets =") 2 $ text (show (elabConfigureTargets elab))
442+
, hang (text "elabBuildTargets =") 2 $ text (show (elabBuildTargets elab))
443+
, hang (text "elabTestTargets =") 2 $ text (show (elabTestTargets elab))
444+
, hang (text "elabBenchTargets =") 2 $ text (show (elabBenchTargets elab))
445+
, hang (text "elabReplTarget =") 2 $ text (show (elabReplTarget elab))
446+
, hang (text "elabHaddockTargets =") 2 $ text (show (elabHaddockTargets elab))
447+
, hang (text "elabBuildHaddocks =") 2 $ text (show (elabBuildHaddocks elab))
448+
, hang (text "elabPkgOrComp =") 2 $ pretty (elabPkgOrComp elab)
449449
]
450-
450+
451451
normaliseConfiguredPackage
452452
:: ElaboratedSharedConfig
453453
-> ElaboratedConfiguredPackage
@@ -847,8 +847,8 @@ instance Structured ElaboratedComponent
847847
instance Pretty ElaboratedComponent where
848848
pretty comp =
849849
hang (text "ElaboratedComponent") 4 $ vcat $
850-
[ text "compSolverName =" <+> text (show (compSolverName comp))
851-
, text "compComponentName =" <+> text (show (compComponentName comp))
850+
[ hang (text "compSolverName =") 2 $ text (show (compSolverName comp))
851+
, hang (text "compComponentName =") 2 $ text (show (compComponentName comp))
852852
, hang (text "compLibDependencies =") 4 $ sep
853853
[ pretty cid <+> if promised then text "promised" else mempty
854854
| (cid, promised) <- compLibDependencies comp
@@ -857,14 +857,14 @@ instance Pretty ElaboratedComponent where
857857
[ pretty ouid
858858
| ouid <- compLinkedLibDependencies comp
859859
]
860-
, text "compInstantiatedWith =" <+> text (show (compInstantiatedWith comp))
861-
, text "compLinkedInstantiatedWith =" <+> text (show (compLinkedInstantiatedWith comp))
860+
, hang (text "compInstantiatedWith =") 2 $ text (show (compInstantiatedWith comp))
861+
, hang (text "compLinkedInstantiatedWith =") 2 $ text (show (compLinkedInstantiatedWith comp))
862862
, hang (text "compExeDependencies =") 4 $ sep
863863
[ pretty cid
864864
| cid <- compExeDependencies comp
865865
]
866-
, text "compPkgConfigDependencies =" <+> text (show (compPkgConfigDependencies comp))
867-
, text "compExeDependencyPaths =" <+> text (show (compExeDependencyPaths comp))
866+
, hang (text "compPkgConfigDependencies =") 2 $ text (show (compPkgConfigDependencies comp))
867+
, hang (text "compExeDependencyPaths =") 2 $ text (show (compExeDependencyPaths comp))
868868
, hang (text "compOrderLibDependencies =") 4 $ sep $
869869
map pretty (compOrderLibDependencies comp)
870870
]
@@ -903,21 +903,21 @@ instance Structured ElaboratedPackage
903903
instance Pretty ElaboratedPackage where
904904
pretty pkg =
905905
hang (text "ElaboratedPackage") 4 $ vcat $
906-
[ text "pkgStage =" <+> pretty (pkgStage pkg)
907-
, text "pkgInstalledId =" <+> pretty (pkgInstalledId pkg)
908-
, text "pkgLibDependencies =" <+> pretty (fmap (vcat . map prettyPromised) (pkgLibDependencies pkg))
909-
, text "pkgDependsOnSelfLib =" <+> pretty (fmap (vcat . map (const (text "*"))) (pkgDependsOnSelfLib pkg))
910-
, text "pkgExeDependencies =" <+> pretty (fmap (vcat . map pretty) (pkgExeDependencies pkg))
911-
, text "pkgExeDependencyPaths =" <+> pretty (fmap (vcat . map prettyExePath) (pkgExeDependencyPaths pkg))
912-
, text "pkgPkgConfigDependencies =" <+> text (show (pkgPkgConfigDependencies pkg))
913-
, text "pkgStanzasEnabled =" <+> text (show (pkgStanzasEnabled pkg))
914-
, text "pkgWhyNotPerComponent =" <+> text (show (pkgWhyNotPerComponent pkg))
906+
[ hang (text "pkgStage =") 2 $ pretty (pkgStage pkg)
907+
, hang (text "pkgInstalledId =") 2 $ pretty (pkgInstalledId pkg)
908+
, hang (text "pkgLibDependencies =") 2 $ pretty (fmap (vcat . map prettyPromised) (pkgLibDependencies pkg))
909+
, hang (text "pkgDependsOnSelfLib =") 2 $ pretty (fmap (vcat . map (const (text "*"))) (pkgDependsOnSelfLib pkg))
910+
, hang (text "pkgExeDependencies =") 2 $ pretty (fmap (vcat . map pretty) (pkgExeDependencies pkg))
911+
, hang (text "pkgExeDependencyPaths =") 2 $ pretty (fmap (vcat . map prettyExePath) (pkgExeDependencyPaths pkg))
912+
, hang (text "pkgPkgConfigDependencies =") 2 $ text (show (pkgPkgConfigDependencies pkg))
913+
, hang (text "pkgStanzasEnabled =") 2 $ text (show (pkgStanzasEnabled pkg))
914+
, hang (text "pkgWhyNotPerComponent =") 2 $ text (show (pkgWhyNotPerComponent pkg))
915915
]
916916
where
917917
prettyPromised (l, p) =
918918
pretty l <+> if p then text "promised" else mempty
919919
prettyExePath (l, p) =
920-
pretty l <+> text "at" <+> text (show p)
920+
pretty l <+> hang (text "at") 2 (text (show p))
921921

922922
-- | Why did we fall-back to a per-package build, instead of using
923923
-- a per-component build?

cabal-install/src/Distribution/Client/Types/PackageLocation.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Distribution.Types.PackageId (PackageId)
1818
import Distribution.Client.Types.Repo
1919
import Distribution.Client.Types.SourceRepo (SourceRepoMaybe)
2020
import Distribution.Solver.Types.SourcePackage (SourcePackage)
21+
import Text.PrettyPrint (text)
2122

2223
type UnresolvedPkgLoc = PackageLocation (Maybe FilePath)
2324

@@ -39,6 +40,18 @@ data PackageLocation local
3940
RemoteSourceRepoPackage SourceRepoMaybe local
4041
deriving (Show, Functor, Eq, Ord, Generic)
4142

43+
instance Pretty local => Pretty (PackageLocation local) where
44+
pretty (LocalUnpackedPackage dir) =
45+
text "LocalUnpackedPackage" <+> text dir
46+
pretty (LocalTarballPackage file) =
47+
text "LocalTarballPackage" <+> text file
48+
pretty (RemoteTarballPackage uri loc) =
49+
text "RemoteTarballPackage" <+> text (show uri) <+> pretty loc
50+
pretty (RepoTarballPackage repo pkgId loc) =
51+
text "RepoTarballPackage" <+> pretty repo <+> pretty pkgId <+> pretty loc
52+
pretty (RemoteSourceRepoPackage repo loc) =
53+
text "RemoteSourceRepoPackage" <+> pretty repo <+> pretty loc
54+
4255
instance Binary local => Binary (PackageLocation local)
4356
instance Structured local => Structured (PackageLocation local)
4457

cabal-install/src/Distribution/Client/Types/Repo.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ data Repo
182182
instance Binary Repo
183183
instance Structured Repo
184184

185+
instance Pretty Repo where
186+
pretty (RepoLocalNoIndex r _) = pretty r
187+
pretty (RepoRemote r _) = pretty r
188+
pretty (RepoSecure r _) = pretty r
189+
185190
-- | Check if this is a remote repo
186191
isRepoRemote :: Repo -> Bool
187192
isRepoRemote RepoLocalNoIndex{} = False

cabal-install/src/Distribution/Client/Types/SourceRepo.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{-# LANGUAGE RankNTypes #-}
77
{-# LANGUAGE StandaloneDeriving #-}
88
{-# LANGUAGE UndecidableInstances #-}
9+
{-# LANGUAGE RecordWildCards #-}
910

1011
module Distribution.Client.Types.SourceRepo
1112
( SourceRepositoryPackage (..)
@@ -24,6 +25,7 @@ import Prelude ()
2425

2526
import Distribution.FieldGrammar
2627
import Distribution.Types.SourceRepo (RepoType (..))
28+
import qualified Text.PrettyPrint as Disp
2729

2830
-- | @source-repository-package@ definition
2931
data SourceRepositoryPackage f = SourceRepositoryPackage
@@ -42,6 +44,17 @@ deriving instance Show (f FilePath) => Show (SourceRepositoryPackage f)
4244
deriving instance Binary (f FilePath) => Binary (SourceRepositoryPackage f)
4345
deriving instance (Typeable f, Structured (f FilePath)) => Structured (SourceRepositoryPackage f)
4446

47+
instance (Foldable f) => Pretty (SourceRepositoryPackage f) where
48+
pretty SourceRepositoryPackage{..} =
49+
Disp.hang (Disp.text "SourceRepositoryPackage") 2 $ Disp.vcat
50+
[ Disp.hang (Disp.text "type =") 2 $ pretty srpType
51+
, Disp.hang (Disp.text "location =") 2 $ Disp.text srpLocation
52+
, Disp.hang (Disp.text "tag =") 2 $ maybe Disp.empty Disp.text srpTag
53+
, Disp.hang (Disp.text "branch =") 2 $ maybe Disp.empty Disp.text srpBranch
54+
, Disp.hang (Disp.text "subdir =") 2 $ Disp.vcat (map Disp.text (toList srpSubdir))
55+
, Disp.hang (Disp.text "post-checkout-command =") 2 $ Disp.vcat (map Disp.text srpCommand)
56+
]
57+
4558
-- | Read from @cabal.project@
4659
type SourceRepoList = SourceRepositoryPackage []
4760

0 commit comments

Comments
 (0)