{-# LANGUAGE OverloadedStrings #-}
module Distribution.PackageDescription.PrettyPrint (
writeGenericPackageDescription,
showGenericPackageDescription,
ppGenericPackageDescription,
writePackageDescription,
showPackageDescription,
writeHookedBuildInfo,
showHookedBuildInfo,
) where
import Distribution.Compat.Prelude
import Prelude ()
import Distribution.Types.CondTree
import Distribution.Types.Dependency
import Distribution.Types.ForeignLib (ForeignLib (foreignLibName))
import Distribution.Types.LibraryName
import Distribution.Types.UnqualComponentName
import Distribution.PackageDescription
import Distribution.Pretty
import Distribution.Fields.Pretty
import Distribution.Simple.Utils
import Distribution.FieldGrammar (PrettyFieldGrammar', prettyFieldGrammar)
import Distribution.PackageDescription.FieldGrammar
(benchmarkFieldGrammar, buildInfoFieldGrammar, executableFieldGrammar, flagFieldGrammar,
foreignLibFieldGrammar, libraryFieldGrammar, packageDescriptionFieldGrammar,
setupBInfoFieldGrammar, sourceRepoFieldGrammar, testSuiteFieldGrammar)
import qualified Distribution.PackageDescription.FieldGrammar as FG
import Text.PrettyPrint (Doc, char, hsep, parens, text, (<+>))
import qualified Data.ByteString.Lazy.Char8 as BS.Char8
writeGenericPackageDescription :: FilePath -> GenericPackageDescription -> NoCallStackIO ()
writeGenericPackageDescription :: FilePath -> GenericPackageDescription -> NoCallStackIO ()
writeGenericPackageDescription fpath :: FilePath
fpath pkg :: GenericPackageDescription
pkg = FilePath -> FilePath -> NoCallStackIO ()
writeUTF8File FilePath
fpath (GenericPackageDescription -> FilePath
showGenericPackageDescription GenericPackageDescription
pkg)
showGenericPackageDescription :: GenericPackageDescription -> String
showGenericPackageDescription :: GenericPackageDescription -> FilePath
showGenericPackageDescription = [PrettyField] -> FilePath
showFields ([PrettyField] -> FilePath)
-> (GenericPackageDescription -> [PrettyField])
-> GenericPackageDescription
-> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenericPackageDescription -> [PrettyField]
ppGenericPackageDescription
ppGenericPackageDescription :: GenericPackageDescription -> [PrettyField]
ppGenericPackageDescription :: GenericPackageDescription -> [PrettyField]
ppGenericPackageDescription gpd :: GenericPackageDescription
gpd = [[PrettyField]] -> [PrettyField]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ PackageDescription -> [PrettyField]
ppPackageDescription (GenericPackageDescription -> PackageDescription
packageDescription GenericPackageDescription
gpd)
, Maybe SetupBuildInfo -> [PrettyField]
ppSetupBInfo (PackageDescription -> Maybe SetupBuildInfo
setupBuildInfo (GenericPackageDescription -> PackageDescription
packageDescription GenericPackageDescription
gpd))
, [Flag] -> [PrettyField]
ppGenPackageFlags (GenericPackageDescription -> [Flag]
genPackageFlags GenericPackageDescription
gpd)
, Maybe (CondTree ConfVar [Dependency] Library) -> [PrettyField]
ppCondLibrary (GenericPackageDescription
-> Maybe (CondTree ConfVar [Dependency] Library)
condLibrary GenericPackageDescription
gpd)
, [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
-> [PrettyField]
ppCondSubLibraries (GenericPackageDescription
-> [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
condSubLibraries GenericPackageDescription
gpd)
, [(UnqualComponentName, CondTree ConfVar [Dependency] ForeignLib)]
-> [PrettyField]
ppCondForeignLibs (GenericPackageDescription
-> [(UnqualComponentName,
CondTree ConfVar [Dependency] ForeignLib)]
condForeignLibs GenericPackageDescription
gpd)
, [(UnqualComponentName, CondTree ConfVar [Dependency] Executable)]
-> [PrettyField]
ppCondExecutables (GenericPackageDescription
-> [(UnqualComponentName,
CondTree ConfVar [Dependency] Executable)]
condExecutables GenericPackageDescription
gpd)
, [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
-> [PrettyField]
ppCondTestSuites (GenericPackageDescription
-> [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
condTestSuites GenericPackageDescription
gpd)
, [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
-> [PrettyField]
ppCondBenchmarks (GenericPackageDescription
-> [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
condBenchmarks GenericPackageDescription
gpd)
]
ppPackageDescription :: PackageDescription -> [PrettyField]
ppPackageDescription :: PackageDescription -> [PrettyField]
ppPackageDescription pd :: PackageDescription
pd =
PrettyFieldGrammar PackageDescription PackageDescription
-> PackageDescription -> [PrettyField]
forall s a. PrettyFieldGrammar s a -> s -> [PrettyField]
prettyFieldGrammar PrettyFieldGrammar PackageDescription PackageDescription
forall (g :: * -> * -> *).
(FieldGrammar g, Applicative (g PackageDescription),
Applicative (g PackageIdentifier)) =>
g PackageDescription PackageDescription
packageDescriptionFieldGrammar PackageDescription
pd
[PrettyField] -> [PrettyField] -> [PrettyField]
forall a. [a] -> [a] -> [a]
++ [SourceRepo] -> [PrettyField]
ppSourceRepos (PackageDescription -> [SourceRepo]
sourceRepos PackageDescription
pd)
ppSourceRepos :: [SourceRepo] -> [PrettyField]
ppSourceRepos :: [SourceRepo] -> [PrettyField]
ppSourceRepos = (SourceRepo -> PrettyField) -> [SourceRepo] -> [PrettyField]
forall a b. (a -> b) -> [a] -> [b]
map SourceRepo -> PrettyField
ppSourceRepo
ppSourceRepo :: SourceRepo -> PrettyField
ppSourceRepo :: SourceRepo -> PrettyField
ppSourceRepo repo :: SourceRepo
repo = FieldName -> [Doc] -> [PrettyField] -> PrettyField
PrettySection "source-repository" [RepoKind -> Doc
forall a. Pretty a => a -> Doc
pretty RepoKind
kind] ([PrettyField] -> PrettyField) -> [PrettyField] -> PrettyField
forall a b. (a -> b) -> a -> b
$
PrettyFieldGrammar SourceRepo SourceRepo
-> SourceRepo -> [PrettyField]
forall s a. PrettyFieldGrammar s a -> s -> [PrettyField]
prettyFieldGrammar (RepoKind -> PrettyFieldGrammar SourceRepo SourceRepo
forall (g :: * -> * -> *).
(FieldGrammar g, Applicative (g SourceRepo)) =>
RepoKind -> g SourceRepo SourceRepo
sourceRepoFieldGrammar RepoKind
kind) SourceRepo
repo
where
kind :: RepoKind
kind = SourceRepo -> RepoKind
repoKind SourceRepo
repo
ppSetupBInfo :: Maybe SetupBuildInfo -> [PrettyField]
ppSetupBInfo :: Maybe SetupBuildInfo -> [PrettyField]
ppSetupBInfo Nothing = [PrettyField]
forall a. Monoid a => a
mempty
ppSetupBInfo (Just sbi :: SetupBuildInfo
sbi)
| SetupBuildInfo -> Bool
defaultSetupDepends SetupBuildInfo
sbi = [PrettyField]
forall a. Monoid a => a
mempty
| Bool
otherwise = PrettyField -> [PrettyField]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PrettyField -> [PrettyField]) -> PrettyField -> [PrettyField]
forall a b. (a -> b) -> a -> b
$ FieldName -> [Doc] -> [PrettyField] -> PrettyField
PrettySection "custom-setup" [] ([PrettyField] -> PrettyField) -> [PrettyField] -> PrettyField
forall a b. (a -> b) -> a -> b
$
PrettyFieldGrammar SetupBuildInfo SetupBuildInfo
-> SetupBuildInfo -> [PrettyField]
forall s a. PrettyFieldGrammar s a -> s -> [PrettyField]
prettyFieldGrammar (Bool -> PrettyFieldGrammar SetupBuildInfo SetupBuildInfo
forall (g :: * -> * -> *).
(FieldGrammar g, Functor (g SetupBuildInfo)) =>
Bool -> g SetupBuildInfo SetupBuildInfo
setupBInfoFieldGrammar Bool
False) SetupBuildInfo
sbi
ppGenPackageFlags :: [Flag] -> [PrettyField]
ppGenPackageFlags :: [Flag] -> [PrettyField]
ppGenPackageFlags = (Flag -> PrettyField) -> [Flag] -> [PrettyField]
forall a b. (a -> b) -> [a] -> [b]
map Flag -> PrettyField
ppFlag
ppFlag :: Flag -> PrettyField
ppFlag :: Flag -> PrettyField
ppFlag flag :: Flag
flag@(MkFlag name :: FlagName
name _ _ _) = FieldName -> [Doc] -> [PrettyField] -> PrettyField
PrettySection "flag" [FlagName -> Doc
ppFlagName FlagName
name] ([PrettyField] -> PrettyField) -> [PrettyField] -> PrettyField
forall a b. (a -> b) -> a -> b
$
PrettyFieldGrammar Flag Flag -> Flag -> [PrettyField]
forall s a. PrettyFieldGrammar s a -> s -> [PrettyField]
prettyFieldGrammar (FlagName -> PrettyFieldGrammar Flag Flag
forall (g :: * -> * -> *).
(FieldGrammar g, Applicative (g Flag)) =>
FlagName -> g Flag Flag
flagFieldGrammar FlagName
name) Flag
flag
ppCondTree2 :: PrettyFieldGrammar' s -> CondTree ConfVar [Dependency] s -> [PrettyField]
ppCondTree2 :: PrettyFieldGrammar' s
-> CondTree ConfVar [Dependency] s -> [PrettyField]
ppCondTree2 grammar :: PrettyFieldGrammar' s
grammar = CondTree ConfVar [Dependency] s -> [PrettyField]
forall c. CondTree ConfVar c s -> [PrettyField]
go
where
go :: CondTree ConfVar c s -> [PrettyField]
go (CondNode it :: s
it _ ifs :: [CondBranch ConfVar c s]
ifs) =
PrettyFieldGrammar' s -> s -> [PrettyField]
forall s a. PrettyFieldGrammar s a -> s -> [PrettyField]
prettyFieldGrammar PrettyFieldGrammar' s
grammar s
it [PrettyField] -> [PrettyField] -> [PrettyField]
forall a. [a] -> [a] -> [a]
++
(CondBranch ConfVar c s -> [PrettyField])
-> [CondBranch ConfVar c s] -> [PrettyField]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap CondBranch ConfVar c s -> [PrettyField]
ppIf [CondBranch ConfVar c s]
ifs
ppIf :: CondBranch ConfVar c s -> [PrettyField]
ppIf (CondBranch c :: Condition ConfVar
c thenTree :: CondTree ConfVar c s
thenTree Nothing)
| Bool
otherwise = [Condition ConfVar -> [PrettyField] -> PrettyField
ppIfCondition Condition ConfVar
c [PrettyField]
thenDoc]
where
thenDoc :: [PrettyField]
thenDoc = CondTree ConfVar c s -> [PrettyField]
go CondTree ConfVar c s
thenTree
ppIf (CondBranch c :: Condition ConfVar
c thenTree :: CondTree ConfVar c s
thenTree (Just elseTree :: CondTree ConfVar c s
elseTree)) =
case (Bool
False, Bool
False) of
(True, True) -> [PrettyField]
forall a. Monoid a => a
mempty
(False, True) -> [ Condition ConfVar -> [PrettyField] -> PrettyField
ppIfCondition Condition ConfVar
c [PrettyField]
thenDoc ]
(True, False) -> [ Condition ConfVar -> [PrettyField] -> PrettyField
ppIfCondition (Condition ConfVar -> Condition ConfVar
forall a. Condition a -> Condition a
cNot Condition ConfVar
c) [PrettyField]
elseDoc ]
(False, False) -> [ Condition ConfVar -> [PrettyField] -> PrettyField
ppIfCondition Condition ConfVar
c [PrettyField]
thenDoc
, FieldName -> [Doc] -> [PrettyField] -> PrettyField
PrettySection "else" [] [PrettyField]
elseDoc
]
where
thenDoc :: [PrettyField]
thenDoc = CondTree ConfVar c s -> [PrettyField]
go CondTree ConfVar c s
thenTree
elseDoc :: [PrettyField]
elseDoc = CondTree ConfVar c s -> [PrettyField]
go CondTree ConfVar c s
elseTree
ppCondLibrary :: Maybe (CondTree ConfVar [Dependency] Library) -> [PrettyField]
ppCondLibrary :: Maybe (CondTree ConfVar [Dependency] Library) -> [PrettyField]
ppCondLibrary Nothing = [PrettyField]
forall a. Monoid a => a
mempty
ppCondLibrary (Just condTree :: CondTree ConfVar [Dependency] Library
condTree) = PrettyField -> [PrettyField]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PrettyField -> [PrettyField]) -> PrettyField -> [PrettyField]
forall a b. (a -> b) -> a -> b
$ FieldName -> [Doc] -> [PrettyField] -> PrettyField
PrettySection "library" [] ([PrettyField] -> PrettyField) -> [PrettyField] -> PrettyField
forall a b. (a -> b) -> a -> b
$
PrettyFieldGrammar' Library
-> CondTree ConfVar [Dependency] Library -> [PrettyField]
forall s.
PrettyFieldGrammar' s
-> CondTree ConfVar [Dependency] s -> [PrettyField]
ppCondTree2 (LibraryName -> PrettyFieldGrammar' Library
forall (g :: * -> * -> *).
(FieldGrammar g, Applicative (g Library),
Applicative (g BuildInfo)) =>
LibraryName -> g Library Library
libraryFieldGrammar LibraryName
LMainLibName) CondTree ConfVar [Dependency] Library
condTree
ppCondSubLibraries :: [(UnqualComponentName, CondTree ConfVar [Dependency] Library)] -> [PrettyField]
ppCondSubLibraries :: [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
-> [PrettyField]
ppCondSubLibraries libs :: [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
libs =
[ FieldName -> [Doc] -> [PrettyField] -> PrettyField
PrettySection "library" [UnqualComponentName -> Doc
forall a. Pretty a => a -> Doc
pretty UnqualComponentName
n]
([PrettyField] -> PrettyField) -> [PrettyField] -> PrettyField
forall a b. (a -> b) -> a -> b
$ PrettyFieldGrammar' Library
-> CondTree ConfVar [Dependency] Library -> [PrettyField]
forall s.
PrettyFieldGrammar' s
-> CondTree ConfVar [Dependency] s -> [PrettyField]
ppCondTree2 (LibraryName -> PrettyFieldGrammar' Library
forall (g :: * -> * -> *).
(FieldGrammar g, Applicative (g Library),
Applicative (g BuildInfo)) =>
LibraryName -> g Library Library
libraryFieldGrammar (LibraryName -> PrettyFieldGrammar' Library)
-> LibraryName -> PrettyFieldGrammar' Library
forall a b. (a -> b) -> a -> b
$ UnqualComponentName -> LibraryName
LSubLibName UnqualComponentName
n) CondTree ConfVar [Dependency] Library
condTree
| (n :: UnqualComponentName
n, condTree :: CondTree ConfVar [Dependency] Library
condTree) <- [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
libs
]
ppCondForeignLibs :: [(UnqualComponentName, CondTree ConfVar [Dependency] ForeignLib)] -> [PrettyField]
ppCondForeignLibs :: [(UnqualComponentName, CondTree ConfVar [Dependency] ForeignLib)]
-> [PrettyField]
ppCondForeignLibs flibs :: [(UnqualComponentName, CondTree ConfVar [Dependency] ForeignLib)]
flibs =
[ FieldName -> [Doc] -> [PrettyField] -> PrettyField
PrettySection "foreign-library" [UnqualComponentName -> Doc
forall a. Pretty a => a -> Doc
pretty UnqualComponentName
n]
([PrettyField] -> PrettyField) -> [PrettyField] -> PrettyField
forall a b. (a -> b) -> a -> b
$ PrettyFieldGrammar' ForeignLib
-> CondTree ConfVar [Dependency] ForeignLib -> [PrettyField]
forall s.
PrettyFieldGrammar' s
-> CondTree ConfVar [Dependency] s -> [PrettyField]
ppCondTree2 (UnqualComponentName -> PrettyFieldGrammar' ForeignLib
forall (g :: * -> * -> *).
(FieldGrammar g, Applicative (g ForeignLib),
Applicative (g BuildInfo)) =>
UnqualComponentName -> g ForeignLib ForeignLib
foreignLibFieldGrammar UnqualComponentName
n) CondTree ConfVar [Dependency] ForeignLib
condTree
| (n :: UnqualComponentName
n, condTree :: CondTree ConfVar [Dependency] ForeignLib
condTree) <- [(UnqualComponentName, CondTree ConfVar [Dependency] ForeignLib)]
flibs
]
ppCondExecutables :: [(UnqualComponentName, CondTree ConfVar [Dependency] Executable)] -> [PrettyField]
ppCondExecutables :: [(UnqualComponentName, CondTree ConfVar [Dependency] Executable)]
-> [PrettyField]
ppCondExecutables exes :: [(UnqualComponentName, CondTree ConfVar [Dependency] Executable)]
exes =
[ FieldName -> [Doc] -> [PrettyField] -> PrettyField
PrettySection "executable" [UnqualComponentName -> Doc
forall a. Pretty a => a -> Doc
pretty UnqualComponentName
n]
([PrettyField] -> PrettyField) -> [PrettyField] -> PrettyField
forall a b. (a -> b) -> a -> b
$ PrettyFieldGrammar' Executable
-> CondTree ConfVar [Dependency] Executable -> [PrettyField]
forall s.
PrettyFieldGrammar' s
-> CondTree ConfVar [Dependency] s -> [PrettyField]
ppCondTree2 (UnqualComponentName -> PrettyFieldGrammar' Executable
forall (g :: * -> * -> *).
(FieldGrammar g, Applicative (g Executable),
Applicative (g BuildInfo)) =>
UnqualComponentName -> g Executable Executable
executableFieldGrammar UnqualComponentName
n) CondTree ConfVar [Dependency] Executable
condTree
| (n :: UnqualComponentName
n, condTree :: CondTree ConfVar [Dependency] Executable
condTree) <- [(UnqualComponentName, CondTree ConfVar [Dependency] Executable)]
exes
]
ppCondTestSuites :: [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)] -> [PrettyField]
ppCondTestSuites :: [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
-> [PrettyField]
ppCondTestSuites suites :: [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
suites =
[ FieldName -> [Doc] -> [PrettyField] -> PrettyField
PrettySection "test-suite" [UnqualComponentName -> Doc
forall a. Pretty a => a -> Doc
pretty UnqualComponentName
n]
([PrettyField] -> PrettyField) -> [PrettyField] -> PrettyField
forall a b. (a -> b) -> a -> b
$ PrettyFieldGrammar' TestSuiteStanza
-> CondTree ConfVar [Dependency] TestSuiteStanza -> [PrettyField]
forall s.
PrettyFieldGrammar' s
-> CondTree ConfVar [Dependency] s -> [PrettyField]
ppCondTree2 PrettyFieldGrammar' TestSuiteStanza
forall (g :: * -> * -> *).
(FieldGrammar g, Applicative (g TestSuiteStanza),
Applicative (g BuildInfo)) =>
g TestSuiteStanza TestSuiteStanza
testSuiteFieldGrammar ((TestSuite -> TestSuiteStanza)
-> CondTree ConfVar [Dependency] TestSuite
-> CondTree ConfVar [Dependency] TestSuiteStanza
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TestSuite -> TestSuiteStanza
FG.unvalidateTestSuite CondTree ConfVar [Dependency] TestSuite
condTree)
| (n :: UnqualComponentName
n, condTree :: CondTree ConfVar [Dependency] TestSuite
condTree) <- [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
suites
]
ppCondBenchmarks :: [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)] -> [PrettyField]
ppCondBenchmarks :: [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
-> [PrettyField]
ppCondBenchmarks suites :: [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
suites =
[ FieldName -> [Doc] -> [PrettyField] -> PrettyField
PrettySection "benchmark" [UnqualComponentName -> Doc
forall a. Pretty a => a -> Doc
pretty UnqualComponentName
n]
([PrettyField] -> PrettyField) -> [PrettyField] -> PrettyField
forall a b. (a -> b) -> a -> b
$ PrettyFieldGrammar' BenchmarkStanza
-> CondTree ConfVar [Dependency] BenchmarkStanza -> [PrettyField]
forall s.
PrettyFieldGrammar' s
-> CondTree ConfVar [Dependency] s -> [PrettyField]
ppCondTree2 PrettyFieldGrammar' BenchmarkStanza
forall (g :: * -> * -> *).
(FieldGrammar g, Applicative (g BenchmarkStanza),
Applicative (g BuildInfo)) =>
g BenchmarkStanza BenchmarkStanza
benchmarkFieldGrammar ((Benchmark -> BenchmarkStanza)
-> CondTree ConfVar [Dependency] Benchmark
-> CondTree ConfVar [Dependency] BenchmarkStanza
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Benchmark -> BenchmarkStanza
FG.unvalidateBenchmark CondTree ConfVar [Dependency] Benchmark
condTree)
| (n :: UnqualComponentName
n, condTree :: CondTree ConfVar [Dependency] Benchmark
condTree) <- [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
suites
]
ppCondition :: Condition ConfVar -> Doc
ppCondition :: Condition ConfVar -> Doc
ppCondition (Var x :: ConfVar
x) = ConfVar -> Doc
ppConfVar ConfVar
x
ppCondition (Lit b :: Bool
b) = FilePath -> Doc
text (Bool -> FilePath
forall a. Show a => a -> FilePath
show Bool
b)
ppCondition (CNot c :: Condition ConfVar
c) = Char -> Doc
char '!' Doc -> Doc -> Doc
<<>> (Condition ConfVar -> Doc
ppCondition Condition ConfVar
c)
ppCondition (COr c1 :: Condition ConfVar
c1 c2 :: Condition ConfVar
c2) = Doc -> Doc
parens ([Doc] -> Doc
hsep [Condition ConfVar -> Doc
ppCondition Condition ConfVar
c1, FilePath -> Doc
text "||"
Doc -> Doc -> Doc
<+> Condition ConfVar -> Doc
ppCondition Condition ConfVar
c2])
ppCondition (CAnd c1 :: Condition ConfVar
c1 c2 :: Condition ConfVar
c2) = Doc -> Doc
parens ([Doc] -> Doc
hsep [Condition ConfVar -> Doc
ppCondition Condition ConfVar
c1, FilePath -> Doc
text "&&"
Doc -> Doc -> Doc
<+> Condition ConfVar -> Doc
ppCondition Condition ConfVar
c2])
ppConfVar :: ConfVar -> Doc
ppConfVar :: ConfVar -> Doc
ppConfVar (OS os :: OS
os) = FilePath -> Doc
text "os" Doc -> Doc -> Doc
<<>> Doc -> Doc
parens (OS -> Doc
forall a. Pretty a => a -> Doc
pretty OS
os)
ppConfVar (Arch arch :: Arch
arch) = FilePath -> Doc
text "arch" Doc -> Doc -> Doc
<<>> Doc -> Doc
parens (Arch -> Doc
forall a. Pretty a => a -> Doc
pretty Arch
arch)
ppConfVar (Flag name :: FlagName
name) = FilePath -> Doc
text "flag" Doc -> Doc -> Doc
<<>> Doc -> Doc
parens (FlagName -> Doc
ppFlagName FlagName
name)
ppConfVar (Impl c :: CompilerFlavor
c v :: VersionRange
v) = FilePath -> Doc
text "impl" Doc -> Doc -> Doc
<<>> Doc -> Doc
parens (CompilerFlavor -> Doc
forall a. Pretty a => a -> Doc
pretty CompilerFlavor
c Doc -> Doc -> Doc
<+> VersionRange -> Doc
forall a. Pretty a => a -> Doc
pretty VersionRange
v)
ppFlagName :: FlagName -> Doc
ppFlagName :: FlagName -> Doc
ppFlagName = FilePath -> Doc
text (FilePath -> Doc) -> (FlagName -> FilePath) -> FlagName -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlagName -> FilePath
unFlagName
ppIfCondition :: (Condition ConfVar) -> [PrettyField] -> PrettyField
ppIfCondition :: Condition ConfVar -> [PrettyField] -> PrettyField
ppIfCondition c :: Condition ConfVar
c = FieldName -> [Doc] -> [PrettyField] -> PrettyField
PrettySection "if" [Condition ConfVar -> Doc
ppCondition Condition ConfVar
c]
writePackageDescription :: FilePath -> PackageDescription -> NoCallStackIO ()
writePackageDescription :: FilePath -> PackageDescription -> NoCallStackIO ()
writePackageDescription fpath :: FilePath
fpath pkg :: PackageDescription
pkg = FilePath -> FilePath -> NoCallStackIO ()
writeUTF8File FilePath
fpath (PackageDescription -> FilePath
showPackageDescription PackageDescription
pkg)
showPackageDescription :: PackageDescription -> String
showPackageDescription :: PackageDescription -> FilePath
showPackageDescription = GenericPackageDescription -> FilePath
showGenericPackageDescription (GenericPackageDescription -> FilePath)
-> (PackageDescription -> GenericPackageDescription)
-> PackageDescription
-> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageDescription -> GenericPackageDescription
pdToGpd
pdToGpd :: PackageDescription -> GenericPackageDescription
pdToGpd :: PackageDescription -> GenericPackageDescription
pdToGpd pd :: PackageDescription
pd = GenericPackageDescription :: PackageDescription
-> [Flag]
-> Maybe (CondTree ConfVar [Dependency] Library)
-> [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
-> [(UnqualComponentName,
CondTree ConfVar [Dependency] ForeignLib)]
-> [(UnqualComponentName,
CondTree ConfVar [Dependency] Executable)]
-> [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
-> [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
-> GenericPackageDescription
GenericPackageDescription
{ packageDescription :: PackageDescription
packageDescription = PackageDescription
pd
, genPackageFlags :: [Flag]
genPackageFlags = []
, condLibrary :: Maybe (CondTree ConfVar [Dependency] Library)
condLibrary = Library -> CondTree ConfVar [Dependency] Library
forall a v a. a -> CondTree v [a] a
mkCondTree (Library -> CondTree ConfVar [Dependency] Library)
-> Maybe Library -> Maybe (CondTree ConfVar [Dependency] Library)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PackageDescription -> Maybe Library
library PackageDescription
pd
, condSubLibraries :: [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
condSubLibraries = Library
-> (UnqualComponentName, CondTree ConfVar [Dependency] Library)
forall v a.
Library -> (UnqualComponentName, CondTree v [a] Library)
mkCondTreeL (Library
-> (UnqualComponentName, CondTree ConfVar [Dependency] Library))
-> [Library]
-> [(UnqualComponentName, CondTree ConfVar [Dependency] Library)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PackageDescription -> [Library]
subLibraries PackageDescription
pd
, condForeignLibs :: [(UnqualComponentName, CondTree ConfVar [Dependency] ForeignLib)]
condForeignLibs = (ForeignLib -> UnqualComponentName)
-> ForeignLib
-> (UnqualComponentName, CondTree ConfVar [Dependency] ForeignLib)
forall a.
(a -> UnqualComponentName)
-> a -> (UnqualComponentName, CondTree ConfVar [Dependency] a)
mkCondTree' ForeignLib -> UnqualComponentName
foreignLibName (ForeignLib
-> (UnqualComponentName, CondTree ConfVar [Dependency] ForeignLib))
-> [ForeignLib]
-> [(UnqualComponentName,
CondTree ConfVar [Dependency] ForeignLib)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PackageDescription -> [ForeignLib]
foreignLibs PackageDescription
pd
, condExecutables :: [(UnqualComponentName, CondTree ConfVar [Dependency] Executable)]
condExecutables = (Executable -> UnqualComponentName)
-> Executable
-> (UnqualComponentName, CondTree ConfVar [Dependency] Executable)
forall a.
(a -> UnqualComponentName)
-> a -> (UnqualComponentName, CondTree ConfVar [Dependency] a)
mkCondTree' Executable -> UnqualComponentName
exeName (Executable
-> (UnqualComponentName, CondTree ConfVar [Dependency] Executable))
-> [Executable]
-> [(UnqualComponentName,
CondTree ConfVar [Dependency] Executable)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PackageDescription -> [Executable]
executables PackageDescription
pd
, condTestSuites :: [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
condTestSuites = (TestSuite -> UnqualComponentName)
-> TestSuite
-> (UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)
forall a.
(a -> UnqualComponentName)
-> a -> (UnqualComponentName, CondTree ConfVar [Dependency] a)
mkCondTree' TestSuite -> UnqualComponentName
testName (TestSuite
-> (UnqualComponentName, CondTree ConfVar [Dependency] TestSuite))
-> [TestSuite]
-> [(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PackageDescription -> [TestSuite]
testSuites PackageDescription
pd
, condBenchmarks :: [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
condBenchmarks = (Benchmark -> UnqualComponentName)
-> Benchmark
-> (UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)
forall a.
(a -> UnqualComponentName)
-> a -> (UnqualComponentName, CondTree ConfVar [Dependency] a)
mkCondTree' Benchmark -> UnqualComponentName
benchmarkName (Benchmark
-> (UnqualComponentName, CondTree ConfVar [Dependency] Benchmark))
-> [Benchmark]
-> [(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PackageDescription -> [Benchmark]
benchmarks PackageDescription
pd
}
where
mkCondTree :: a -> CondTree v [a] a
mkCondTree x :: a
x = a -> [a] -> [CondBranch v [a] a] -> CondTree v [a] a
forall v c a. a -> c -> [CondBranch v c a] -> CondTree v c a
CondNode a
x [] []
mkCondTreeL :: Library -> (UnqualComponentName, CondTree v [a] Library)
mkCondTreeL l :: Library
l = (UnqualComponentName
-> Maybe UnqualComponentName -> UnqualComponentName
forall a. a -> Maybe a -> a
fromMaybe (FilePath -> UnqualComponentName
mkUnqualComponentName "") (LibraryName -> Maybe UnqualComponentName
libraryNameString (Library -> LibraryName
libName Library
l)), Library
-> [a] -> [CondBranch v [a] Library] -> CondTree v [a] Library
forall v c a. a -> c -> [CondBranch v c a] -> CondTree v c a
CondNode Library
l [] [])
mkCondTree'
:: (a -> UnqualComponentName)
-> a -> (UnqualComponentName, CondTree ConfVar [Dependency] a)
mkCondTree' :: (a -> UnqualComponentName)
-> a -> (UnqualComponentName, CondTree ConfVar [Dependency] a)
mkCondTree' f :: a -> UnqualComponentName
f x :: a
x = (a -> UnqualComponentName
f a
x, a
-> [Dependency]
-> [CondBranch ConfVar [Dependency] a]
-> CondTree ConfVar [Dependency] a
forall v c a. a -> c -> [CondBranch v c a] -> CondTree v c a
CondNode a
x [] [])
writeHookedBuildInfo :: FilePath -> HookedBuildInfo -> NoCallStackIO ()
writeHookedBuildInfo :: FilePath -> HookedBuildInfo -> NoCallStackIO ()
writeHookedBuildInfo fpath :: FilePath
fpath = FilePath -> ByteString -> NoCallStackIO ()
writeFileAtomic FilePath
fpath (ByteString -> NoCallStackIO ())
-> (HookedBuildInfo -> ByteString)
-> HookedBuildInfo
-> NoCallStackIO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> ByteString
BS.Char8.pack
(FilePath -> ByteString)
-> (HookedBuildInfo -> FilePath) -> HookedBuildInfo -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HookedBuildInfo -> FilePath
showHookedBuildInfo
showHookedBuildInfo :: HookedBuildInfo -> String
showHookedBuildInfo :: HookedBuildInfo -> FilePath
showHookedBuildInfo (mb_lib_bi :: Maybe BuildInfo
mb_lib_bi, ex_bis :: [(UnqualComponentName, BuildInfo)]
ex_bis) = [PrettyField] -> FilePath
showFields ([PrettyField] -> FilePath) -> [PrettyField] -> FilePath
forall a b. (a -> b) -> a -> b
$
[PrettyField]
-> (BuildInfo -> [PrettyField]) -> Maybe BuildInfo -> [PrettyField]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [PrettyField]
forall a. Monoid a => a
mempty (PrettyFieldGrammar BuildInfo BuildInfo
-> BuildInfo -> [PrettyField]
forall s a. PrettyFieldGrammar s a -> s -> [PrettyField]
prettyFieldGrammar PrettyFieldGrammar BuildInfo BuildInfo
forall (g :: * -> * -> *).
(FieldGrammar g, Applicative (g BuildInfo)) =>
g BuildInfo BuildInfo
buildInfoFieldGrammar) Maybe BuildInfo
mb_lib_bi [PrettyField] -> [PrettyField] -> [PrettyField]
forall a. [a] -> [a] -> [a]
++
[ FieldName -> [Doc] -> [PrettyField] -> PrettyField
PrettySection "executable:" [UnqualComponentName -> Doc
forall a. Pretty a => a -> Doc
pretty UnqualComponentName
name]
([PrettyField] -> PrettyField) -> [PrettyField] -> PrettyField
forall a b. (a -> b) -> a -> b
$ PrettyFieldGrammar BuildInfo BuildInfo
-> BuildInfo -> [PrettyField]
forall s a. PrettyFieldGrammar s a -> s -> [PrettyField]
prettyFieldGrammar PrettyFieldGrammar BuildInfo BuildInfo
forall (g :: * -> * -> *).
(FieldGrammar g, Applicative (g BuildInfo)) =>
g BuildInfo BuildInfo
buildInfoFieldGrammar BuildInfo
bi
| (name :: UnqualComponentName
name, bi :: BuildInfo
bi) <- [(UnqualComponentName, BuildInfo)]
ex_bis
]