From: simonmar Date: Wed, 27 Feb 2002 15:16:53 +0000 (+0000) Subject: [project @ 2002-02-27 15:16:53 by simonmar] X-Git-Tag: Approx_11550_changesets_converted~2341 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=205d1bb04ef62a2d67aa5f3750449c50badc284b;p=ghc-hetmet.git [project @ 2002-02-27 15:16:53 by simonmar] When searching for files with multiple extensions in multiple paths, search each path for all the possible files, rather than the other way around. Otherwise, a .hs file later in the path may override a .lhs file earlier in the path, and similar strange things happen with mkdependHS. Reported-by: Duncan Coutts MERGE TO STABLE --- diff --git a/ghc/compiler/main/Finder.lhs b/ghc/compiler/main/Finder.lhs index de9b760..fc945b6 100644 --- a/ghc/compiler/main/Finder.lhs +++ b/ghc/compiler/main/Finder.lhs @@ -186,25 +186,18 @@ searchPathExts :: [FilePath] -> String -> [(String, FilePath -> String -> IO (Module, ModuleLocation))] -> IO (Maybe (Module, ModuleLocation)) -searchPathExts path basename exts = search exts +searchPathExts path basename exts = search path where - search [] = return Nothing - search ((x,f):xs) = do - let fName = (basename ++ '.':x) - found <- findOnPath path fName - case found of - -- special case to avoid getting "./foo." all the time - Just "." -> fmap Just (f fName basename) - Just path -> fmap Just (f (path ++ '/':fName) - (path ++ '/':basename)) - Nothing -> search xs - -findOnPath :: [String] -> String -> IO (Maybe FilePath) -findOnPath path s = loop path - where - loop [] = return Nothing - loop (d:ds) = do - let file = d ++ '/':s - b <- doesFileExist file - if b then return (Just d) else loop ds + search [] = return Nothing + search (p:ps) = loop exts + where + base | p == "." = basename + | otherwise = p ++ '/':basename + + loop [] = search ps + loop ((ext,fn):exts) = do + let file = base ++ '.':ext + b <- doesFileExist file + if b then Just `liftM` fn file base + else loop exts \end{code}