findModule, -- :: ModuleName -> IO (Maybe (Module, ModuleLocation))
mkHomeModuleLocn, -- :: ModuleName -> String -> FilePath
-- -> IO ModuleLocation
- emptyHomeDirCache -- :: IO ()
+ emptyHomeDirCache, -- :: IO ()
+ flushPackageCache -- :: [PackageConfig] -> IO ()
) where
#include "HsVersions.h"
import Config
import IOExts
-import Directory
import List
import IO
import Monad
-import Outputable ( showSDoc, ppr ) -- debugging only
+import Outputable
\end{code}
The Finder provides a thin filesystem abstraction to the rest of the
initFinder :: [PackageConfig] -> IO ()
initFinder pkgs
- = do { -- expunge our home cache
- ; writeIORef v_HomeDirCache Nothing
- -- lazilly fill in the package cache
- ; writeIORef v_PkgDirCache (unsafePerformIO (newPkgCache pkgs))
- }
+ = do emptyHomeDirCache
+ flushPackageCache pkgs
+
+-- empty, and lazilly fill in the package cache
+flushPackageCache :: [PackageConfig] -> IO ()
+flushPackageCache pkgs = writeIORef v_PkgDirCache
+ (unsafePerformIO (newPkgCache pkgs))
emptyHomeDirCache :: IO ()
-emptyHomeDirCache
- = writeIORef v_HomeDirCache Nothing
+emptyHomeDirCache = writeIORef v_HomeDirCache Nothing
findModule :: ModuleName -> IO (Maybe (Module, ModuleLocation))
findModule name
-- to ["."]).
home_imports <- readIORef v_Import_paths
let extendFM fm path = do
- contents <- getDirectoryContents' path
+ contents <- softGetDirectoryContents path
let clean_contents = filter isUsefulFile contents
return (addListToFM fm (zip clean_contents (repeat path)))
- home_map <- foldM extendFM emptyFM home_imports
+ home_map <- foldM extendFM emptyFM (reverse home_imports)
writeIORef v_HomeDirCache (Just home_map)
return home_map
mkHomeModuleLocn mod_name basename source_fn = do
- -- figure out the .hi file name: it lives in the same dir as the
- -- source, unless there's a -ohi flag on the command line.
- ohi <- readIORef v_Output_hi
hisuf <- readIORef v_Hi_suf
- let hifile = case ohi of
- Nothing -> getdir basename
- ++ '/':moduleNameUserString mod_name
+ let hifile = getdir basename ++ '/':moduleNameUserString mod_name
++ '.':hisuf
- Just fn -> fn
-- figure out the .o file name. It also lives in the same dir
-- as the source, but can be overriden by a -odir flag.
let dirs = import_dirs pkg
pkg_name = _PK_ (name pkg)
let addDir fm dir = do
- contents <- getDirectoryContents' dir
+ contents <- softGetDirectoryContents dir
return (addListToFM fm (zip contents
(repeat (pkg_name,dir))))
foldM addDir fm dirs
isUsefulFile fn
= let suffix = (reverse . takeWhile (/= '.') . reverse) fn
in suffix `elem` ["hi", "hs", "lhs", "hi-boot", "hi-boot-5"]
-
-getDirectoryContents' d
- = IO.catch (getDirectoryContents d)
- (\_ -> do hPutStr stderr
- ("WARNING: error while reading directory " ++ d)
- return []
- )
-
\end{code}