diff options
author | Yuras Shumovich <shumovichy@gmail.com> | 2017-01-20 16:53:45 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-01-20 16:55:36 -0500 |
commit | 15b9a85ef03e2729d487a6f8460be8880c797609 (patch) | |
tree | 401bc0e8f102c03ff61e7d8d967eefe4accd5960 /compiler/main/GhcMake.hs | |
parent | c43011da283bfcef664378bb451d5f3bffcdbe92 (diff) | |
download | haskell-15b9a85ef03e2729d487a6f8460be8880c797609.tar.gz |
Warn on missing home modules
Introduce a warning, -Wmissing-home-modules, to warn about home modules,
not listed in command line.
It is usefull for cabal when user fails to list a module in
`exposed-modules` and `other-modules`.
Test Plan: make TEST=MissingMod
Reviewers: mpickering, austin, bgamari
Reviewed By: bgamari
Subscribers: simonpj, mpickering, thomie
Differential Revision: https://phabricator.haskell.org/D2977
GHC Trac Issues: #13129
Diffstat (limited to 'compiler/main/GhcMake.hs')
-rw-r--r-- | compiler/main/GhcMake.hs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs index be6510bcb2..f74d09755f 100644 --- a/compiler/main/GhcMake.hs +++ b/compiler/main/GhcMake.hs @@ -132,9 +132,48 @@ depanal excluded_mods allow_dup_roots = do mod_graphE <- liftIO $ downsweep hsc_env old_graph excluded_mods allow_dup_roots mod_graph <- reportImportErrors mod_graphE + + warnMissingHomeModules hsc_env mod_graph + setSession hsc_env { hsc_mod_graph = mod_graph } return mod_graph +-- Note [Missing home modules] +-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-- Sometimes user doesn't want GHC to pick up modules, not explicitly listed +-- in a command line. For example, cabal may want to enable this warning +-- when building a library, so that GHC warns user about modules, not listed +-- neither in `exposed-modules`, nor in `other-modules`. +-- +-- Here "home module" means a module, that doesn't come from an other package. +-- +-- For example, if GHC is invoked with modules "A" and "B" as targets, +-- but "A" imports some other module "C", then GHC will issue a warning +-- about module "C" not being listed in a command line. +-- +-- The warning in enabled by `-Wmissing-home-modules`. See Trac #13129 +warnMissingHomeModules :: GhcMonad m => HscEnv -> ModuleGraph -> m () +warnMissingHomeModules hsc_env mod_graph = + when (wopt Opt_WarnMissingHomeModules dflags && not (null missing)) $ + logWarnings (listToBag [warn]) + where + dflags = hsc_dflags hsc_env + missing = filter (`notElem` targets) imports + imports = map (moduleName . ms_mod) mod_graph + targets = map (targetid_to_name . targetId) (hsc_targets hsc_env) + + msg = text "Modules are not listed in command line: " + <> sep (map ppr missing) + warn = makeIntoWarning + (Reason Opt_WarnMissingHomeModules) + (mkPlainErrMsg dflags noSrcSpan msg) + + targetid_to_name (TargetModule name) = name + targetid_to_name (TargetFile file _) = + -- We can get a file even if module name in specified in command line + -- because it can be converted in guessTarget. So lets convert it back. + mkModuleName (fst $ splitExtension file) + -- | Describes which modules of the module graph need to be loaded. data LoadHowMuch = LoadAllTargets |