-doMkDependHS :: Session -> [FilePath] -> IO ()
-doMkDependHS session srcs
- = do { -- Initialisation
- dflags <- GHC.getSessionDynFlags session
- ; files <- beginMkDependHS dflags
-
- -- Do the downsweep to find all the modules
- ; targets <- mapM (\s -> GHC.guessTarget s Nothing) srcs
- ; GHC.setTargets session targets
- ; let excl_mods = depExcludeMods dflags
- ; r <- GHC.depanal session excl_mods True {- Allow dup roots -}
- ; case r of
- Nothing -> exitWith (ExitFailure 1)
- Just mod_summaries -> do {
+doMkDependHS :: GhcMonad m => [FilePath] -> m ()
+doMkDependHS srcs = do
+ -- Initialisation
+ dflags <- GHC.getSessionDynFlags
+ files <- liftIO $ beginMkDependHS dflags
+
+ -- Do the downsweep to find all the modules
+ targets <- mapM (\s -> GHC.guessTarget s Nothing) srcs
+ GHC.setTargets targets
+ let excl_mods = depExcludeMods dflags
+ mod_summaries <- GHC.depanal excl_mods True {- Allow dup roots -}
+
+ -- Sort into dependency order
+ -- There should be no cycles
+ let sorted = GHC.topSortModuleGraph False mod_summaries Nothing
+
+ -- Print out the dependencies if wanted
+ liftIO $ debugTraceMsg dflags 2 (text "Module dependencies" $$ ppr sorted)