@@ -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 = [] ,
@@ -387,6 +387,7 @@ instance Text ModuleRenaming where
387
387
-- The Library type
388
388
389
389
data Library = Library {
390
+ libName :: String ,
390
391
exposedModules :: [ModuleName ],
391
392
reexportedModules :: [ModuleReexport ],
392
393
requiredSignatures :: [ModuleName ], -- ^ What sigs need implementations?
@@ -400,6 +401,7 @@ instance Binary Library
400
401
401
402
instance Monoid Library where
402
403
mempty = Library {
404
+ libName = mempty ,
403
405
exposedModules = mempty ,
404
406
reexportedModules = mempty ,
405
407
requiredSignatures = mempty ,
@@ -411,6 +413,7 @@ instance Monoid Library where
411
413
412
414
instance Semigroup Library where
413
415
a <> b = Library {
416
+ libName = combine' libName,
414
417
exposedModules = combine exposedModules,
415
418
reexportedModules = combine reexportedModules,
416
419
requiredSignatures = combine requiredSignatures,
@@ -419,20 +422,26 @@ instance Semigroup Library where
419
422
libBuildInfo = combine libBuildInfo
420
423
}
421
424
where combine field = field a `mappend` field b
425
+ combine' field = case (field a, field b) of
426
+ (" " ," " ) -> " "
427
+ (" " , x) -> x
428
+ (x, " " ) -> x
429
+ (x, y) -> error $ " Ambiguous values for library field: '"
430
+ ++ x ++ " ' and '" ++ y ++ " '"
422
431
423
432
emptyLibrary :: Library
424
433
emptyLibrary = mempty
425
434
426
435
-- | does this package have any libraries?
427
436
hasLibs :: PackageDescription -> Bool
428
- hasLibs p = maybe False (buildable . libBuildInfo) (library p)
437
+ hasLibs p = any (buildable . libBuildInfo) (libraries p)
429
438
430
439
-- | 'Maybe' version of 'hasLibs'
431
- maybeHasLibs :: PackageDescription -> Maybe Library
440
+ maybeHasLibs :: PackageDescription -> [ Library ]
432
441
maybeHasLibs p =
433
- library p >>= \ lib -> if buildable (libBuildInfo lib)
434
- then Just lib
435
- else Nothing
442
+ libraries p >>= \ lib -> if buildable (libBuildInfo lib)
443
+ then return lib
444
+ else []
436
445
437
446
-- | If the package description has a library section, call the given
438
447
-- function with the library build info as argument.
@@ -915,7 +924,7 @@ emptyBuildInfo = mempty
915
924
-- all buildable executables, test suites and benchmarks. Useful for gathering
916
925
-- dependencies.
917
926
allBuildInfo :: PackageDescription -> [BuildInfo ]
918
- allBuildInfo pkg_descr = [ bi | Just lib <- [library pkg_descr]
927
+ allBuildInfo pkg_descr = [ bi | lib <- libraries pkg_descr
919
928
, let bi = libBuildInfo lib
920
929
, buildable bi ]
921
930
++ [ bi | exe <- executables pkg_descr
@@ -950,10 +959,10 @@ usedExtensions :: BuildInfo -> [Extension]
950
959
usedExtensions bi = oldExtensions bi
951
960
++ defaultExtensions bi
952
961
953
- type HookedBuildInfo = (Maybe BuildInfo , [(String , BuildInfo )])
962
+ type HookedBuildInfo = ([( String , BuildInfo )] , [(String , BuildInfo )])
954
963
955
964
emptyHookedBuildInfo :: HookedBuildInfo
956
- emptyHookedBuildInfo = (Nothing , [] )
965
+ emptyHookedBuildInfo = ([] , [] )
957
966
958
967
-- | Select options for a particular Haskell compiler.
959
968
hcOptions :: CompilerFlavor -> BuildInfo -> [String ]
@@ -1109,28 +1118,30 @@ lowercase = map Char.toLower
1109
1118
-- ------------------------------------------------------------
1110
1119
1111
1120
updatePackageDescription :: HookedBuildInfo -> PackageDescription -> PackageDescription
1112
- updatePackageDescription (mb_lib_bi , exe_bi) p
1113
- = p{ executables = updateExecutables exe_bi (executables p)
1114
- , library = updateLibrary mb_lib_bi (library p)
1121
+ updatePackageDescription (lib_bi , exe_bi) p
1122
+ = p{ executables = updateMany exeName updateExecutable exe_bi (executables p)
1123
+ , libraries = updateMany libName updateLibrary lib_bi (libraries p)
1115
1124
}
1116
1125
where
1117
- updateLibrary :: Maybe BuildInfo -> Maybe Library -> Maybe Library
1118
- updateLibrary (Just bi) (Just lib) = Just (lib{libBuildInfo = bi `mappend` libBuildInfo lib})
1119
- updateLibrary Nothing mb_lib = mb_lib
1120
- updateLibrary (Just _) Nothing = Nothing
1121
-
1122
- updateExecutables :: [(String , BuildInfo )] -- ^ [(exeName, new buildinfo)]
1123
- -> [Executable ] -- ^ list of executables to update
1124
- -> [Executable ] -- ^ list with exeNames updated
1125
- updateExecutables exe_bi' executables' = foldr updateExecutable executables' exe_bi'
1126
-
1127
- updateExecutable :: (String , BuildInfo ) -- ^ (exeName, new buildinfo)
1128
- -> [Executable ] -- ^ list of executables to update
1129
- -> [Executable ] -- ^ list with exeName updated
1130
- updateExecutable _ [] = []
1131
- updateExecutable exe_bi'@ (name,bi) (exe: exes)
1132
- | exeName exe == name = exe{buildInfo = bi `mappend` buildInfo exe} : exes
1133
- | otherwise = exe : updateExecutable exe_bi' exes
1126
+ updateMany :: (a -> String ) -- ^ @exeName@ or @libName@
1127
+ -> (BuildInfo -> a -> a ) -- ^ @updateExecutable@ or @updateLibrary@
1128
+ -> [(String , BuildInfo )] -- ^ [(name, new buildinfo)]
1129
+ -> [a ] -- ^ list of components to update
1130
+ -> [a ] -- ^ list with updated components
1131
+ updateMany name update hooked_bi' cs' = foldr (updateOne name update) cs' hooked_bi'
1132
+
1133
+ updateOne :: (a -> String ) -- ^ @exeName@ or @libName@
1134
+ -> (BuildInfo -> a -> a ) -- ^ @updateExecutable@ or @updateLibrary@
1135
+ -> (String , BuildInfo ) -- ^ (name, new buildinfo)
1136
+ -> [a ] -- ^ list of compnoents to update
1137
+ -> [a ] -- ^ list with name component updated
1138
+ updateOne _ _ _ [] = []
1139
+ updateOne name_sel update hooked_bi'@ (name,bi) (c: cs)
1140
+ | name_sel c == name = update bi c : cs
1141
+ | otherwise = c : updateOne name_sel update hooked_bi' cs
1142
+
1143
+ updateExecutable bi exe = exe{buildInfo = bi `mappend` buildInfo exe}
1144
+ updateLibrary bi lib = lib{libBuildInfo = bi `mappend` libBuildInfo lib}
1134
1145
1135
1146
-- ---------------------------------------------------------------------------
1136
1147
-- The GenericPackageDescription type
@@ -1139,7 +1150,7 @@ data GenericPackageDescription =
1139
1150
GenericPackageDescription {
1140
1151
packageDescription :: PackageDescription ,
1141
1152
genPackageFlags :: [Flag ],
1142
- condLibrary :: Maybe ( CondTree ConfVar [Dependency ] Library ),
1153
+ condLibraries :: [( String , CondTree ConfVar [Dependency ] Library )] ,
1143
1154
condExecutables :: [(String , CondTree ConfVar [Dependency ] Executable )],
1144
1155
condTestSuites :: [(String , CondTree ConfVar [Dependency ] TestSuite )],
1145
1156
condBenchmarks :: [(String , CondTree ConfVar [Dependency ] Benchmark )]
0 commit comments