diff options
author | Herbert Valerio Riedel <hvr@gnu.org> | 2017-05-22 11:59:56 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-05-22 12:41:20 -0400 |
commit | dac49bdc79387ca9f91c7c5c9220699efb6239fb (patch) | |
tree | db91e9dea573a30636ca0a75687cd9738ccde0bf | |
parent | 83ee930fdd125d74939307ed3fa1bf6a2ba7fb36 (diff) | |
download | haskell-dac49bdc79387ca9f91c7c5c9220699efb6239fb.tar.gz |
Handle file targets in missing home modules warning
When main module is listed on command line as a file, we should not
issue a warning about it. See Trac #13727
Reviewers: austin, bgamari, Yuras
Reviewed By: bgamari, Yuras
Subscribers: 23Skidoo, rwbarton, thomie
GHC Trac Issues: #13727
Differential Revision: https://phabricator.haskell.org/D3598
17 files changed, 124 insertions, 10 deletions
diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs index 60f38d4bf4..a3b45e3a29 100644 --- a/compiler/main/GhcMake.hs +++ b/compiler/main/GhcMake.hs @@ -164,11 +164,35 @@ warnMissingHomeModules :: GhcMonad m => HscEnv -> ModuleGraph -> m () warnMissingHomeModules hsc_env mod_graph = when (wopt Opt_WarnMissingHomeModules dflags && not (null missing)) $ logWarnings (listToBag [warn]) - where + 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) + targets = map targetId (hsc_targets hsc_env) + + is_known_module mod = any (is_my_target mod) targets + + -- We need to be careful to handle the case where (possibly + -- path-qualified) filenames (aka 'TargetFile') rather than module + -- names are being passed on the GHC command-line. + -- + -- For instance, `ghc --make src-exe/Main.hs` and + -- `ghc --make -isrc-exe Main` are supposed to be equivalent. + -- Note also that we can't always infer the associated module name + -- directly from the filename argument. See Trac #13727. + is_my_target mod (TargetModule name) + = moduleName (ms_mod mod) == name + is_my_target mod (TargetFile target_file _) + | Just mod_file <- ml_hs_file (ms_location mod) + = target_file == mod_file || + -- We can get a file target even if a module name was + -- originally specified in a command line because it can + -- be converted in guessTarget (by appending .hs/.lhs). + -- So let's convert it back and compare with module name + mkModuleName (fst $ splitExtension target_file) + == moduleName (ms_mod mod) + is_my_target _ _ = False + + missing = map (moduleName . ms_mod) $ + filter (not . is_known_module) mod_graph msg = text "Modules are not listed in command line: " <> sep (map ppr missing) @@ -176,12 +200,6 @@ warnMissingHomeModules hsc_env mod_graph = (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 let's convert it back. - mkModuleName (fst $ splitExtension file) - -- | Describes which modules of the module graph need to be loaded. data LoadHowMuch = LoadAllTargets diff --git a/testsuite/tests/warnings/should_compile/T13727/Makefile b/testsuite/tests/warnings/should_compile/T13727/Makefile new file mode 100644 index 0000000000..1c39d1c1fe --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/Makefile @@ -0,0 +1,3 @@ +TOP=../../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727a.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727a.stderr new file mode 100644 index 0000000000..64ad6d2895 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/T13727a.stderr @@ -0,0 +1,6 @@ + +<no location info>: warning: [-Wmissing-home-modules] + Modules are not listed in command line: M1 +[1 of 2] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o ) +[2 of 2] Compiling Main ( src-exe/Main.hs, src-exe/Main.o ) +Linking src-exe/Main ... diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727b.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727b.stderr new file mode 100644 index 0000000000..64ad6d2895 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/T13727b.stderr @@ -0,0 +1,6 @@ + +<no location info>: warning: [-Wmissing-home-modules] + Modules are not listed in command line: M1 +[1 of 2] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o ) +[2 of 2] Compiling Main ( src-exe/Main.hs, src-exe/Main.o ) +Linking src-exe/Main ... diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727c.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727c.stderr new file mode 100644 index 0000000000..0b9ac0ebf2 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/T13727c.stderr @@ -0,0 +1,3 @@ +[1 of 2] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o ) +[2 of 2] Compiling Main ( src-exe/Main.hs, src-exe/Main.o ) +Linking src-exe/Main ... diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727d.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727d.stderr new file mode 100644 index 0000000000..0b9ac0ebf2 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/T13727d.stderr @@ -0,0 +1,3 @@ +[1 of 2] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o ) +[2 of 2] Compiling Main ( src-exe/Main.hs, src-exe/Main.o ) +Linking src-exe/Main ... diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727e.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727e.stderr new file mode 100644 index 0000000000..0b9ac0ebf2 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/T13727e.stderr @@ -0,0 +1,3 @@ +[1 of 2] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o ) +[2 of 2] Compiling Main ( src-exe/Main.hs, src-exe/Main.o ) +Linking src-exe/Main ... diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727f.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727f.stderr new file mode 100644 index 0000000000..35bfae84a7 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/T13727f.stderr @@ -0,0 +1,7 @@ + +<no location info>: warning: [-Wmissing-home-modules] + Modules are not listed in command line: M1 Main +[1 of 3] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o ) +[2 of 3] Compiling Main ( src-exe/Main.hs, src-exe/Main.o ) +[3 of 3] Compiling AltMain ( src-exe/AltMain.hs, src-exe/AltMain.o ) +Linking src-exe/AltMain ... diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727g.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727g.stderr new file mode 100644 index 0000000000..35bfae84a7 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/T13727g.stderr @@ -0,0 +1,7 @@ + +<no location info>: warning: [-Wmissing-home-modules] + Modules are not listed in command line: M1 Main +[1 of 3] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o ) +[2 of 3] Compiling Main ( src-exe/Main.hs, src-exe/Main.o ) +[3 of 3] Compiling AltMain ( src-exe/AltMain.hs, src-exe/AltMain.o ) +Linking src-exe/AltMain ... diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727h.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727h.stderr new file mode 100644 index 0000000000..1832b38432 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/T13727h.stderr @@ -0,0 +1,7 @@ + +<no location info>: warning: [-Wmissing-home-modules] + Modules are not listed in command line: M1 +[1 of 3] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o ) +[2 of 3] Compiling Main ( src-exe/Main.hs, src-exe/Main.o ) +[3 of 3] Compiling AltMain ( src-exe/AltMain.hs, src-exe/AltMain.o ) +Linking src-exe/AltMain ... diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727i.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727i.stderr new file mode 100644 index 0000000000..1832b38432 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/T13727i.stderr @@ -0,0 +1,7 @@ + +<no location info>: warning: [-Wmissing-home-modules] + Modules are not listed in command line: M1 +[1 of 3] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o ) +[2 of 3] Compiling Main ( src-exe/Main.hs, src-exe/Main.o ) +[3 of 3] Compiling AltMain ( src-exe/AltMain.hs, src-exe/AltMain.o ) +Linking src-exe/AltMain ... diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727j.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727j.stderr new file mode 100644 index 0000000000..f6d3197f01 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/T13727j.stderr @@ -0,0 +1,7 @@ + +<no location info>: warning: [-Wmissing-home-modules] + Modules are not listed in command line: Main +[1 of 3] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o ) +[2 of 3] Compiling Main ( src-exe/Main.hs, src-exe/Main.o ) +[3 of 3] Compiling AltMain ( src-exe/AltMain.hs, src-exe/AltMain.o ) +Linking src-exe/AltMain ... diff --git a/testsuite/tests/warnings/should_compile/T13727/T13727k.stderr b/testsuite/tests/warnings/should_compile/T13727/T13727k.stderr new file mode 100644 index 0000000000..c648d9b593 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/T13727k.stderr @@ -0,0 +1,4 @@ +[1 of 3] Compiling M1 ( src-lib/M1.hs, src-lib/M1.o ) +[2 of 3] Compiling Main ( src-exe/Main.hs, src-exe/Main.o ) +[3 of 3] Compiling AltMain ( src-exe/AltMain.hs, src-exe/AltMain.o ) +Linking src-exe/AltMain ... diff --git a/testsuite/tests/warnings/should_compile/T13727/all.T b/testsuite/tests/warnings/should_compile/T13727/all.T new file mode 100644 index 0000000000..1ca91bded7 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/all.T @@ -0,0 +1,20 @@ +# basic tests +## complains about M1 only +test('T13727a', [extra_files(['src-exe/','src-lib/'])], multimod_compile, ['Main', '-isrc-exe -isrc-lib -Wmissing-home-modules']) +test('T13727b', [extra_files(['src-exe/','src-lib/'])], multimod_compile, ['src-exe/Main.hs', '-isrc-lib -Wmissing-home-modules']) +## warning-free +test('T13727c', [extra_files(['src-exe/','src-lib/'])], multimod_compile, ['Main', 'M1 -isrc-exe -isrc-lib -Wmissing-home-modules']) +test('T13727d', [extra_files(['src-exe/','src-lib/'])], multimod_compile, ['src-exe/Main.hs', 'M1 -isrc-lib -Wmissing-home-modules']) +test('T13727e', [extra_files(['src-exe/','src-lib/'])], multimod_compile, ['src-exe/Main.hs', 'src-lib/M1.hs -Wmissing-home-modules']) + +# tests involving -main-is +## complains about M1 & Main +test('T13727f', [extra_files(['src-exe/','src-lib/'])], multimod_compile, ['AltMain', '-main-is AltMain.alt_main -isrc-exe -isrc-lib -Wmissing-home-modules']) +test('T13727g', [extra_files(['src-exe/','src-lib/'])], multimod_compile, ['src-exe/AltMain.hs', '-main-is AltMain.alt_main -isrc-exe -isrc-lib -Wmissing-home-modules']) +## complains about M1 only +test('T13727h', [extra_files(['src-exe/','src-lib/'])], multimod_compile, ['src-exe/AltMain.hs', '-main-is AltMain.alt_main ./src-exe/Main.hs -isrc-exe -isrc-lib -Wmissing-home-modules']) +test('T13727i', [extra_files(['src-exe/','src-lib/'])], multimod_compile, ['AltMain', '-main-is AltMain.alt_main Main -isrc-exe -isrc-lib -Wmissing-home-modules']) +## complains about Main only +test('T13727j', [extra_files(['src-exe/','src-lib/'])], multimod_compile, ['AltMain', '-main-is AltMain.alt_main M1 -isrc-exe -isrc-lib -Wmissing-home-modules']) +## warning-free +test('T13727k', [extra_files(['src-exe/','src-lib/'])], multimod_compile, ['AltMain', '-main-is AltMain.alt_main M1 Main -isrc-exe -isrc-lib -Wmissing-home-modules']) diff --git a/testsuite/tests/warnings/should_compile/T13727/src-exe/AltMain.hs b/testsuite/tests/warnings/should_compile/T13727/src-exe/AltMain.hs new file mode 100644 index 0000000000..850ae96f33 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/src-exe/AltMain.hs @@ -0,0 +1,6 @@ +module AltMain(alt_main) where + +import Main + +alt_main :: IO () +alt_main = Main.main diff --git a/testsuite/tests/warnings/should_compile/T13727/src-exe/Main.hs b/testsuite/tests/warnings/should_compile/T13727/src-exe/Main.hs new file mode 100644 index 0000000000..0394c57d98 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/src-exe/Main.hs @@ -0,0 +1,6 @@ +module Main(main) where + +import M1 () + +main :: IO () +main = return () diff --git a/testsuite/tests/warnings/should_compile/T13727/src-lib/M1.hs b/testsuite/tests/warnings/should_compile/T13727/src-lib/M1.hs new file mode 100644 index 0000000000..5d99c370b0 --- /dev/null +++ b/testsuite/tests/warnings/should_compile/T13727/src-lib/M1.hs @@ -0,0 +1 @@ +module M1 where |