1
+ {-# LANGUAGE OverloadedStrings #-}
1
2
-----------------------------------------------------------------------------
2
3
-- |
3
4
-- Module : Distribution.Client.Init.FileCreators
@@ -50,7 +51,7 @@ import System.Directory
50
51
( getCurrentDirectory , doesFileExist , copyFile
51
52
, createDirectoryIfMissing )
52
53
53
- import Text.PrettyPrint hiding (mode , cat )
54
+ import Text.PrettyPrint hiding ((<>) , mode , cat )
54
55
55
56
import Distribution.Client.Init.Defaults
56
57
( defaultCabalVersion , myLibModule )
@@ -62,8 +63,12 @@ import Distribution.Client.Init.Types
62
63
( InitFlags (.. ), BuildType (.. ), PackageType (.. ) )
63
64
64
65
import Distribution.CabalSpecVersion
66
+ import Distribution.Compat.Newtype
67
+ ( Newtype )
65
68
import Distribution.Deprecated.Text
66
69
( display , Text (.. ) )
70
+ import Distribution.Fields.Field
71
+ ( FieldName )
67
72
import Distribution.License
68
73
( licenseFromSPDX )
69
74
import qualified Distribution.ModuleName as ModuleName
@@ -417,7 +422,7 @@ generateCabalFile fileName c =
417
422
[]
418
423
False
419
424
420
- , fieldP " extra-source-files" (maybeToFlag $ (formatExtraSourceFiles <$> extraSrc c))
425
+ , fieldPAla " extra-source-files" formatExtraSourceFiles (maybeToFlag ( extraSrc c))
421
426
[" Extra files to be distributed with the package, such as examples or a README." ]
422
427
True
423
428
]
@@ -439,22 +444,22 @@ generateCabalFile fileName c =
439
444
440
445
generateBuildInfo :: BuildType -> InitFlags -> [PrettyField [String ]]
441
446
generateBuildInfo buildType c' = catMaybes
442
- [ fieldP " other-modules" ( formatOtherModules <$> maybeToFlag otherMods)
447
+ [ fieldPAla " other-modules" formatOtherModules ( maybeToFlag otherMods)
443
448
[ case buildType of
444
449
LibBuild -> " Modules included in this library but not exported."
445
450
ExecBuild -> " Modules included in this executable, other than Main." ]
446
451
True
447
452
448
- , fieldP " other-extensions" (maybeToFlag (formatOtherExtensions <$> otherExts c))
453
+ , fieldPAla " other-extensions" formatOtherExtensions (maybeToFlag (otherExts c))
449
454
[" LANGUAGE extensions used by modules in this package." ]
450
455
True
451
456
452
- , fieldP " build-depends" (maybeToFlag (formatDependencyList <$> buildDependencies) )
457
+ , fieldPAla " build-depends" formatDependencyList (maybeToFlag buildDependencies)
453
458
[" Other library packages from which modules are imported." ]
454
459
True
455
460
456
- , fieldP " hs-source-dirs"
457
- (maybeToFlag (formatHsSourceDirs <$> case buildType of
461
+ , fieldPAla " hs-source-dirs" formatHsSourceDirs
462
+ (maybeToFlag (case buildType of
458
463
LibBuild -> sourceDirs c
459
464
ExecBuild -> applicationDirs c))
460
465
[" Directories containing source files." ]
@@ -494,16 +499,16 @@ generateCabalFile fileName c =
494
499
495
500
-- | Construct a 'PrettyField' from a field that can be automatically
496
501
-- converted to a 'Doc' via 'display'.
497
- field :: Text t =>
498
- String
502
+ field :: Text t
503
+ => FieldName
499
504
-> Flag t
500
505
-> [String ]
501
506
-> Bool
502
507
-> Maybe (PrettyField [String ])
503
508
field fieldName fieldContentsFlag = fieldS fieldName (display <$> fieldContentsFlag)
504
509
505
510
-- | Construct a 'PrettyField' from a 'String' field.
506
- fieldS :: String -- ^ Name of the field
511
+ fieldS :: FieldName -- ^ Name of the field
507
512
-> Flag String -- ^ Field contents
508
513
-> [String ] -- ^ Comment to explain the field
509
514
-> Bool -- ^ Should the field be included (commented out) even if blank?
@@ -512,16 +517,28 @@ generateCabalFile fileName c =
512
517
513
518
-- | Construct a 'PrettyField' from a Flag which can be 'pretty'-ied.
514
519
fieldP :: Pretty a
515
- => String
520
+ => FieldName
516
521
-> Flag a
517
522
-> [String ]
518
523
-> Bool
519
524
-> Maybe (PrettyField [String ])
520
525
fieldP fieldName fieldContentsFlag fieldComments includeField =
521
- fieldD fieldName (pretty <$> fieldContentsFlag) fieldComments includeField
526
+ fieldPAla fieldName Identity fieldContentsFlag fieldComments includeField
527
+
528
+ -- | Construct a 'PrettyField' from a flag which can be 'pretty'-ied, wrapped in newtypeWrapper.
529
+ fieldPAla
530
+ :: (Pretty b , Newtype a b )
531
+ => FieldName
532
+ -> (a -> b )
533
+ -> Flag a
534
+ -> [String ]
535
+ -> Bool
536
+ -> Maybe (PrettyField [String ])
537
+ fieldPAla fieldName newtypeWrapper fieldContentsFlag fieldComments includeField =
538
+ fieldD fieldName (pretty . newtypeWrapper <$> fieldContentsFlag) fieldComments includeField
522
539
523
540
-- | Construct a 'PrettyField' from a 'Doc' Flag.
524
- fieldD :: String -- ^ Name of the field
541
+ fieldD :: FieldName -- ^ Name of the field
525
542
-> Flag Doc -- ^ Field contents
526
543
-> [String ] -- ^ Comment to explain the field
527
544
-> Bool -- ^ Should the field be included (commented out) even if blank?
@@ -551,23 +568,23 @@ generateCabalFile fileName c =
551
568
fieldSWithContents fieldName fieldContents fieldComments
552
569
553
570
-- | Optionally produce a field with no content (depending on flags).
554
- fieldSEmptyContents :: String
571
+ fieldSEmptyContents :: FieldName
555
572
-> [String ]
556
573
-> Bool
557
574
-> Maybe (PrettyField [String ])
558
575
fieldSEmptyContents fieldName fieldComments includeField
559
576
| not includeField || (minimal c == Flag True ) =
560
577
Nothing
561
578
| otherwise =
562
- Just (PrettyFieldCommentedOut (map (" -- " ++ ) fieldComments) (toUTF8BS fieldName) )
579
+ Just (PrettyFieldCommentedOut (map (" -- " ++ ) fieldComments) fieldName)
563
580
564
581
-- | Produce a field with content.
565
- fieldSWithContents :: String
582
+ fieldSWithContents :: FieldName
566
583
-> Doc
567
584
-> [String ]
568
585
-> PrettyField [String ]
569
586
fieldSWithContents fieldName fieldContents fieldComments =
570
- PrettyField (map (" -- " ++ ) fieldComments) (toUTF8BS fieldName) fieldContents
587
+ PrettyField (map (" -- " ++ ) fieldComments) fieldName fieldContents
571
588
572
589
executableStanza :: PrettyField [String ]
573
590
executableStanza = PrettySection [] (toUTF8BS " executable" ) [exeName] $ catMaybes
@@ -582,7 +599,7 @@ generateCabalFile fileName c =
582
599
583
600
libraryStanza :: PrettyField [String ]
584
601
libraryStanza = PrettySection [] (toUTF8BS " library" ) [] $ catMaybes
585
- [ fieldP " exposed-modules" (maybeToFlag (formatExposedModules <$> exposedModules c))
602
+ [ fieldPAla " exposed-modules" formatExposedModules (maybeToFlag (exposedModules c))
586
603
[" Modules exported by the library." ]
587
604
True
588
605
]
@@ -600,16 +617,16 @@ generateCabalFile fileName c =
600
617
[" The interface type and version of the test suite." ]
601
618
True
602
619
603
- , fieldP " hs-source-dirs"
604
- (maybeToFlag (formatHsSourceDirs <$> testDirs c))
620
+ , fieldPAla " hs-source-dirs" formatHsSourceDirs
621
+ (maybeToFlag (testDirs c))
605
622
[" Directories containing source files." ]
606
623
True
607
624
608
625
, fieldS " main-is" (Flag testFile)
609
626
[" The entrypoint to the test suite." ]
610
627
True
611
628
612
- , fieldP " build-depends" (maybeToFlag (formatDependencyList <$> dependencies c))
629
+ , fieldPAla " build-depends" formatDependencyList (maybeToFlag (dependencies c))
613
630
[" Test dependencies." ]
614
631
True
615
632
]
0 commit comments