{-# LANGUAGE OverloadedStrings #-}
module Distribution.Client.Init.Format
(
listFieldS
, field
, fieldD
, commentedOutWithComments
, withComments
, annNoComments
, postProcessFieldLines
, mkCommonStanza
, mkLibStanza
, mkExeStanza
, mkTestStanza
, mkPkgDescription
) where
import Distribution.CabalSpecVersion
import Distribution.Client.Init.Types
import Distribution.FieldGrammar.Newtypes (SpecLicense (SpecLicense))
import Distribution.Fields
import Distribution.License
import Distribution.Package (unPackageName)
import Distribution.PackageDescription.FieldGrammar
import Distribution.Pretty
import qualified Distribution.SPDX.License as SPDX
import Distribution.Simple.Utils hiding (cabalVersion)
import Distribution.Solver.Compat.Prelude hiding (empty)
import Distribution.Utils.Path
import Text.PrettyPrint
field
:: Pretty b
=> FieldName
-> (a -> b)
-> a
-> [String]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field :: forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field ByteString
fieldName a -> b
modifier a
fieldContents =
ByteString
-> Doc
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
fieldD ByteString
fieldName (b -> Doc
forall a. Pretty a => a -> Doc
pretty (b -> Doc) -> b -> Doc
forall a b. (a -> b) -> a -> b
$ a -> b
modifier a
fieldContents)
fieldD
:: FieldName
-> Doc
-> [String]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
fieldD :: ByteString
-> Doc
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
fieldD ByteString
fieldName Doc
fieldContents [[Char]]
fieldComments Bool
includeField WriteOpts
opts
| Bool
hasNoComments Bool -> Bool -> Bool
|| Bool
isMinimal = CommentPosition -> PrettyField FieldAnnotation
contents CommentPosition
NoComment
| Bool
otherwise = CommentPosition -> PrettyField FieldAnnotation
contents (CommentPosition -> PrettyField FieldAnnotation)
-> CommentPosition -> PrettyField FieldAnnotation
forall a b. (a -> b) -> a -> b
$ ByteString -> [[Char]] -> CommentPosition
forall {a}. (Eq a, IsString a) => a -> [[Char]] -> CommentPosition
commentPositionFor ByteString
fieldName [[Char]]
fieldComments
where
commentPositionFor :: a -> [[Char]] -> CommentPosition
commentPositionFor a
fn
| a
fn a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
"cabal-version" = [[Char]] -> CommentPosition
CommentAfter
| Bool
otherwise = [[Char]] -> CommentPosition
CommentBefore
isMinimal :: Bool
isMinimal = WriteOpts -> Bool
_optMinimal WriteOpts
opts
hasNoComments :: Bool
hasNoComments = WriteOpts -> Bool
_optNoComments WriteOpts
opts
contents :: CommentPosition -> PrettyField FieldAnnotation
contents
| Doc
fieldContents Doc -> Doc -> Bool
forall a. Eq a => a -> a -> Bool
== Doc
empty = CommentPosition -> PrettyField FieldAnnotation
fieldSEmptyContents
| Bool
otherwise = CommentPosition -> PrettyField FieldAnnotation
fieldSWithContents
fieldSEmptyContents :: CommentPosition -> PrettyField FieldAnnotation
fieldSEmptyContents CommentPosition
cs
| Bool -> Bool
not Bool
includeField Bool -> Bool -> Bool
|| Bool
isMinimal = PrettyField FieldAnnotation
forall ann. PrettyField ann
PrettyEmpty
| Bool
otherwise =
FieldAnnotation -> ByteString -> Doc -> PrettyField FieldAnnotation
forall ann. ann -> ByteString -> Doc -> PrettyField ann
PrettyField
(CommentPosition -> FieldAnnotation
commentedOutWithComments CommentPosition
cs)
ByteString
fieldName
Doc
empty
fieldSWithContents :: CommentPosition -> PrettyField FieldAnnotation
fieldSWithContents CommentPosition
cs =
FieldAnnotation -> ByteString -> Doc -> PrettyField FieldAnnotation
forall ann. ann -> ByteString -> Doc -> PrettyField ann
PrettyField (CommentPosition -> FieldAnnotation
withComments CommentPosition
cs) ByteString
fieldName Doc
fieldContents
commentedOutWithComments :: CommentPosition -> FieldAnnotation
(CommentBefore [[Char]]
cs) = Bool -> CommentPosition -> FieldAnnotation
FieldAnnotation Bool
True (CommentPosition -> FieldAnnotation)
-> ([[Char]] -> CommentPosition) -> [[Char]] -> FieldAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Char]] -> CommentPosition
CommentBefore ([[Char]] -> FieldAnnotation) -> [[Char]] -> FieldAnnotation
forall a b. (a -> b) -> a -> b
$ ([Char] -> [Char]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> [Char]
commentNoTrailing [[Char]]
cs
commentedOutWithComments (CommentAfter [[Char]]
cs) = Bool -> CommentPosition -> FieldAnnotation
FieldAnnotation Bool
True (CommentPosition -> FieldAnnotation)
-> ([[Char]] -> CommentPosition) -> [[Char]] -> FieldAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Char]] -> CommentPosition
CommentAfter ([[Char]] -> FieldAnnotation) -> [[Char]] -> FieldAnnotation
forall a b. (a -> b) -> a -> b
$ ([Char] -> [Char]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> [Char]
commentNoTrailing [[Char]]
cs
commentedOutWithComments CommentPosition
NoComment = Bool -> CommentPosition -> FieldAnnotation
FieldAnnotation Bool
True CommentPosition
NoComment
withComments :: CommentPosition -> FieldAnnotation
(CommentBefore [[Char]]
cs) = Bool -> CommentPosition -> FieldAnnotation
FieldAnnotation Bool
False (CommentPosition -> FieldAnnotation)
-> ([[Char]] -> CommentPosition) -> [[Char]] -> FieldAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Char]] -> CommentPosition
CommentBefore ([[Char]] -> FieldAnnotation) -> [[Char]] -> FieldAnnotation
forall a b. (a -> b) -> a -> b
$ ([Char] -> [Char]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> [Char]
commentNoTrailing [[Char]]
cs
withComments (CommentAfter [[Char]]
cs) = Bool -> CommentPosition -> FieldAnnotation
FieldAnnotation Bool
False (CommentPosition -> FieldAnnotation)
-> ([[Char]] -> CommentPosition) -> [[Char]] -> FieldAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Char]] -> CommentPosition
CommentAfter ([[Char]] -> FieldAnnotation) -> [[Char]] -> FieldAnnotation
forall a b. (a -> b) -> a -> b
$ ([Char] -> [Char]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> [Char]
commentNoTrailing [[Char]]
cs
withComments CommentPosition
NoComment = Bool -> CommentPosition -> FieldAnnotation
FieldAnnotation Bool
False CommentPosition
NoComment
annNoComments :: FieldAnnotation
= Bool -> CommentPosition -> FieldAnnotation
FieldAnnotation Bool
False CommentPosition
NoComment
postProcessFieldLines :: FieldAnnotation -> [String] -> [String]
postProcessFieldLines :: FieldAnnotation -> [[Char]] -> [[Char]]
postProcessFieldLines FieldAnnotation
ann
| FieldAnnotation -> Bool
annCommentedOut FieldAnnotation
ann = ([Char] -> [Char]) -> [[Char]] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Char] -> [Char]
commentNoTrailing
| Bool
otherwise = [[Char]] -> [[Char]]
forall a. a -> a
id
mkCommonStanza :: WriteOpts -> PrettyField FieldAnnotation
mkCommonStanza :: WriteOpts -> PrettyField FieldAnnotation
mkCommonStanza WriteOpts
opts = case CabalSpecVersion -> HasCommonStanzas
specHasCommonStanzas (CabalSpecVersion -> HasCommonStanzas)
-> CabalSpecVersion -> HasCommonStanzas
forall a b. (a -> b) -> a -> b
$ WriteOpts -> CabalSpecVersion
_optCabalSpec WriteOpts
opts of
HasCommonStanzas
NoCommonStanzas -> PrettyField FieldAnnotation
forall ann. PrettyField ann
PrettyEmpty
HasCommonStanzas
_ ->
FieldAnnotation
-> ByteString
-> [Doc]
-> [PrettyField FieldAnnotation]
-> PrettyField FieldAnnotation
forall ann.
ann -> ByteString -> [Doc] -> [PrettyField ann] -> PrettyField ann
PrettySection
FieldAnnotation
annNoComments
ByteString
"common"
[[Char] -> Doc
text [Char]
"warnings"]
[ByteString
-> ([Char] -> Doc)
-> [Char]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field ByteString
"ghc-options" [Char] -> Doc
text [Char]
"-Wall" [] Bool
False WriteOpts
opts]
mkLibStanza :: WriteOpts -> LibTarget -> PrettyField FieldAnnotation
mkLibStanza :: WriteOpts -> LibTarget -> PrettyField FieldAnnotation
mkLibStanza WriteOpts
opts (LibTarget [[Char]]
srcDirs Language
lang NonEmpty ModuleName
expMods [ModuleName]
otherMods [Extension]
exts [Dependency]
deps [Dependency]
tools) =
FieldAnnotation
-> ByteString
-> [Doc]
-> [PrettyField FieldAnnotation]
-> PrettyField FieldAnnotation
forall ann.
ann -> ByteString -> [Doc] -> [PrettyField ann] -> PrettyField ann
PrettySection
FieldAnnotation
annNoComments
([Char] -> ByteString
toUTF8BS [Char]
"library")
[]
[ case CabalSpecVersion -> HasCommonStanzas
specHasCommonStanzas (CabalSpecVersion -> HasCommonStanzas)
-> CabalSpecVersion -> HasCommonStanzas
forall a b. (a -> b) -> a -> b
$ WriteOpts -> CabalSpecVersion
_optCabalSpec WriteOpts
opts of
HasCommonStanzas
NoCommonStanzas -> PrettyField FieldAnnotation
forall ann. PrettyField ann
PrettyEmpty
HasCommonStanzas
_ ->
ByteString
-> ([[Char]] -> Doc)
-> [[Char]]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"import"
([Doc] -> Doc
hsep ([Doc] -> Doc) -> ([[Char]] -> [Doc]) -> [[Char]] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char] -> Doc) -> [[Char]] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> Doc
text)
[[Char]
"warnings"]
[[Char]
"Import common warning flags."]
Bool
False
WriteOpts
opts
, ByteString
-> ([ModuleName] -> List VCat (MQuoted ModuleName) ModuleName)
-> [ModuleName]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"exposed-modules"
[ModuleName] -> List VCat (MQuoted ModuleName) ModuleName
formatExposedModules
(NonEmpty ModuleName -> [ModuleName]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty ModuleName
expMods)
[[Char]
"Modules exported by the library."]
Bool
True
WriteOpts
opts
, ByteString
-> ([ModuleName] -> List VCat (MQuoted ModuleName) ModuleName)
-> [ModuleName]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"other-modules"
[ModuleName] -> List VCat (MQuoted ModuleName) ModuleName
formatOtherModules
[ModuleName]
otherMods
[[Char]
"Modules included in this library but not exported."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Extension] -> List FSep (MQuoted Extension) Extension)
-> [Extension]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"other-extensions"
[Extension] -> List FSep (MQuoted Extension) Extension
formatOtherExtensions
[Extension]
exts
[[Char]
"LANGUAGE extensions used by modules in this package."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Dependency]
-> List CommaVCat (Identity Dependency) Dependency)
-> [Dependency]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"build-depends"
[Dependency] -> List CommaVCat (Identity Dependency) Dependency
formatDependencyList
[Dependency]
deps
[[Char]
"Other library packages from which modules are imported."]
Bool
True
WriteOpts
opts
, ByteString
-> ([SymbolicPath Pkg ('Dir Source)]
-> List
FSep
(SymbolicPathNT Pkg ('Dir Source))
(SymbolicPath Pkg ('Dir Source)))
-> [SymbolicPath Pkg ('Dir Source)]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"hs-source-dirs"
[SymbolicPath Pkg ('Dir Source)]
-> List
FSep
(SymbolicPathNT Pkg ('Dir Source))
(SymbolicPath Pkg ('Dir Source))
formatHsSourceDirs
([Char] -> SymbolicPath Pkg ('Dir Source)
forall from (to :: FileOrDir). [Char] -> SymbolicPath from to
makeSymbolicPath ([Char] -> SymbolicPath Pkg ('Dir Source))
-> [[Char]] -> [SymbolicPath Pkg ('Dir Source)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[Char]]
srcDirs)
[[Char]
"Directories containing source files."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Dependency]
-> List CommaVCat (Identity Dependency) Dependency)
-> [Dependency]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
(WriteOpts -> ByteString
buildToolTag WriteOpts
opts)
[Dependency] -> List CommaVCat (Identity Dependency) Dependency
formatDependencyList
[Dependency]
tools
[[Char]
"Extra tools (e.g. alex, hsc2hs, ...) needed to build the source."]
Bool
False
WriteOpts
opts
, ByteString
-> (Language -> Language)
-> Language
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"default-language"
Language -> Language
forall a. a -> a
id
Language
lang
[[Char]
"Base language which the package is written in."]
Bool
True
WriteOpts
opts
]
mkExeStanza :: WriteOpts -> ExeTarget -> PrettyField FieldAnnotation
mkExeStanza :: WriteOpts -> ExeTarget -> PrettyField FieldAnnotation
mkExeStanza WriteOpts
opts (ExeTarget HsFilePath
exeMain [[Char]]
appDirs Language
lang [ModuleName]
otherMods [Extension]
exts [Dependency]
deps [Dependency]
tools) =
FieldAnnotation
-> ByteString
-> [Doc]
-> [PrettyField FieldAnnotation]
-> PrettyField FieldAnnotation
forall ann.
ann -> ByteString -> [Doc] -> [PrettyField ann] -> PrettyField ann
PrettySection
FieldAnnotation
annNoComments
([Char] -> ByteString
toUTF8BS [Char]
"executable")
[Doc
exeName]
[ case CabalSpecVersion -> HasCommonStanzas
specHasCommonStanzas (CabalSpecVersion -> HasCommonStanzas)
-> CabalSpecVersion -> HasCommonStanzas
forall a b. (a -> b) -> a -> b
$ WriteOpts -> CabalSpecVersion
_optCabalSpec WriteOpts
opts of
HasCommonStanzas
NoCommonStanzas -> PrettyField FieldAnnotation
forall ann. PrettyField ann
PrettyEmpty
HasCommonStanzas
_ ->
ByteString
-> ([[Char]] -> Doc)
-> [[Char]]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"import"
([Doc] -> Doc
hsep ([Doc] -> Doc) -> ([[Char]] -> [Doc]) -> [[Char]] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char] -> Doc) -> [[Char]] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> Doc
text)
[[Char]
"warnings"]
[[Char]
"Import common warning flags."]
Bool
False
WriteOpts
opts
, ByteString
-> (HsFilePath -> Doc)
-> HsFilePath
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"main-is"
HsFilePath -> Doc
unsafeFromHs
HsFilePath
exeMain
[[Char]
".hs or .lhs file containing the Main module."]
Bool
True
WriteOpts
opts
, ByteString
-> ([ModuleName] -> List VCat (MQuoted ModuleName) ModuleName)
-> [ModuleName]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"other-modules"
[ModuleName] -> List VCat (MQuoted ModuleName) ModuleName
formatOtherModules
[ModuleName]
otherMods
[[Char]
"Modules included in this executable, other than Main."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Extension] -> List FSep (MQuoted Extension) Extension)
-> [Extension]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"other-extensions"
[Extension] -> List FSep (MQuoted Extension) Extension
formatOtherExtensions
[Extension]
exts
[[Char]
"LANGUAGE extensions used by modules in this package."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Dependency]
-> List CommaVCat (Identity Dependency) Dependency)
-> [Dependency]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"build-depends"
[Dependency] -> List CommaVCat (Identity Dependency) Dependency
formatDependencyList
[Dependency]
deps
[[Char]
"Other library packages from which modules are imported."]
Bool
True
WriteOpts
opts
, ByteString
-> ([SymbolicPath Pkg ('Dir Source)]
-> List
FSep
(SymbolicPathNT Pkg ('Dir Source))
(SymbolicPath Pkg ('Dir Source)))
-> [SymbolicPath Pkg ('Dir Source)]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"hs-source-dirs"
[SymbolicPath Pkg ('Dir Source)]
-> List
FSep
(SymbolicPathNT Pkg ('Dir Source))
(SymbolicPath Pkg ('Dir Source))
formatHsSourceDirs
([Char] -> SymbolicPath Pkg ('Dir Source)
forall from (to :: FileOrDir). [Char] -> SymbolicPath from to
makeSymbolicPath ([Char] -> SymbolicPath Pkg ('Dir Source))
-> [[Char]] -> [SymbolicPath Pkg ('Dir Source)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[Char]]
appDirs)
[[Char]
"Directories containing source files."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Dependency]
-> List CommaVCat (Identity Dependency) Dependency)
-> [Dependency]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
(WriteOpts -> ByteString
buildToolTag WriteOpts
opts)
[Dependency] -> List CommaVCat (Identity Dependency) Dependency
formatDependencyList
[Dependency]
tools
[[Char]
"Extra tools (e.g. alex, hsc2hs, ...) needed to build the source."]
Bool
False
WriteOpts
opts
, ByteString
-> (Language -> Language)
-> Language
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"default-language"
Language -> Language
forall a. a -> a
id
Language
lang
[[Char]
"Base language which the package is written in."]
Bool
True
WriteOpts
opts
]
where
exeName :: Doc
exeName = PackageName -> Doc
forall a. Pretty a => a -> Doc
pretty (PackageName -> Doc) -> PackageName -> Doc
forall a b. (a -> b) -> a -> b
$ WriteOpts -> PackageName
_optPkgName WriteOpts
opts
mkTestStanza :: WriteOpts -> TestTarget -> PrettyField FieldAnnotation
mkTestStanza :: WriteOpts -> TestTarget -> PrettyField FieldAnnotation
mkTestStanza WriteOpts
opts (TestTarget HsFilePath
testMain [[Char]]
dirs Language
lang [ModuleName]
otherMods [Extension]
exts [Dependency]
deps [Dependency]
tools) =
FieldAnnotation
-> ByteString
-> [Doc]
-> [PrettyField FieldAnnotation]
-> PrettyField FieldAnnotation
forall ann.
ann -> ByteString -> [Doc] -> [PrettyField ann] -> PrettyField ann
PrettySection
FieldAnnotation
annNoComments
([Char] -> ByteString
toUTF8BS [Char]
"test-suite")
[Doc
suiteName]
[ case CabalSpecVersion -> HasCommonStanzas
specHasCommonStanzas (CabalSpecVersion -> HasCommonStanzas)
-> CabalSpecVersion -> HasCommonStanzas
forall a b. (a -> b) -> a -> b
$ WriteOpts -> CabalSpecVersion
_optCabalSpec WriteOpts
opts of
HasCommonStanzas
NoCommonStanzas -> PrettyField FieldAnnotation
forall ann. PrettyField ann
PrettyEmpty
HasCommonStanzas
_ ->
ByteString
-> ([[Char]] -> Doc)
-> [[Char]]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"import"
([Doc] -> Doc
hsep ([Doc] -> Doc) -> ([[Char]] -> [Doc]) -> [[Char]] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char] -> Doc) -> [[Char]] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> Doc
text)
[[Char]
"warnings"]
[[Char]
"Import common warning flags."]
Bool
False
WriteOpts
opts
, ByteString
-> (Language -> Language)
-> Language
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"default-language"
Language -> Language
forall a. a -> a
id
Language
lang
[[Char]
"Base language which the package is written in."]
Bool
True
WriteOpts
opts
, ByteString
-> ([ModuleName] -> List VCat (MQuoted ModuleName) ModuleName)
-> [ModuleName]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"other-modules"
[ModuleName] -> List VCat (MQuoted ModuleName) ModuleName
formatOtherModules
[ModuleName]
otherMods
[[Char]
"Modules included in this executable, other than Main."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Extension] -> List FSep (MQuoted Extension) Extension)
-> [Extension]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"other-extensions"
[Extension] -> List FSep (MQuoted Extension) Extension
formatOtherExtensions
[Extension]
exts
[[Char]
"LANGUAGE extensions used by modules in this package."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Char] -> Doc)
-> [Char]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"type"
[Char] -> Doc
text
[Char]
"exitcode-stdio-1.0"
[[Char]
"The interface type and version of the test suite."]
Bool
True
WriteOpts
opts
, ByteString
-> ([SymbolicPath Pkg ('Dir Source)]
-> List
FSep
(SymbolicPathNT Pkg ('Dir Source))
(SymbolicPath Pkg ('Dir Source)))
-> [SymbolicPath Pkg ('Dir Source)]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"hs-source-dirs"
[SymbolicPath Pkg ('Dir Source)]
-> List
FSep
(SymbolicPathNT Pkg ('Dir Source))
(SymbolicPath Pkg ('Dir Source))
formatHsSourceDirs
([Char] -> SymbolicPath Pkg ('Dir Source)
forall from (to :: FileOrDir). [Char] -> SymbolicPath from to
makeSymbolicPath ([Char] -> SymbolicPath Pkg ('Dir Source))
-> [[Char]] -> [SymbolicPath Pkg ('Dir Source)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[Char]]
dirs)
[[Char]
"Directories containing source files."]
Bool
True
WriteOpts
opts
, ByteString
-> (HsFilePath -> Doc)
-> HsFilePath
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"main-is"
HsFilePath -> Doc
unsafeFromHs
HsFilePath
testMain
[[Char]
"The entrypoint to the test suite."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Dependency]
-> List CommaVCat (Identity Dependency) Dependency)
-> [Dependency]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"build-depends"
[Dependency] -> List CommaVCat (Identity Dependency) Dependency
formatDependencyList
[Dependency]
deps
[[Char]
"Test dependencies."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Dependency]
-> List CommaVCat (Identity Dependency) Dependency)
-> [Dependency]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
(WriteOpts -> ByteString
buildToolTag WriteOpts
opts)
[Dependency] -> List CommaVCat (Identity Dependency) Dependency
formatDependencyList
[Dependency]
tools
[[Char]
"Extra tools (e.g. alex, hsc2hs, ...) needed to build the source."]
Bool
False
WriteOpts
opts
]
where
suiteName :: Doc
suiteName = [Char] -> Doc
text ([Char] -> Doc) -> [Char] -> Doc
forall a b. (a -> b) -> a -> b
$ PackageName -> [Char]
unPackageName (WriteOpts -> PackageName
_optPkgName WriteOpts
opts) [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"-test"
mkPkgDescription :: WriteOpts -> PkgDescription -> [PrettyField FieldAnnotation]
mkPkgDescription :: WriteOpts -> PkgDescription -> [PrettyField FieldAnnotation]
mkPkgDescription WriteOpts
opts PkgDescription
pkgDesc =
[ ByteString
-> ([Char] -> Doc)
-> [Char]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"cabal-version"
[Char] -> Doc
text
((if CabalSpecVersion
cabalSpec CabalSpecVersion -> CabalSpecVersion -> Bool
forall a. Ord a => a -> a -> Bool
< CabalSpecVersion
CabalSpecV1_12 then [Char]
">=" else [Char]
"") [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ CabalSpecVersion -> [Char]
showCabalSpecVersion CabalSpecVersion
cabalSpec)
[ [Char]
"The cabal-version field refers to the version of the .cabal specification,"
, [Char]
"and can be different from the cabal-install (the tool) version and the"
, [Char]
"Cabal (the library) version you are using. As such, the Cabal (the library)"
, [Char]
"version used must be equal or greater than the version stated in this field."
, [Char]
"Starting from the specification version 2.2, the cabal-version field must be"
, [Char]
"the first thing in the cabal file."
]
Bool
False
WriteOpts
opts
, ByteString
-> (PackageName -> Doc)
-> PackageName
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"name"
PackageName -> Doc
forall a. Pretty a => a -> Doc
pretty
(PkgDescription -> PackageName
_pkgName PkgDescription
pkgDesc)
[ [Char]
"Initial package description '" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ PackageName -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow (WriteOpts -> PackageName
_optPkgName WriteOpts
opts) [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"' generated by"
, [Char]
"'cabal init'. For further documentation, see:"
, [Char]
" http://haskell.org/cabal/users-guide/"
, [Char]
""
, [Char]
"The name of the package."
]
Bool
True
WriteOpts
opts
, ByteString
-> (Version -> Doc)
-> Version
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"version"
Version -> Doc
forall a. Pretty a => a -> Doc
pretty
(PkgDescription -> Version
_pkgVersion PkgDescription
pkgDesc)
[ [Char]
"The package version."
, [Char]
"See the Haskell package versioning policy (PVP) for standards"
, [Char]
"guiding when and how versions should be incremented."
, [Char]
"https://pvp.haskell.org"
, [Char]
"PVP summary: +-+------- breaking API changes"
, [Char]
" | | +----- non-breaking API additions"
, [Char]
" | | | +--- code changes with no API change"
]
Bool
True
WriteOpts
opts
, ByteString
-> ([Char] -> Doc)
-> [Char]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"synopsis"
[Char] -> Doc
text
(PkgDescription -> [Char]
_pkgSynopsis PkgDescription
pkgDesc)
[[Char]
"A short (one-line) description of the package."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Char] -> Doc)
-> [Char]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"description"
[Char] -> Doc
text
[Char]
""
[[Char]
"A longer description of the package."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Char] -> Doc)
-> [Char]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"homepage"
[Char] -> Doc
text
(PkgDescription -> [Char]
_pkgHomePage PkgDescription
pkgDesc)
[[Char]
"URL for the project homepage or repository."]
Bool
False
WriteOpts
opts
, ByteString
-> ([Char] -> Doc)
-> [Char]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"bug-reports"
[Char] -> Doc
text
[Char]
""
[[Char]
"A URL where users can report bugs."]
Bool
False
WriteOpts
opts
, ByteString
-> (SpecLicense -> Doc)
-> SpecLicense
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"license"
SpecLicense -> Doc
forall a. Pretty a => a -> Doc
pretty
(PkgDescription -> SpecLicense
_pkgLicense PkgDescription
pkgDesc)
[[Char]
"The license under which the package is released."]
Bool
True
WriteOpts
opts
, case PkgDescription -> SpecLicense
_pkgLicense PkgDescription
pkgDesc of
SpecLicense (Left License
SPDX.NONE) -> PrettyField FieldAnnotation
forall ann. PrettyField ann
PrettyEmpty
SpecLicense (Right License
AllRightsReserved) -> PrettyField FieldAnnotation
forall ann. PrettyField ann
PrettyEmpty
SpecLicense (Right License
UnspecifiedLicense) -> PrettyField FieldAnnotation
forall ann. PrettyField ann
PrettyEmpty
SpecLicense
_ ->
ByteString
-> ([Char] -> Doc)
-> [Char]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"license-file"
[Char] -> Doc
text
[Char]
"LICENSE"
[[Char]
"The file containing the license text."]
Bool
False
WriteOpts
opts
, ByteString
-> ([Char] -> Doc)
-> [Char]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"author"
[Char] -> Doc
text
(PkgDescription -> [Char]
_pkgAuthor PkgDescription
pkgDesc)
[[Char]
"The package author(s)."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Char] -> Doc)
-> [Char]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"maintainer"
[Char] -> Doc
text
(PkgDescription -> [Char]
_pkgEmail PkgDescription
pkgDesc)
[[Char]
"An email address to which users can send suggestions, bug reports, and patches."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Char] -> Doc)
-> [Char]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"copyright"
[Char] -> Doc
text
[Char]
""
[[Char]
"A copyright notice."]
Bool
True
WriteOpts
opts
, ByteString
-> ([Char] -> Doc)
-> [Char]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"category"
[Char] -> Doc
text
(PkgDescription -> [Char]
_pkgCategory PkgDescription
pkgDesc)
[]
Bool
False
WriteOpts
opts
, ByteString
-> ([Char] -> Doc)
-> [Char]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"build-type"
[Char] -> Doc
text
[Char]
"Simple"
[]
Bool
False
WriteOpts
opts
, case PkgDescription -> Maybe (Set [Char])
_pkgExtraDocFiles PkgDescription
pkgDesc of
Maybe (Set [Char])
Nothing -> PrettyField FieldAnnotation
forall ann. PrettyField ann
PrettyEmpty
Just Set [Char]
fs ->
ByteString
-> ([[Char]]
-> List VCat (RelativePathNT Pkg 'File) (RelativePath Pkg 'File))
-> [[Char]]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"extra-doc-files"
([RelativePath Pkg 'File]
-> List VCat (RelativePathNT Pkg 'File) (RelativePath Pkg 'File)
formatExtraSourceFiles ([RelativePath Pkg 'File]
-> List VCat (RelativePathNT Pkg 'File) (RelativePath Pkg 'File))
-> ([[Char]] -> [RelativePath Pkg 'File])
-> [[Char]]
-> List VCat (RelativePathNT Pkg 'File) (RelativePath Pkg 'File)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char] -> RelativePath Pkg 'File)
-> [[Char]] -> [RelativePath Pkg 'File]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> RelativePath Pkg 'File
forall (allowAbs :: AllowAbsolute) from (to :: FileOrDir).
[Char] -> SymbolicPathX allowAbs from to
unsafeMakeSymbolicPath)
(Set [Char] -> [[Char]]
forall a. Set a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList Set [Char]
fs)
[[Char]
"Extra doc files to be distributed with the package, such as a CHANGELOG or a README."]
Bool
True
WriteOpts
opts
, ByteString
-> ([[Char]]
-> List VCat (RelativePathNT Pkg 'File) (RelativePath Pkg 'File))
-> [[Char]]
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
forall b a.
Pretty b =>
ByteString
-> (a -> b)
-> a
-> [[Char]]
-> Bool
-> WriteOpts
-> PrettyField FieldAnnotation
field
ByteString
"extra-source-files"
([RelativePath Pkg 'File]
-> List VCat (RelativePathNT Pkg 'File) (RelativePath Pkg 'File)
formatExtraSourceFiles ([RelativePath Pkg 'File]
-> List VCat (RelativePathNT Pkg 'File) (RelativePath Pkg 'File))
-> ([[Char]] -> [RelativePath Pkg 'File])
-> [[Char]]
-> List VCat (RelativePathNT Pkg 'File) (RelativePath Pkg 'File)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char] -> RelativePath Pkg 'File)
-> [[Char]] -> [RelativePath Pkg 'File]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> RelativePath Pkg 'File
forall (allowAbs :: AllowAbsolute) from (to :: FileOrDir).
[Char] -> SymbolicPathX allowAbs from to
unsafeMakeSymbolicPath)
(Set [Char] -> [[Char]]
forall a. Set a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (Set [Char] -> [[Char]]) -> Set [Char] -> [[Char]]
forall a b. (a -> b) -> a -> b
$ PkgDescription -> Set [Char]
_pkgExtraSrcFiles PkgDescription
pkgDesc)
[[Char]
"Extra source files to be distributed with the package, such as examples, or a tutorial module."]
Bool
True
WriteOpts
opts
]
where
cabalSpec :: CabalSpecVersion
cabalSpec = PkgDescription -> CabalSpecVersion
_pkgCabalVersion PkgDescription
pkgDesc
listFieldS :: [String] -> Doc
listFieldS :: [[Char]] -> Doc
listFieldS = [Char] -> Doc
text ([Char] -> Doc) -> ([[Char]] -> [Char]) -> [[Char]] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
", "
unsafeFromHs :: HsFilePath -> Doc
unsafeFromHs :: HsFilePath -> Doc
unsafeFromHs = [Char] -> Doc
text ([Char] -> Doc) -> (HsFilePath -> [Char]) -> HsFilePath -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsFilePath -> [Char]
_hsFilePath
buildToolTag :: WriteOpts -> FieldName
buildToolTag :: WriteOpts -> ByteString
buildToolTag WriteOpts
opts
| WriteOpts -> CabalSpecVersion
_optCabalSpec WriteOpts
opts CabalSpecVersion -> CabalSpecVersion -> Bool
forall a. Ord a => a -> a -> Bool
< CabalSpecVersion
CabalSpecV3_0 = ByteString
"build-tools"
| Bool
otherwise = ByteString
"build-tool-depends"
commentNoTrailing :: String -> String
[Char]
"" = [Char]
"--"
commentNoTrailing [Char]
c = [Char]
"-- " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
c