[project @ 2002-02-27 15:16:53 by simonmar]
authorsimonmar <unknown>
Wed, 27 Feb 2002 15:16:53 +0000 (15:16 +0000)
committersimonmar <unknown>
Wed, 27 Feb 2002 15:16:53 +0000 (15:16 +0000)
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 <duncan.coutts@worcester.oxford.ac.uk>

MERGE TO STABLE

ghc/compiler/main/Finder.lhs

index de9b760..fc945b6 100644 (file)
@@ -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.<ext>" 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}