Commit 4021ce46 authored by Edward Z. Yang's avatar Edward Z. Yang
Browse files

Fix HookedBuildInfo parsing to support old-style format (needs test.)


Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent 49fca143
......@@ -1136,7 +1136,12 @@ updatePackageDescription (lib_bi, exe_bi) p
-> [a] -- ^list with name component updated
updateOne _ _ _ [] = []
updateOne name_sel update hooked_bi'@(name,bi) (c:cs)
| name_sel c == name = update 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 == "" && name_sel c == display (pkgName (package p)))
= update bi c : cs
| otherwise = c : updateOne name_sel update hooked_bi' cs
updateExecutable bi exe = exe{buildInfo = bi `mappend` buildInfo exe}
......
......@@ -1201,8 +1201,21 @@ deprecField _ = cabalBug "'deprecField' called on a non-field"
parseHookedBuildInfo :: String -> ParseResult HookedBuildInfo
parseHookedBuildInfo inp = do
fields <- readFields inp
foldM parseStanza ([], []) (stanzas fields)
let (mLibFields:rest) = stanzas fields
mLib <- parseLib mLibFields
foldM parseStanza (mLib, []) rest
where
-- For backwards compatibility, if you have a bare stanza,
-- we assume it's part of the public library. We don't
-- know what the name is, so the people using the HookedBuildInfo
-- have to handle this carefully.
parseLib :: [Field] -> ParseResult [(String, BuildInfo)]
parseLib (bi@(F _ inFieldName _:_))
| lowercase inFieldName /= "executable" &&
lowercase inFieldName /= "library"
= liftM (\bis -> [("", bis)]) (parseBI bi)
parseLib _ = return []
parseStanza :: HookedBuildInfo -> [Field] -> ParseResult HookedBuildInfo
parseStanza (lib_bis, exe_bis) (F line inFieldName mName:bi)
| lowercase inFieldName == "executable"
......@@ -1212,7 +1225,9 @@ parseHookedBuildInfo inp = do
= do bis <- parseBI bi
return ((mName, bis):lib_bis, exe_bis)
| otherwise
= syntaxError line "expecting 'executable' or 'library' at top of stanza"
= syntaxError line $
"expecting 'executable' or 'library' at top of stanza, " ++
"but got '" ++ inFieldName ++ "'"
parseStanza _ (_:_) = cabalBug "`parseStanza' called on a non-field"
parseStanza _ [] = syntaxError 0 "error in parsing buildinfo file. Expected stanza"
......
......@@ -421,7 +421,8 @@ sanityCheckHookedBuildInfo pkg_descr (hookLibs, hookExes)
hookExeNames = nub (map fst hookExes)
nonExistantExes = hookExeNames \\ pkgExeNames
pkgLibNames = nub (map libName (libraries pkg_descr))
-- Blank refers to the default, public library
pkgLibNames = "" : nub (map libName (libraries pkg_descr))
hookLibNames = nub (map fst hookLibs)
nonExistantLibs = hookLibNames \\ pkgLibNames
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment