Skip to content

Commit e2c04f0

Browse files
Yurasezyang
authored andcommitted
Enable -Wmissing-home modules when building a library
1 parent 60ca093 commit e2c04f0

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

Cabal/Distribution/Simple/GHC.hs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,11 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
14501450
componentGhcOptions :: Verbosity -> LocalBuildInfo
14511451
-> BuildInfo -> ComponentLocalBuildInfo -> FilePath
14521452
-> GhcOptions
1453-
componentGhcOptions = Internal.componentGhcOptions
1453+
componentGhcOptions verbosity lbi =
1454+
Internal.componentGhcOptions verbosity implInfo lbi
1455+
where
1456+
comp = compiler lbi
1457+
implInfo = getImplInfo comp
14541458

14551459
componentCcGhcOptions :: Verbosity -> LocalBuildInfo
14561460
-> BuildInfo -> ComponentLocalBuildInfo

Cabal/Distribution/Simple/GHC/ImplInfo.hs

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ data GhcImplInfo = GhcImplInfo
4242
, flagPackageConf :: Bool -- ^ use package-conf instead of package-db
4343
, flagDebugInfo :: Bool -- ^ -g flag supported
4444
, supportsPkgEnvFiles :: Bool -- ^ picks up @.ghc.environment@ files
45+
, flagWarnMissingHomeModules :: Bool -- ^ -Wmissing-home-modules is supported
4546
}
4647

4748
getImplInfo :: Compiler -> GhcImplInfo
@@ -67,6 +68,7 @@ ghcVersionImplInfo ver = GhcImplInfo
6768
, flagPackageConf = v < [7,5]
6869
, flagDebugInfo = v >= [7,10]
6970
, supportsPkgEnvFiles = v >= [8,0,1,20160901] -- broken in 8.0.1, fixed in 8.0.2
71+
, flagWarnMissingHomeModules = v >= [8,2,1]
7072
}
7173
where
7274
v = versionNumbers ver
@@ -83,6 +85,7 @@ ghcjsVersionImplInfo _ghcjsver ghcver = GhcImplInfo
8385
, flagPackageConf = False
8486
, flagDebugInfo = False
8587
, supportsPkgEnvFiles = ghcv >= [8,0,2] --TODO: check this works in ghcjs
88+
, flagWarnMissingHomeModules = False
8689
}
8790
where
8891
ghcv = versionNumbers ghcver

Cabal/Distribution/Simple/GHC/Internal.hs

+8-2
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ componentCcGhcOptions verbosity _implInfo lbi bi clbi odir filename =
290290
ghcOptObjDir = toFlag odir
291291
}
292292

293-
componentGhcOptions :: Verbosity -> LocalBuildInfo
293+
componentGhcOptions :: Verbosity -> GhcImplInfo -> LocalBuildInfo
294294
-> BuildInfo -> ComponentLocalBuildInfo -> FilePath
295295
-> GhcOptions
296-
componentGhcOptions verbosity lbi bi clbi odir =
296+
componentGhcOptions verbosity implInfo lbi bi clbi odir =
297297
mempty {
298298
-- Respect -v0, but don't crank up verbosity on GHC if
299299
-- Cabal verbosity is requested. For that, use --ghc-option=-v instead!
@@ -316,6 +316,12 @@ componentGhcOptions verbosity lbi bi clbi odir =
316316
_ -> [],
317317
ghcOptNoCode = toFlag $ componentIsIndefinite clbi,
318318
ghcOptHideAllPackages = toFlag True,
319+
ghcOptWarnMissingHomeModules = case clbi of
320+
LibComponentLocalBuildInfo{} ->
321+
if flagWarnMissingHomeModules implInfo
322+
then toFlag True
323+
else mempty
324+
_ -> mempty,
319325
ghcOptPackageDBs = withPackageDB lbi,
320326
ghcOptPackages = toNubListR $ mkGhcOptPackages clbi,
321327
ghcOptSplitObjs = toFlag (splitObjs lbi),

Cabal/Distribution/Simple/GHCJS.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,9 @@ componentGhcOptions :: Verbosity -> LocalBuildInfo
823823
-> BuildInfo -> ComponentLocalBuildInfo -> FilePath
824824
-> GhcOptions
825825
componentGhcOptions verbosity lbi bi clbi odir =
826-
let opts = Internal.componentGhcOptions verbosity lbi bi clbi odir
826+
let opts = Internal.componentGhcOptions verbosity implInfo lbi bi clbi odir
827+
comp = compiler lbi
828+
implInfo = getImplInfo comp
827829
in opts { ghcOptExtra = ghcOptExtra opts `mappend` toNubListR
828830
(hcOptions GHCJS bi)
829831
}

Cabal/Distribution/Simple/Program/GHC.hs

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ data GhcOptions = GhcOptions {
110110
-- | Start with a clean package set; the @ghc -hide-all-packages@ flag
111111
ghcOptHideAllPackages :: Flag Bool,
112112

113+
-- | Warn about modules, not listed in command line
114+
ghcOptWarnMissingHomeModules :: Flag Bool,
115+
113116
-- | Don't automatically link in Haskell98 etc; the @ghc
114117
-- -no-auto-link-packages@ flag.
115118
ghcOptNoAutoLinkPackages :: Flag Bool,
@@ -434,6 +437,7 @@ renderGhcOptions comp _platform@(Platform _arch os) opts
434437
, concat [ ["-fno-code", "-fwrite-interface"] | flagBool ghcOptNoCode ]
435438

436439
, [ "-hide-all-packages" | flagBool ghcOptHideAllPackages ]
440+
, [ "-Wmissing-home-modules" | flagBool ghcOptWarnMissingHomeModules ]
437441
, [ "-no-auto-link-packages" | flagBool ghcOptNoAutoLinkPackages ]
438442

439443
, packageDbArgs implInfo (ghcOptPackageDBs opts)

0 commit comments

Comments
 (0)