From 1d43ed12aa8ecef97459d852868d241e42bcbeb8 Mon Sep 17 00:00:00 2001 From: Freddy Cubas Date: Fri, 18 Jul 2025 09:18:52 -0400 Subject: [PATCH] Added option to not try to disambiguate multiple main modules --- src/Graphmod.hs | 12 ++++++++++-- src/Graphmod/Utils.hs | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Graphmod.hs b/src/Graphmod.hs index 2edb7f2..c0f47b2 100644 --- a/src/Graphmod.hs +++ b/src/Graphmod.hs @@ -108,11 +108,11 @@ graph opts inputs = fmap maybePrune $ mfix $ \ ~(_,mods) -> then add done es size m [] todo else loop done es size todo f : gs -> do unless (null gs) (warn opts (ambigMsg m fs)) - (x,imps) <- parseFile f + (x,imps) <- parseFile (multi_main opts) f add done es size x imps todo loop done es size (File f : todo) = - do (m,is) <- parseFile f + do (m,is) <- parseFile (multi_main opts) f if ignore done m then loop done es size todo else add done es size m is todo @@ -489,6 +489,7 @@ data Opts = Opts , graph_size :: String , use_cabal :: Bool -- ^ should we try to use a cabal file, if any + , multi_main :: Bool } type IgnoreSet = Trie.Trie String IgnoreSpec @@ -510,6 +511,7 @@ default_opts = Opts , prune_edges = False , graph_size = "6,4" , use_cabal = True + , multi_main = True } options :: [OptDescr OptT] @@ -555,6 +557,9 @@ options = , Option ['v'] ["version"] (NoArg set_show_version) "Show the current version." + + , Option [] ["single-main"] (NoArg set_single_main) + "Don't try to disambiguate multiple main modules" ] add_current :: OptT @@ -577,6 +582,9 @@ set_no_cluster o = o { use_clusters = False } set_no_mod_in_cluster :: OptT set_no_mod_in_cluster o = o { mod_in_cluster = False } +set_single_main :: OptT +set_single_main o = o { multi_main = False } + add_inc :: FilePath -> OptT add_inc d o = o { inc_dirs = d : inc_dirs o } diff --git a/src/Graphmod/Utils.hs b/src/Graphmod/Utils.hs index 2dc2f60..57e19c7 100644 --- a/src/Graphmod/Utils.hs +++ b/src/Graphmod/Utils.hs @@ -31,8 +31,8 @@ data ImpType = NormalImp | SourceImp deriving (Show,Eq,Ord) -- | Get the imports of a file. -parseFile :: FilePath -> IO (ModName,[Import]) -parseFile f = +parseFile :: Bool -> FilePath -> IO (ModName,[Import]) +parseFile multi_main f = do h <- IO.openFile f IO.ReadMode IO.hSetEncoding h IO.utf8 (modName, imps) <- (parseString . get_text) `fmap` IO.hGetContents h @@ -42,7 +42,7 @@ parseFile f = then return (splitModName (takeBaseName f), imps) else case modName of -- disambiguate Main modules with no qualifiers - (Hierarchy [],"Main") -> return (splitFilePath f,imps) + (Hierarchy [],"Main") | multi_main -> return (splitFilePath f,imps) _ -> return (modName, imps)