#include "HsVersions.h"
-import MkIface --tmp
-import HsSyn -- tmp
-
import CmLink
import CmTypes
import DriverPipeline
import Exception ( Exception, try )
#endif
--- lang
-import Exception ( throwDyn )
+import EXCEPTION ( throwDyn )
-- std
import Directory ( getModificationTime, doesFileExist )
-- clean up between compilations
let cleanup = cleanTempFilesExcept verb
- (ppFilesFromSummaries (flattenSCCs upsweep_these))
+ (ppFilesFromSummaries (flattenSCCs mg2))
(upsweep_complete_success, threaded3, modsUpswept, newLis)
<- upsweep_mods ghci_mode dflags valid_linkables reachable_from
downsweep :: [FilePath] -> [ModSummary] -> IO [ModSummary]
downsweep roots old_summaries
= do rootSummaries <- mapM getRootSummary roots
+ checkDuplicates rootSummaries
all_summaries
<- loop (concat (map (\ m -> zip (repeat (fromMaybe "<unknown>" (ml_hs_file (ms_location m))))
(ms_imps m)) rootSummaries))
hs_file = file ++ ".hs"
lhs_file = file ++ ".lhs"
+ -- In a root module, the filename is allowed to diverge from the module
+ -- name, so we have to check that there aren't multiple root files
+ -- defining the same module (otherwise the duplicates will be silently
+ -- ignored, leading to confusing behaviour).
+ checkDuplicates :: [ModSummary] -> IO ()
+ checkDuplicates summaries = mapM_ check summaries
+ where check summ =
+ case dups of
+ [] -> return ()
+ [_one] -> return ()
+ many -> multiRootsErr modl many
+ where modl = ms_mod summ
+ dups =
+ [ fromJust (ml_hs_file (ms_location summ'))
+ | summ' <- summaries, ms_mod summ' == modl ]
+
getSummary :: (FilePath,ModuleName) -> IO (Maybe ModSummary)
getSummary (currentMod,nm)
= do found <- findModule nm
= throwDyn (CmdLineError (showSDoc (text "module" <+>
quotes (ppr mod) <+>
text "is a package module")))
+
+multiRootsErr mod files
+ = throwDyn (ProgramError (showSDoc (
+ text "module" <+> quotes (ppr mod) <+>
+ text "is defined in multiple files:" <+>
+ sep (map text files))))
\end{code}