-findModule name = do
- j <- maybeHomeModule name
- case j of
- Just home_module -> return (Just home_module)
- Nothing -> maybePackageModule name
-
-maybeHomeModule :: ModuleName -> IO (Maybe (Module, ModuleLocation))
-maybeHomeModule mod_name = do
- home_cache <- readIORef v_HomeDirCache
-
- home_map <-
- case home_cache of
- Nothing -> do
- -- populate the home dir cache, using the import path (the import
- -- path is changed by -i flags on the command line, and defaults
- -- to ["."]).
- home_imports <- readIORef v_Import_paths
- let extendFM fm path = do
- contents <- getDirectoryContents' path
- return (addListToFM fm (zip contents (repeat path)))
- home_map <- foldM extendFM emptyFM home_imports
- writeIORef v_HomeDirCache (Just home_map)
- return home_map
-
- Just home_map -> return home_map
-
- let basename = moduleNameString mod_name
- hs = basename ++ ".hs"
- lhs = basename ++ ".lhs"
-
- case lookupFM home_map hs of {
- Just path -> mkHomeModuleLocn mod_name (path ++ '/':basename) hs;
- Nothing ->
-
- case lookupFM home_map lhs of {
- Just path -> mkHomeModuleLocn mod_name (path ++ '/':basename) lhs;
- Nothing -> return Nothing
-
- }}
-
-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
+findModule name = findModuleDep name False
+
+findModuleDep :: ModuleName -> Bool -> IO (Maybe (Module, ModuleLocation))
+findModuleDep name is_source
+ = do { j <- maybeHomeModule name is_source
+ ; case j of
+ Just home_module -> return (Just home_module)
+ Nothing -> findPackageMod name False
+ }
+
+maybeHomeModule :: ModuleName -> Bool -> IO (Maybe (Module, ModuleLocation))
+maybeHomeModule mod_name is_source = do
+ home_path <- readIORef v_Import_paths
+ hisuf <- readIORef v_Hi_suf
+
+ let mod_str = moduleNameUserString mod_name
+ basename = map (\c -> if c == '.' then '/' else c) mod_str
+ -- last chance: .hi-boot-<ver> and .hi-boot
+ hi_boot_ver = "hi-boot-" ++ cHscIfaceFileVersion
+
+ std_exts =
+ [ (hisuf,
+ \ _ fName path -> mkHiOnlyModuleLocn mod_name fName)
+ , ("hs",
+ \ _ fName path -> mkHomeModuleLocn mod_name path fName)
+ , ("lhs",
+ \ _ fName path -> mkHomeModuleLocn mod_name path fName)
+ ]
+
+ boot_exts =
+ [ (hi_boot_ver, \ _ fName path -> mkHiOnlyModuleLocn mod_name fName)
+ , ("hi-boot", \ _ fName path -> mkHiOnlyModuleLocn mod_name fName)
+ ]
+
+ searchPathExts
+ (map ((,) undefined) home_path)
+ basename
+ (if is_source then (boot_exts++std_exts) else std_exts ++ boot_exts)
+ -- for SOURCE imports, check the hi-boot extensions
+ -- before the source/iface ones, to avoid
+ -- creating circ Makefile deps.
+
+mkHiOnlyModuleLocn mod_name hi_file =
+ return
+ ( mkHomeModule mod_name
+ , ModuleLocation{ ml_hspp_file = Nothing
+ , ml_hs_file = Nothing
+ , ml_hi_file = hi_file
+ , ml_obj_file = Nothing
+ }
+ )
+
+-- The .hi file always follows the module name, whereas the object
+-- file may follow the name of the source file in the case where the
+-- two differ (see summariseFile in compMan/CompManager.lhs).
+
+mkHomeModuleLocn mod_name
+ basename -- everything but the extension
+ source_fn -- full path to the source (required)
+ = do
+