[project @ 2001-10-22 10:33:50 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / Finder.lhs
index 5a4d8b7..c90bb0f 100644 (file)
@@ -64,30 +64,34 @@ maybeHomeModule :: ModuleName -> Bool -> IO (Maybe (Module, ModuleLocation))
 maybeHomeModule mod_name is_source = do
    home_path <- readIORef v_Import_paths
    hisuf     <- readIORef v_Hi_suf
+   mode      <- readIORef v_GhcMode
 
    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)
-       ]
+       -- In compilation manager modes, we look for source files in the home
+       -- package because we can compile these automatically.  In one-shot
+       -- compilation mode we look for .hi files only.
+       std_exts
+         | isCompManagerMode mode =
+               [ ("hs",   \ _ fName path -> mkHomeModuleLocn mod_name path fName)
+               , ("lhs",  \ _ fName path -> mkHomeModuleLocn mod_name path fName)
+               ]
+        | otherwise =
+               [ (hisuf,  \ _ fName path -> mkHiOnlyModuleLocn mod_name fName) ]
+
+        -- last chance: .hi-boot-<ver> and .hi-boot
+       hi_boot_ver = "hi-boot-" ++ cHscIfaceFileVersion
 
        boot_exts = 
-                       [ (hi_boot_ver, \ _ fName path -> mkHiOnlyModuleLocn mod_name fName)
-               , ("hi-boot", \ _ fName path -> mkHiOnlyModuleLocn mod_name fName)
-               ]
+               [ (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)
+       (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.
@@ -116,7 +120,7 @@ mkHomeModuleLocn mod_name
 
    -- take the *last* component of the module name (if a hierarchical name),
    -- and append it to the directory to get the .hi file name.
-   let (_,mod_str) = split_longest_prefix (moduleNameUserString mod_name) '.'
+   let (_,mod_str) = split_longest_prefix (moduleNameUserString mod_name) (=='.')
        hi_filename = mod_str ++ '.':hisuf
        hi_path | Just d <- hidir = d
               | otherwise       = getdir basename
@@ -148,6 +152,15 @@ findPackageMod mod_name hiOnly = do
   let imp_dirs = concatMap (\ pkg -> map ((,) pkg) (import_dirs pkg)) pkgs
       mod_str  = moduleNameUserString mod_name 
       basename = map (\c -> if c == '.' then '/' else c) mod_str
+
+      mkPackageModule mod_name pkg mbFName path =
+        return ( mkModule mod_name (mkFastString (name pkg))
+               , ModuleLocation{ ml_hspp_file = Nothing
+                              , ml_hs_file   = mbFName
+                              , ml_hi_file   = path ++ '.':package_hisuf
+                              , ml_obj_file  = Nothing
+                              })
+
   searchPathExts
        imp_dirs basename
         ((package_hisuf,\ pkg fName path -> mkPackageModule mod_name pkg Nothing path) :
@@ -157,13 +170,6 @@ findPackageMod mod_name hiOnly = do
          , ("lhs", \ pkg fName path -> mkPackageModule mod_name pkg (Just fName) path)
          ]))
  where
-  mkPackageModule mod_name pkg mbFName path =
-    return ( mkModule mod_name (mkFastString (name pkg))
-           , ModuleLocation{ ml_hspp_file = Nothing
-                          , ml_hs_file   = mbFName
-                          , ml_hi_file   = path ++".hi"
-                          , ml_obj_file  = Nothing
-                          })
 
 findPackageModule :: ModuleName -> IO (Maybe (Module, ModuleLocation))
 findPackageModule mod_name = findPackageMod mod_name True