@@ -189,7 +189,7 @@ data PackageDescription
189
189
buildType :: Maybe BuildType ,
190
190
setupBuildInfo :: Maybe SetupBuildInfo ,
191
191
-- components
192
- library :: Maybe Library ,
192
+ libraries :: [ Library ] ,
193
193
executables :: [Executable ],
194
194
testSuites :: [TestSuite ],
195
195
benchmarks :: [Benchmark ],
@@ -256,7 +256,7 @@ emptyPackageDescription
256
256
category = " " ,
257
257
customFieldsPD = [] ,
258
258
setupBuildInfo = Nothing ,
259
- library = Nothing ,
259
+ libraries = [] ,
260
260
executables = [] ,
261
261
testSuites = [] ,
262
262
benchmarks = [] ,
@@ -390,6 +390,7 @@ instance Text ModuleRenaming where
390
390
-- The Library type
391
391
392
392
data Library = Library {
393
+ libName :: String ,
393
394
exposedModules :: [ModuleName ],
394
395
reexportedModules :: [ModuleReexport ],
395
396
requiredSignatures :: [ModuleName ], -- ^ What sigs need implementations?
@@ -403,6 +404,7 @@ instance Binary Library
403
404
404
405
instance Monoid Library where
405
406
mempty = Library {
407
+ libName = mempty ,
406
408
exposedModules = mempty ,
407
409
reexportedModules = mempty ,
408
410
requiredSignatures = mempty ,
@@ -414,6 +416,7 @@ instance Monoid Library where
414
416
415
417
instance Semigroup Library where
416
418
a <> b = Library {
419
+ libName = combine' libName,
417
420
exposedModules = combine exposedModules,
418
421
reexportedModules = combine reexportedModules,
419
422
requiredSignatures = combine requiredSignatures,
@@ -422,20 +425,26 @@ instance Semigroup Library where
422
425
libBuildInfo = combine libBuildInfo
423
426
}
424
427
where combine field = field a `mappend` field b
428
+ combine' field = case (field a, field b) of
429
+ (" " ," " ) -> " "
430
+ (" " , x) -> x
431
+ (x, " " ) -> x
432
+ (x, y) -> error $ " Ambiguous values for library field: '"
433
+ ++ x ++ " ' and '" ++ y ++ " '"
425
434
426
435
emptyLibrary :: Library
427
436
emptyLibrary = mempty
428
437
429
438
-- | does this package have any libraries?
430
439
hasLibs :: PackageDescription -> Bool
431
- hasLibs p = maybe False (buildable . libBuildInfo) (library p)
440
+ hasLibs p = any (buildable . libBuildInfo) (libraries p)
432
441
433
442
-- | 'Maybe' version of 'hasLibs'
434
- maybeHasLibs :: PackageDescription -> Maybe Library
443
+ maybeHasLibs :: PackageDescription -> [ Library ]
435
444
maybeHasLibs p =
436
- library p >>= \ lib -> if buildable (libBuildInfo lib)
437
- then Just lib
438
- else Nothing
445
+ libraries p >>= \ lib -> if buildable (libBuildInfo lib)
446
+ then return lib
447
+ else []
439
448
440
449
-- | If the package description has a library section, call the given
441
450
-- function with the library build info as argument.
@@ -919,7 +928,7 @@ emptyBuildInfo = mempty
919
928
-- all buildable executables, test suites and benchmarks. Useful for gathering
920
929
-- dependencies.
921
930
allBuildInfo :: PackageDescription -> [BuildInfo ]
922
- allBuildInfo pkg_descr = [ bi | Just lib <- [library pkg_descr]
931
+ allBuildInfo pkg_descr = [ bi | lib <- libraries pkg_descr
923
932
, let bi = libBuildInfo lib
924
933
, buildable bi ]
925
934
++ [ bi | exe <- executables pkg_descr
@@ -954,10 +963,10 @@ usedExtensions :: BuildInfo -> [Extension]
954
963
usedExtensions bi = oldExtensions bi
955
964
++ defaultExtensions bi
956
965
957
- type HookedBuildInfo = (Maybe BuildInfo , [(String , BuildInfo )])
966
+ type HookedBuildInfo = ([( String , BuildInfo )] , [(String , BuildInfo )])
958
967
959
968
emptyHookedBuildInfo :: HookedBuildInfo
960
- emptyHookedBuildInfo = (Nothing , [] )
969
+ emptyHookedBuildInfo = ([] , [] )
961
970
962
971
-- | Select options for a particular Haskell compiler.
963
972
hcOptions :: CompilerFlavor -> BuildInfo -> [String ]
@@ -1113,28 +1122,30 @@ lowercase = map Char.toLower
1113
1122
-- ------------------------------------------------------------
1114
1123
1115
1124
updatePackageDescription :: HookedBuildInfo -> PackageDescription -> PackageDescription
1116
- updatePackageDescription (mb_lib_bi , exe_bi) p
1117
- = p{ executables = updateExecutables exe_bi (executables p)
1118
- , library = updateLibrary mb_lib_bi (library p)
1125
+ updatePackageDescription (lib_bi , exe_bi) p
1126
+ = p{ executables = updateMany exeName updateExecutable exe_bi (executables p)
1127
+ , libraries = updateMany libName updateLibrary lib_bi (libraries p)
1119
1128
}
1120
1129
where
1121
- updateLibrary :: Maybe BuildInfo -> Maybe Library -> Maybe Library
1122
- updateLibrary (Just bi) (Just lib) = Just (lib{libBuildInfo = bi `mappend` libBuildInfo lib})
1123
- updateLibrary Nothing mb_lib = mb_lib
1124
- updateLibrary (Just _) Nothing = Nothing
1125
-
1126
- updateExecutables :: [(String , BuildInfo )] -- ^ [(exeName, new buildinfo)]
1127
- -> [Executable ] -- ^ list of executables to update
1128
- -> [Executable ] -- ^ list with exeNames updated
1129
- updateExecutables exe_bi' executables' = foldr updateExecutable executables' exe_bi'
1130
-
1131
- updateExecutable :: (String , BuildInfo ) -- ^ (exeName, new buildinfo)
1132
- -> [Executable ] -- ^ list of executables to update
1133
- -> [Executable ] -- ^ list with exeName updated
1134
- updateExecutable _ [] = []
1135
- updateExecutable exe_bi'@ (name,bi) (exe: exes)
1136
- | exeName exe == name = exe{buildInfo = bi `mappend` buildInfo exe} : exes
1137
- | otherwise = exe : updateExecutable exe_bi' exes
1130
+ updateMany :: (a -> String ) -- ^ @exeName@ or @libName@
1131
+ -> (BuildInfo -> a -> a ) -- ^ @updateExecutable@ or @updateLibrary@
1132
+ -> [(String , BuildInfo )] -- ^ [(name, new buildinfo)]
1133
+ -> [a ] -- ^ list of components to update
1134
+ -> [a ] -- ^ list with updated components
1135
+ updateMany name update hooked_bi' cs' = foldr (updateOne name update) cs' hooked_bi'
1136
+
1137
+ updateOne :: (a -> String ) -- ^ @exeName@ or @libName@
1138
+ -> (BuildInfo -> a -> a ) -- ^ @updateExecutable@ or @updateLibrary@
1139
+ -> (String , BuildInfo ) -- ^ (name, new buildinfo)
1140
+ -> [a ] -- ^ list of compnoents to update
1141
+ -> [a ] -- ^ list with name component updated
1142
+ updateOne _ _ _ [] = []
1143
+ updateOne name_sel update hooked_bi'@ (name,bi) (c: cs)
1144
+ | name_sel c == name = update bi c : cs
1145
+ | otherwise = c : updateOne name_sel update hooked_bi' cs
1146
+
1147
+ updateExecutable bi exe = exe{buildInfo = bi `mappend` buildInfo exe}
1148
+ updateLibrary bi lib = lib{libBuildInfo = bi `mappend` libBuildInfo lib}
1138
1149
1139
1150
-- ---------------------------------------------------------------------------
1140
1151
-- The GenericPackageDescription type
@@ -1143,7 +1154,7 @@ data GenericPackageDescription =
1143
1154
GenericPackageDescription {
1144
1155
packageDescription :: PackageDescription ,
1145
1156
genPackageFlags :: [Flag ],
1146
- condLibrary :: Maybe ( CondTree ConfVar [Dependency ] Library ),
1157
+ condLibraries :: [( String , CondTree ConfVar [Dependency ] Library )] ,
1147
1158
condExecutables :: [(String , CondTree ConfVar [Dependency ] Executable )],
1148
1159
condTestSuites :: [(String , CondTree ConfVar [Dependency ] TestSuite )],
1149
1160
condBenchmarks :: [(String , CondTree ConfVar [Dependency ] Benchmark )]
0 commit comments