Commit 852dd091 authored by Edward Z. Yang's avatar Edward Z. Yang Committed by GitHub
Browse files

Merge pull request #3580 from ezyang/cabal-convenience-bc

BC fix: libraries -> library/subLibraries (#3574)
parents ad80449b c421cb78
......@@ -32,6 +32,7 @@ module Distribution.PackageDescription (
descCabalVersion,
BuildType(..),
knownBuildTypes,
allLibraries,
-- ** Renaming
ModuleRenaming(..),
......@@ -125,7 +126,7 @@ import Distribution.Text
import Language.Haskell.Extension
import Data.Data (Data)
import Data.List (nub, intercalate)
import Data.List (nub, intercalate, find)
import Data.Maybe (fromMaybe, maybeToList)
import Data.Foldable as Fold (Foldable(foldMap))
import Data.Traversable as Trav (Traversable(traverse))
......@@ -189,7 +190,8 @@ data PackageDescription
buildType :: Maybe BuildType,
setupBuildInfo :: Maybe SetupBuildInfo,
-- components
libraries :: [Library],
library :: Maybe Library,
subLibraries :: [Library],
executables :: [Executable],
testSuites :: [TestSuite],
benchmarks :: [Benchmark],
......@@ -256,7 +258,8 @@ emptyPackageDescription
category = "",
customFieldsPD = [],
setupBuildInfo = Nothing,
libraries = [],
library = Nothing,
subLibraries = [],
executables = [],
testSuites = [],
benchmarks = [],
......@@ -393,7 +396,7 @@ instance Text ModuleRenaming where
-- The Library type
data Library = Library {
libName :: String,
libName :: Maybe String,
exposedModules :: [ModuleName],
reexportedModules :: [ModuleReexport],
requiredSignatures:: [ModuleName], -- ^ What sigs need implementations?
......@@ -417,7 +420,7 @@ instance Monoid Library where
instance Semigroup Library where
a <> b = Library {
libName = combine' libName,
libName = combine libName,
exposedModules = combine exposedModules,
reexportedModules = combine reexportedModules,
requiredSignatures = combine requiredSignatures,
......@@ -425,25 +428,23 @@ instance Semigroup Library where
libBuildInfo = combine libBuildInfo
}
where combine field = field a `mappend` field b
combine' field = case (field a, field b) of
("","") -> ""
("", x) -> x
(x, "") -> x
(x, y) -> error $ "Ambiguous values for library field: '"
++ x ++ "' and '" ++ y ++ "'"
emptyLibrary :: Library
emptyLibrary = mempty
-- | Does this package have a PUBLIC library?
-- | Does this package have a buildable PUBLIC library?
hasPublicLib :: PackageDescription -> Bool
hasPublicLib p = any f (libraries p)
where f lib = buildable (libBuildInfo lib) &&
libName lib == display (packageName (package p))
hasPublicLib p =
case library p of
Just lib -> buildable (libBuildInfo lib)
Nothing -> False
-- | Does this package have any libraries?
hasLibs :: PackageDescription -> Bool
hasLibs p = any (buildable . libBuildInfo) (libraries p)
hasLibs p = any (buildable . libBuildInfo) (allLibraries p)
allLibraries :: PackageDescription -> [Library]
allLibraries p = maybeToList (library p) ++ subLibraries p
-- | If the package description has a buildable library section,
-- call the given function with the library build info as argument.
......@@ -453,7 +454,7 @@ hasLibs p = any (buildable . libBuildInfo) (libraries p)
-- for more information.
withLib :: PackageDescription -> (Library -> IO ()) -> IO ()
withLib pkg_descr f =
sequence_ [f lib | lib <- libraries pkg_descr, buildable (libBuildInfo lib)]
sequence_ [f lib | lib <- allLibraries pkg_descr, buildable (libBuildInfo lib)]
-- | Get all the module names from the library (exposed and internal modules)
-- which need to be compiled. (This does not include reexports, which
......@@ -920,7 +921,7 @@ emptyBuildInfo = mempty
-- all buildable executables, test suites and benchmarks. Useful for gathering
-- dependencies.
allBuildInfo :: PackageDescription -> [BuildInfo]
allBuildInfo pkg_descr = [ bi | lib <- libraries pkg_descr
allBuildInfo pkg_descr = [ bi | lib <- allLibraries pkg_descr
, let bi = libBuildInfo lib
, buildable bi ]
++ [ bi | exe <- executables pkg_descr
......@@ -954,7 +955,8 @@ usedExtensions bi = oldExtensions bi
++ defaultExtensions bi
-- Libraries live in a separate namespace, so must distinguish
data ComponentName = CLibName String
data ComponentName = CLibName
| CSubLibName String
| CExeName String
| CTestName String
| CBenchName String
......@@ -964,13 +966,17 @@ instance Binary ComponentName
-- Build-target-ish syntax
instance Text ComponentName where
disp (CLibName str) = Disp.text ("lib:" ++ str)
disp CLibName = Disp.text "lib"
disp (CSubLibName str) = Disp.text ("lib:" ++ str)
disp (CExeName str) = Disp.text ("exe:" ++ str)
disp (CTestName str) = Disp.text ("test:" ++ str)
disp (CBenchName str) = Disp.text ("bench:" ++ str)
parse = do
ctor <- Parse.choice [ Parse.string "lib:" >> return CLibName
parse = parseComposite <++ parseSingle
where
parseSingle = Parse.string "lib" >> return CLibName
parseComposite = do
ctor <- Parse.choice [ Parse.string "lib:" >> return CSubLibName
, Parse.string "exe:" >> return CExeName
, Parse.string "bench:" >> return CBenchName
, Parse.string "test:" >> return CTestName ]
......@@ -979,8 +985,8 @@ instance Text ComponentName where
-- as package names.)
fmap (ctor . unPackageName) parse
defaultLibName :: PackageIdentifier -> ComponentName
defaultLibName pid = CLibName (display (pkgName pid))
defaultLibName :: ComponentName
defaultLibName = CLibName
type HookedBuildInfo = [(ComponentName, BuildInfo)]
......@@ -1143,11 +1149,16 @@ lowercase = map Char.toLower
updatePackageDescription :: HookedBuildInfo -> PackageDescription -> PackageDescription
updatePackageDescription hooked_bis p
= p{ executables = updateMany (CExeName . exeName) updateExecutable (executables p)
, libraries = updateMany (CLibName . libName) updateLibrary (libraries p)
, library = fmap (updateLibrary lib_bi) (library p)
, subLibraries = updateMany (maybe CLibName CSubLibName . libName) updateLibrary (subLibraries p)
, benchmarks = updateMany (CBenchName . benchmarkName) updateBenchmark (benchmarks p)
, testSuites = updateMany (CTestName . testName) updateTestSuite (testSuites p)
}
where
lib_bi = case find ((== CLibName) . fst) hooked_bis of
Nothing -> mempty
Just (_, bi) -> bi
updateMany :: (a -> ComponentName) -- ^ get 'ComponentName' from @a@
-> (BuildInfo -> a -> a) -- ^ @updateExecutable@, @updateLibrary@, etc
-> [a] -- ^list of components to update
......@@ -1161,11 +1172,7 @@ updatePackageDescription hooked_bis p
-> [a] -- ^list with name component updated
updateOne _ _ _ [] = []
updateOne name_sel update hooked_bi'@(name,bi) (c:cs)
| name_sel c == name ||
-- Special case: an empty name means "please update the BuildInfo for
-- the public library, i.e. the one with the same name as the
-- package." See 'parseHookedBuildInfo'.
name == CLibName "" && name_sel c == defaultLibName (package p)
| name_sel c == name
= update bi c : cs
| otherwise = c : updateOne name_sel update hooked_bi' cs
......@@ -1181,7 +1188,8 @@ data GenericPackageDescription =
GenericPackageDescription {
packageDescription :: PackageDescription,
genPackageFlags :: [Flag],
condLibraries :: [(String, CondTree ConfVar [Dependency] Library)],
condLibrary :: Maybe (CondTree ConfVar [Dependency] Library),
condSubLibraries :: [(String, CondTree ConfVar [Dependency] Library)],
condExecutables :: [(String, CondTree ConfVar [Dependency] Executable)],
condTestSuites :: [(String, CondTree ConfVar [Dependency] TestSuite)],
condBenchmarks :: [(String, CondTree ConfVar [Dependency] Benchmark)]
......
......@@ -47,7 +47,7 @@ import Distribution.Simple.LocalBuildInfo hiding (compiler)
import Language.Haskell.Extension
import Data.Maybe
( isNothing, isJust, catMaybes, mapMaybe, fromMaybe )
( isNothing, isJust, catMaybes, mapMaybe, fromMaybe, maybeToList )
import Data.List (sort, group, isPrefixOf, nub, find)
import Control.Monad
( filterM, liftM )
......@@ -174,7 +174,7 @@ checkSanity pkg =
, check (all ($ pkg) [ null . executables
, null . testSuites
, null . benchmarks
, null . libraries ]) $
, null . allLibraries ]) $
PackageBuildImpossible
"No executables, libraries, tests, or benchmarks found. Nothing to do."
......@@ -182,11 +182,18 @@ checkSanity pkg =
PackageBuildImpossible $ "Duplicate sections: " ++ commaSep duplicateNames
++ ". The name of every library, executable, test suite, and benchmark section in"
++ " the package must be unique."
-- NB: but it's OK for executables to have the same name!
, check (any (== display (packageName pkg)) subLibNames) $
PackageBuildImpossible $ "Illegal internal library name " ++ display (packageName pkg)
++ ". Internal libraries cannot have the same name as the package. Maybe"
++ " you wanted a non-internal library? If so, rewrite the section stanza"
++ " from 'library: '" ++ display (packageName pkg) ++ "' to 'library'."
]
--TODO: check for name clashes case insensitively: windows file systems cannot
--cope.
++ concatMap (checkLibrary pkg) (libraries pkg)
++ concatMap (checkLibrary pkg) (allLibraries pkg)
++ concatMap (checkExecutable pkg) (executables pkg)
++ concatMap (checkTestSuite pkg) (testSuites pkg)
++ concatMap (checkBenchmark pkg) (benchmarks pkg)
......@@ -200,15 +207,14 @@ checkSanity pkg =
++ "tool only supports up to version " ++ display cabalVersion ++ "."
]
where
-- The public library gets special dispensation, because it
-- The public 'library' gets special dispensation, because it
-- is common practice to export a library and name the executable
-- the same as the package. We always put the public library
-- in the top-level directory in dist, so no conflicts either.
libNames = filter (/= unPackageName (packageName pkg)) . map libName $ libraries pkg
-- the same as the package.
subLibNames = catMaybes . map libName $ subLibraries pkg
exeNames = map exeName $ executables pkg
testNames = map testName $ testSuites pkg
bmNames = map benchmarkName $ benchmarks pkg
duplicateNames = dups $ libNames ++ exeNames ++ testNames ++ bmNames
duplicateNames = dups $ subLibNames ++ exeNames ++ testNames ++ bmNames
checkLibrary :: PackageDescription -> Library -> [PackageCheck]
checkLibrary pkg lib =
......@@ -221,7 +227,10 @@ checkLibrary pkg lib =
, check (null (libModules lib) && null (reexportedModules lib)) $
PackageDistSuspiciousWarn $
"Library " ++ libName lib ++ " does not expose any modules"
"Library " ++ (case libName lib of
Nothing -> ""
Just n -> n
) ++ "does not expose any modules"
-- check use of required-signatures/exposed-signatures sections
, checkVersion [1,21] (not (null (requiredSignatures lib))) $
......@@ -691,7 +700,7 @@ checkGhcOptions pkg =
where
all_ghc_options = concatMap get_ghc_options (allBuildInfo pkg)
lib_ghc_options = concatMap (get_ghc_options . libBuildInfo) (libraries pkg)
lib_ghc_options = concatMap (get_ghc_options . libBuildInfo) (allLibraries pkg)
get_ghc_options bi = hcOptions GHC bi ++ hcProfOptions GHC bi
++ hcSharedOptions GHC bi
......@@ -915,17 +924,14 @@ checkCabalVersion pkg =
++ "'other-languages' field."
, checkVersion [1,23]
(case libraries pkg of
[lib] -> libName lib /= unPackageName (packageName pkg)
[] -> False
_ -> True) $
(not (null (subLibraries pkg))) $
PackageDistInexcusable $
"To use multiple 'library' sections or a named library section "
++ "the package needs to specify at least 'cabal-version >= 1.23'."
-- check use of reexported-modules sections
, checkVersion [1,21]
(any (not.null.reexportedModules) (libraries pkg)) $
(any (not.null.reexportedModules) (allLibraries pkg)) $
PackageDistInexcusable $
"To use the 'reexported-module' field the package needs to specify "
++ "at least 'cabal-version: >= 1.21'."
......@@ -1331,8 +1337,11 @@ checkConditionals pkg =
unknownOSs = [ os | OS (OtherOS os) <- conditions ]
unknownArches = [ arch | Arch (OtherArch arch) <- conditions ]
unknownImpls = [ impl | Impl (OtherCompiler impl) _ <- conditions ]
conditions = concatMap (fvs . snd) (condLibraries pkg)
conditions = concatMap fvs (maybeToList (condLibrary pkg))
++ concatMap (fvs . snd) (condSubLibraries pkg)
++ concatMap (fvs . snd) (condExecutables pkg)
++ concatMap (fvs . snd) (condTestSuites pkg)
++ concatMap (fvs . snd) (condBenchmarks pkg)
fvs (CondNode _ _ ifs) = concatMap compfv ifs -- free variables
compfv (c, ct, mct) = condfv c ++ fvs ct ++ maybe [] fvs mct
condfv c = case c of
......@@ -1435,8 +1444,11 @@ checkDevelopmentOnlyFlags pkg =
allConditionalBuildInfo :: [([Condition ConfVar], BuildInfo)]
allConditionalBuildInfo =
concatMap (collectCondTreePaths libBuildInfo . snd)
(condLibraries pkg)
concatMap (collectCondTreePaths libBuildInfo)
(maybeToList (condLibrary pkg))
++ concatMap (collectCondTreePaths libBuildInfo . snd)
(condSubLibraries pkg)
++ concatMap (collectCondTreePaths buildInfo . snd)
(condExecutables pkg)
......
......@@ -282,7 +282,8 @@ resolveWithFlags dom enabled os arch impl constrs trees checkDeps =
env flags flag = (maybe (Left flag) Right . lookup flag) flags
pdTaggedBuildInfo :: PDTagged -> BuildInfo
pdTaggedBuildInfo (Lib _ l) = libBuildInfo l
pdTaggedBuildInfo (Lib l) = libBuildInfo l
pdTaggedBuildInfo (SubLib _ l) = libBuildInfo l
pdTaggedBuildInfo (Exe _ e) = buildInfo e
pdTaggedBuildInfo (Test _ t) = testBuildInfo t
pdTaggedBuildInfo (Bench _ b) = benchmarkBuildInfo b
......@@ -339,7 +340,8 @@ extractConditions :: (BuildInfo -> Bool) -> GenericPackageDescription
-> [Condition ConfVar]
extractConditions f gpkg =
concat [
extractCondition (f . libBuildInfo) . snd <$> condLibraries gpkg
extractCondition (f . libBuildInfo) <$> maybeToList (condLibrary gpkg)
, extractCondition (f . libBuildInfo) . snd <$> condSubLibraries gpkg
, extractCondition (f . buildInfo) . snd <$> condExecutables gpkg
, extractCondition (f . testBuildInfo) . snd <$> condTestSuites gpkg
, extractCondition (f . benchmarkBuildInfo) . snd <$> condBenchmarks gpkg
......@@ -424,7 +426,8 @@ overallDependencies enabled (TargetSet targets) = mconcat depss
where
(depss, _) = unzip $ filter (removeDisabledSections . snd) targets
removeDisabledSections :: PDTagged -> Bool
removeDisabledSections (Lib _ l) = componentEnabled enabled (CLib l)
removeDisabledSections (Lib l) = componentEnabled enabled (CLib l)
removeDisabledSections (SubLib _ l) = componentEnabled enabled (CLib l)
removeDisabledSections (Exe _ e) = componentEnabled enabled (CExe e)
removeDisabledSections (Test _ t) = componentEnabled enabled (CTest t)
removeDisabledSections (Bench _ b) = componentEnabled enabled (CBench b)
......@@ -449,53 +452,61 @@ constrainBy left extra =
-- | Collect up the targets in a TargetSet of tagged targets, storing the
-- dependencies as we go.
flattenTaggedTargets :: TargetSet PDTagged ->
([(String, Library)], [(String, Executable)], [(String, TestSuite)]
(Maybe Library
, [(String, Library)], [(String, Executable)], [(String, TestSuite)]
, [(String, Benchmark)])
flattenTaggedTargets (TargetSet targets) = foldr untag ([], [], [], []) targets
flattenTaggedTargets (TargetSet targets) = foldr untag (Nothing, [], [], [], []) targets
where
untag (deps, Lib n l) (libs, exes, tests, bms)
untag (_, Lib _) (Just _, _, _, _, _) = userBug "Only one library expected"
untag (deps, Lib l) (Nothing, libs, exes, tests, bms) =
(Just l', libs, exes, tests, bms)
where
l' = l {
libBuildInfo = (libBuildInfo l) { targetBuildDepends = fromDepMap deps }
}
untag (deps, SubLib n l) (mb_lib, libs, exes, tests, bms)
| any ((== n) . fst) libs =
userBug $ "There exist several libs with the same name: '" ++ n ++ "'"
-- NB: libraries live in a different namespace than everything else
-- TODO: no, (new-style) TESTS live in same namespace!!
| otherwise = ((n, l'):libs, exes, tests, bms)
| otherwise = (mb_lib, (n, l'):libs, exes, tests, bms)
where
l' = l {
libBuildInfo = (libBuildInfo l) { targetBuildDepends = fromDepMap deps }
}
untag (deps, Exe n e) (libs, exes, tests, bms)
untag (deps, Exe n e) (mb_lib, libs, exes, tests, bms)
| any ((== n) . fst) exes =
userBug $ "There exist several exes with the same name: '" ++ n ++ "'"
| any ((== n) . fst) tests =
userBug $ "There exists a test with the same name as an exe: '" ++ n ++ "'"
| any ((== n) . fst) bms =
userBug $ "There exists a benchmark with the same name as an exe: '" ++ n ++ "'"
| otherwise = (libs, (n, e'):exes, tests, bms)
| otherwise = (mb_lib, libs, (n, e'):exes, tests, bms)
where
e' = e {
buildInfo = (buildInfo e) { targetBuildDepends = fromDepMap deps }
}
untag (deps, Test n t) (libs, exes, tests, bms)
untag (deps, Test n t) (mb_lib, libs, exes, tests, bms)
| any ((== n) . fst) tests =
userBug $ "There exist several tests with the same name: '" ++ n ++ "'"
| any ((== n) . fst) exes =
userBug $ "There exists an exe with the same name as the test: '" ++ n ++ "'"
| any ((== n) . fst) bms =
userBug $ "There exists a benchmark with the same name as the test: '" ++ n ++ "'"
| otherwise = (libs, exes, (n, t'):tests, bms)
| otherwise = (mb_lib, libs, exes, (n, t'):tests, bms)
where
t' = t {
testBuildInfo = (testBuildInfo t)
{ targetBuildDepends = fromDepMap deps }
}
untag (deps, Bench n b) (libs, exes, tests, bms)
untag (deps, Bench n b) (mb_lib, libs, exes, tests, bms)
| any ((== n) . fst) bms =
userBug $ "There exist several benchmarks with the same name: '" ++ n ++ "'"
| any ((== n) . fst) exes =
userBug $ "There exists an exe with the same name as the benchmark: '" ++ n ++ "'"
| any ((== n) . fst) tests =
userBug $ "There exists a test with the same name as the benchmark: '" ++ n ++ "'"
| otherwise = (libs, exes, tests, (n, b'):bms)
| otherwise = (mb_lib, libs, exes, tests, (n, b'):bms)
where
b' = b {
benchmarkBuildInfo = (benchmarkBuildInfo b)
......@@ -509,10 +520,10 @@ flattenTaggedTargets (TargetSet targets) = foldr untag ([], [], [], []) targets
--
-- ezyang: Arguably, this should be:
-- data PDTagged = PDComp String Component
-- data PDTagged = PDComp Component
-- | PDNull
-- Also, what the heck is the String? The componentName?
data PDTagged = Lib String Library
data PDTagged = Lib Library
| SubLib String Library
| Exe String Executable
| Test String TestSuite
| Bench String Benchmark
......@@ -526,7 +537,8 @@ instance Monoid PDTagged where
instance Semigroup PDTagged where
PDNull <> x = x
x <> PDNull = x
Lib n l <> Lib n' l' | n == n' = Lib n (l <> l')
Lib l <> Lib l' = Lib (l <> l')
SubLib n l <> SubLib n' l' | n == n' = SubLib n (l <> l')
Exe n e <> Exe n' e' | n == n' = Exe n (e <> e')
Test n t <> Test n' t' | n == n' = Test n (t <> t')
Bench n b <> Bench n' b' | n == n' = Bench n (b <> b')
......@@ -570,10 +582,11 @@ finalizePD ::
-- description along with the flag assignments chosen.
finalizePD userflags enabled satisfyDep
(Platform arch os) impl constraints
(GenericPackageDescription pkg flags libs0 exes0 tests0 bms0) =
(GenericPackageDescription pkg flags mb_lib0 sub_libs0 exes0 tests0 bms0) =
case resolveFlags of
Right ((libs', exes', tests', bms'), targetSet, flagVals) ->
Right ( pkg { libraries = libs'
Right ((mb_lib', sub_libs', exes', tests', bms'), targetSet, flagVals) ->
Right ( pkg { library = mb_lib'
, subLibraries = sub_libs'
, executables = exes'
, testSuites = tests'
, benchmarks = bms'
......@@ -584,7 +597,8 @@ finalizePD userflags enabled satisfyDep
Left missing -> Left missing
where
-- Combine lib, exes, and tests into one list of @CondTree@s with tagged data
condTrees = map (\(name,tree) -> mapTreeData (Lib name) tree) libs0
condTrees = maybeToList (fmap (mapTreeData Lib) mb_lib0)
++ map (\(name,tree) -> mapTreeData (SubLib name) tree) sub_libs0
++ map (\(name,tree) -> mapTreeData (Exe name) tree) exes0
++ map (\(name,tree) -> mapTreeData (Test name) tree) tests0
++ map (\(name,tree) -> mapTreeData (Bench name) tree) bms0
......@@ -592,8 +606,9 @@ finalizePD userflags enabled satisfyDep
resolveFlags =
case resolveWithFlags flagChoices enabled os arch impl constraints condTrees check of
Right (targetSet, fs) ->
let (libs, exes, tests, bms) = flattenTaggedTargets targetSet in
Right ( (map (\(n,l) -> (libFillInDefaults l) { libName = n }) libs,
let (mb_lib, sub_libs, exes, tests, bms) = flattenTaggedTargets targetSet in
Right ( (fmap (\l -> (libFillInDefaults l) { libName = Nothing }) mb_lib,
map (\(n,l) -> (libFillInDefaults l) { libName = Just n }) sub_libs,
map (\(n,e) -> (exeFillInDefaults e) { exeName = n }) exes,
map (\(n,t) -> (testFillInDefaults t) { testName = n }) tests,
map (\(n,b) -> (benchFillInDefaults b) { benchmarkName = n }) bms),
......@@ -650,21 +665,26 @@ resolveWithFlags [] Distribution.System.Linux Distribution.System.I386 (Distribu
-- default path will be missing from the package description returned by this
-- function.
flattenPackageDescription :: GenericPackageDescription -> PackageDescription
flattenPackageDescription (GenericPackageDescription pkg _ libs0 exes0 tests0 bms0) =
pkg { libraries = reverse libs
flattenPackageDescription (GenericPackageDescription pkg _ mlib0 sub_libs0 exes0 tests0 bms0) =
pkg { library = mlib
, subLibraries = reverse sub_libs
, executables = reverse exes
, testSuites = reverse tests
, benchmarks = reverse bms
, buildDepends = reverse ldeps ++ reverse edeps ++ reverse tdeps ++ reverse bdeps
, buildDepends = ldeps ++ reverse sub_ldeps ++ reverse edeps ++ reverse tdeps ++ reverse bdeps
}
where
(libs, ldeps) = foldr flattenLib ([],[]) libs0
(mlib, ldeps) = case mlib0 of
Just lib -> let (l,ds) = ignoreConditions lib in
(Just ((libFillInDefaults l) { libName = Nothing }), ds)
Nothing -> (Nothing, [])
(sub_libs, sub_ldeps) = foldr flattenLib ([],[]) sub_libs0
(exes, edeps) = foldr flattenExe ([],[]) exes0
(tests, tdeps) = foldr flattenTst ([],[]) tests0
(bms, bdeps) = foldr flattenBm ([],[]) bms0
flattenLib (n, t) (es, ds) =
let (e, ds') = ignoreConditions t in
( (libFillInDefaults $ e { libName = n }) : es, ds' ++ ds )
( (libFillInDefaults $ e { libName = Just n }) : es, ds' ++ ds )
flattenExe (n, t) (es, ds) =
let (e, ds') = ignoreConditions t in
( (exeFillInDefaults $ e { exeName = n }) : es, ds' ++ ds )
......@@ -720,7 +740,8 @@ transformAllBuildInfos onBuildInfo onSetupBuildInfo gpd = gpd'
pd = packageDescription gpd
pd' = pd {
libraries = map onLibrary (libraries pd),
library = fmap onLibrary (library pd),
subLibraries = map onLibrary (subLibraries pd),
executables = map onExecutable (executables pd),
testSuites = map onTestSuite (testSuites pd),
benchmarks = map onBenchmark (benchmarks pd),
......@@ -760,18 +781,21 @@ transformAllCondTrees onLibrary onExecutable
onTestSuite onBenchmark onDepends gpd = gpd'
where
gpd' = gpd {
condLibraries = condLibs',
condLibrary = condLib',
condSubLibraries = condSubLibs',
condExecutables = condExes',
condTestSuites = condTests',
condBenchmarks = condBenchs'
}
condLibs = condLibraries gpd
condLib = condLibrary gpd
condSubLibs = condSubLibraries gpd
condExes = condExecutables gpd
condTests = condTestSuites gpd
condBenchs = condBenchmarks gpd
condLibs' = map (mapSnd $ onCondTree onLibrary) condLibs
condLib' = fmap (onCondTree onLibrary) condLib
condSubLibs' = map (mapSnd $ onCondTree onLibrary) condSubLibs
condExes' = map (mapSnd $ onCondTree onExecutable) condExes
condTests' = map (mapSnd $ onCondTree onTestSuite) condTests
condBenchs' = map (mapSnd $ onCondTree onBenchmark) condBenchs
......
......@@ -56,7 +56,7 @@ import Distribution.Text
import Distribution.Compat.ReadP hiding (get)
import Data.Char (isSpace)
import Data.Maybe (listToMaybe, isJust)
import Data.Maybe (listToMaybe, isJust, maybeToList)
import Data.List (nub, unfoldr, partition, (\\))
import Control.Monad (liftM, foldM, when, unless, ap)
#if __GLASGOW_HASKELL__ < 710
......@@ -738,14 +738,14 @@ parsePackageDescription file = do
-- 'getBody' assumes that the remaining fields only consist of
-- flags, lib and exe sections.
(repos, flags, mcsetup, libs, exes, tests, bms) <- getBody pkg
(repos, flags, mcsetup, mlib, sub_libs, exes, tests, bms) <- getBody pkg
warnIfRest -- warn if getBody did not parse up to the last field.
-- warn about using old/new syntax with wrong cabal-version:
maybeWarnCabalVersion (not $ oldSyntax fields0) pkg
checkForUndefinedFlags flags libs exes tests
checkForUndefinedFlags flags mlib sub_libs exes tests
return $ GenericPackageDescription
pkg { sourceRepos = repos, setupBuildInfo = mcsetup }
flags libs exes tests bms
flags mlib sub_libs exes tests bms
where
oldSyntax = all isSimpleField
......@@ -852,6 +852,7 @@ parsePackageDescription file = do
getBody :: PackageDescription
-> PM ([SourceRepo], [Flag]
,Maybe SetupBuildInfo
,(Maybe (CondTree ConfVar [Dependency] Library))
,[(String, CondTree ConfVar [Dependency] Library)]
,[(String, CondTree ConfVar [Dependency] Executable)]
,[(String, CondTree ConfVar [Dependency] TestSuite)]
......@@ -864,8 +865,8 @@ parsePackageDescription file = do
exename <- lift $ runP line_no "executable" parseTokenQ sec_label
flds <- collectFields parseExeFields sec_fields
skipField
(repos, flags, csetup, lib, exes, tests, bms) <- getBody pkg
return (repos, flags, csetup, lib, (exename, flds): exes, tests, bms)
(repos, flags, csetup, mlib, sub_libs, exes, tests, bms) <- getBody pkg
return (repos, flags, csetup, mlib, sub_libs, (exename, flds): exes, tests, bms)
| sec_type == "test-suite" -> do
when (null sec_label) $ lift $ syntaxError line_no
......@@ -905,8 +906,8 @@ parsePackageDescription file = do
if checkTestType emptyTestSuite flds
then do
skipField