X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=distrib%2Fcompare%2FFilenameDescr.hs;fp=distrib%2Fcompare%2FFilenameDescr.hs;h=4b5898e990c441bb9e9a43d141032efabfcdea3c;hp=5952058639427702972cb06cb7ebcbb4cf12897c;hb=42b40db07ce70b89f867247809c4e930fd82a6f6;hpb=3ce328c715c8ae97325d21216a4dd51050876c62 diff --git a/distrib/compare/FilenameDescr.hs b/distrib/compare/FilenameDescr.hs index 5952058..4b5898e 100644 --- a/distrib/compare/FilenameDescr.hs +++ b/distrib/compare/FilenameDescr.hs @@ -2,7 +2,9 @@ module FilenameDescr where import Data.Either +import Data.List +import BuildInfo import Utils import Tar @@ -12,6 +14,7 @@ import Tar type FilenameDescr = [FilenameDescrBit] data FilenameDescrBit = VersionOf String | FP String + | Ways deriving (Show, Eq, Ord) normalise :: FilenameDescr -> FilenameDescr @@ -20,24 +23,11 @@ normalise [x] = [x] normalise (FP x1 : FP x2 : xs) = normalise (FP (x1 ++ x2) : xs) normalise (x : xs) = x : normalise xs --- Mapping from thing (e.g. "Cabal") to version (e.g. "1.10.0.0") -type ThingVersionMap = [(String, String)] - -addThingVersion :: ThingVersionMap -> String -> String -> Maybe ThingVersionMap -addThingVersion mapping thing version - = case lookup thing mapping of - Just version' -> - if version == version' - then Just mapping - else Nothing - Nothing -> - Just ((thing, version) : mapping) - -- Sanity check that the FilenameDescr matches the filename in the tar line -checkContent :: ThingVersionMap -> (FilenameDescr, TarLine) -> Errors -checkContent mapping (fd, tl) +checkContent :: BuildInfo -> (FilenameDescr, TarLine) -> Errors +checkContent buildInfo (fd, tl) = let fn = tlFileName tl - in case flattenFilenameDescr mapping fd of + in case flattenFilenameDescr buildInfo fd of Right fn' -> if fn' == fn then [] @@ -45,14 +35,15 @@ checkContent mapping (fd, tl) Left errs -> errs -flattenFilenameDescr :: ThingVersionMap -> FilenameDescr +flattenFilenameDescr :: BuildInfo -> FilenameDescr -> Either Errors FilePath -flattenFilenameDescr mapping fd = case partitionEithers (map f fd) of - ([], strs) -> Right (concat strs) - (errs, _) -> Left (concat errs) +flattenFilenameDescr buildInfo fd = case partitionEithers (map f fd) of + ([], strs) -> Right (concat strs) + (errs, _) -> Left (concat errs) where f (FP fp) = Right fp f (VersionOf thing) - = case lookup thing mapping of + = case lookup thing (biThingVersionMap buildInfo) of Just v -> Right v Nothing -> Left ["Can't happen: thing has no version in mapping"] + f Ways = Right $ intercalate "-" $ biWays buildInfo