X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Fmain%2FDriverMkDepend.hs;h=400f8bdf0b927ee84495c3a0b1ac31c3c27805e2;hp=adfcbbdbf0071f67e49e9f25142113991e739c68;hb=34cc75e1a62638f2833815746ebce0a9114dc26b;hpb=25ed0cf7d4c2fbf9e455405f0a8525e0ae27b4e7 diff --git a/compiler/main/DriverMkDepend.hs b/compiler/main/DriverMkDepend.hs index adfcbbd..400f8bd 100644 --- a/compiler/main/DriverMkDepend.hs +++ b/compiler/main/DriverMkDepend.hs @@ -21,12 +21,12 @@ import HsSyn ( ImportDecl(..) ) import PrelNames import DynFlags import Util -import HscTypes ( HscEnv, IsBootInterface, msObjFilePath, msHsFilePath, getSession ) +import HscTypes import SysTools ( newTempName ) import qualified SysTools import Module import Digraph ( SCC(..) ) -import Finder ( findImportedModule, FindResult(..) ) +import Finder import Outputable import Panic import SrcLoc @@ -34,7 +34,7 @@ import Data.List import FastString import Exception -import ErrUtils ( debugTraceMsg, putMsg ) +import ErrUtils import MonadUtils ( liftIO ) import System.Directory @@ -72,7 +72,8 @@ doMkDependHS srcs = do -- Prcess them one by one, dumping results into makefile -- and complaining about cycles hsc_env <- getSession - mapM (liftIO . processDeps dflags hsc_env excl_mods (mkd_tmp_hdl files)) sorted + root <- liftIO getCurrentDirectory + mapM (liftIO . processDeps dflags hsc_env excl_mods root (mkd_tmp_hdl files)) sorted -- If -ddump-mod-cycles, show cycles in the module graph liftIO $ dumpModCycles dflags mod_summaries @@ -158,6 +159,7 @@ beginMkDependHS dflags = do processDeps :: DynFlags -> HscEnv -> [ModuleName] + -> FilePath -> Handle -- Write dependencies to here -> SCC ModSummary -> IO () @@ -176,25 +178,25 @@ processDeps :: DynFlags -- -- For {-# SOURCE #-} imports the "hi" will be "hi-boot". -processDeps _ _ _ _ (CyclicSCC nodes) +processDeps _ _ _ _ _ (CyclicSCC nodes) = -- There shouldn't be any cycles; report them ghcError (ProgramError (showSDoc $ GHC.cyclicModuleErr nodes)) -processDeps dflags hsc_env excl_mods hdl (AcyclicSCC node) +processDeps dflags hsc_env excl_mods root hdl (AcyclicSCC node) = do { let extra_suffixes = depSuffixes dflags include_pkg_deps = depIncludePkgDeps dflags src_file = msHsFilePath node obj_file = msObjFilePath node obj_files = insertSuffixes obj_file extra_suffixes - do_imp is_boot pkg_qual imp_mod - = do { mb_hi <- findDependency hsc_env pkg_qual imp_mod + do_imp loc is_boot pkg_qual imp_mod + = do { mb_hi <- findDependency hsc_env loc pkg_qual imp_mod is_boot include_pkg_deps ; case mb_hi of { Nothing -> return () ; Just hi_file -> do { let hi_files = insertSuffixes hi_file extra_suffixes - write_dep (obj,hi) = writeDependency hdl [obj] hi + write_dep (obj,hi) = writeDependency root hdl [obj] hi -- Add one dependency for each suffix; -- e.g. A.o : B.hi @@ -204,13 +206,13 @@ processDeps dflags hsc_env excl_mods hdl (AcyclicSCC node) -- Emit std dependency of the object(s) on the source file -- Something like A.o : A.hs - ; writeDependency hdl obj_files src_file + ; writeDependency root hdl obj_files src_file -- Emit a dependency for each import ; let do_imps is_boot idecls = sequence_ - [ do_imp is_boot (ideclPkgQual i) mod - | L _ i <- idecls, + [ do_imp loc is_boot (ideclPkgQual i) mod + | L loc i <- idecls, let mod = unLoc (ideclName i), mod `notElem` excl_mods ] @@ -218,17 +220,18 @@ processDeps dflags hsc_env excl_mods hdl (AcyclicSCC node) ; do_imps False (ms_imps node) ; when (dopt Opt_ImplicitPrelude (ms_hspp_opts node)) $ - do_imp False Nothing pRELUDE_NAME + do_imp noSrcSpan False Nothing pRELUDE_NAME } findDependency :: HscEnv + -> SrcSpan -> Maybe FastString -- package qualifier, if any -> ModuleName -- Imported module -> IsBootInterface -- Source import -> Bool -- Record dependency on package modules -> IO (Maybe FilePath) -- Interface file file -findDependency hsc_env pkg imp is_boot include_pkg_deps +findDependency hsc_env srcloc pkg imp is_boot include_pkg_deps = do { -- Find the module; this will be fast because -- we've done it once during downsweep r <- findImportedModule hsc_env imp pkg @@ -242,16 +245,23 @@ findDependency hsc_env pkg imp is_boot include_pkg_deps | otherwise -> return Nothing - _ -> panic "findDependency" + fail -> throwOneError $ mkPlainErrMsg srcloc $ + cannotFindModule (hsc_dflags hsc_env) imp fail } ----------------------------- -writeDependency :: Handle -> [FilePath] -> FilePath -> IO () --- (writeDependency h [t1,t2] dep) writes to handle h the dependency +writeDependency :: FilePath -> Handle -> [FilePath] -> FilePath -> IO () +-- (writeDependency r h [t1,t2] dep) writes to handle h the dependency -- t1 t2 : dep -writeDependency hdl targets dep - = hPutStrLn hdl (unwords (map forOutput targets) ++ " : " ++ forOutput dep) - where forOutput = escapeSpaces . reslash Forwards . normalise +writeDependency root hdl targets dep + = do let -- We need to avoid making deps on + -- c:/foo/... + -- on cygwin as make gets confused by the : + -- Making relative deps avoids some instances of this. + dep' = makeRelative root dep + forOutput = escapeSpaces . reslash Forwards . normalise + output = unwords (map forOutput targets) ++ " : " ++ forOutput dep' + hPutStrLn hdl output ----------------------------- insertSuffixes