Skip to content

Commit 31712d3

Browse files
committed
Warnings for unlisted modules (commercialhaskell#32,commercialhaskell#105)
1 parent 829f7de commit 31712d3

2 files changed

Lines changed: 93 additions & 81 deletions

File tree

src/Stack/Package.hs

Lines changed: 92 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -412,22 +412,26 @@ benchmarkFiles :: (MonadLogger m, MonadIO m, MonadThrow m, MonadReader (Path Abs
412412
benchmarkFiles ty bench = do
413413
dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
414414
dir <- asks (parent . fst)
415-
exposed <-
416-
resolveFilesAndDeps
417-
ty
418-
(Just $ benchmarkName bench)
419-
(dirs ++ [dir])
420-
(case benchmarkInterface bench of
421-
BenchmarkExeV10 _ fp ->
422-
[Right fp]
423-
BenchmarkUnsupported _ ->
424-
[])
425-
haskellModuleExts
426-
bfiles <- buildFiles ty (Just $ benchmarkName bench) dir build
427-
case ty of
428-
AllFiles -> return (concat [bfiles,exposed])
429-
Modules -> return (concat [bfiles])
415+
rfiles <- resolveFilesAndDeps
416+
ty
417+
(Just $ benchmarkName bench)
418+
(dirs ++ [dir])
419+
names
420+
haskellModuleExts
421+
cfiles <- buildCSources ty build
422+
return (rfiles ++ cfiles)
430423
where
424+
names =
425+
case ty of
426+
AllFiles -> concat [bnames,exposed]
427+
Modules -> concat [bnames]
428+
exposed =
429+
case benchmarkInterface bench of
430+
BenchmarkExeV10 _ fp ->
431+
[Right fp]
432+
BenchmarkUnsupported _ ->
433+
[]
434+
bnames = map Left (otherModules build)
431435
build = benchmarkBuildInfo bench
432436

433437
-- | Get all files referenced by the test.
@@ -436,24 +440,28 @@ testFiles :: (MonadLogger m, MonadIO m, MonadThrow m, MonadReader (Path Abs File
436440
testFiles ty test = do
437441
dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
438442
dir <- asks (parent . fst)
439-
exposed <-
440-
resolveFilesAndDeps
441-
ty
442-
(Just $ testName test)
443-
(dirs ++ [dir])
444-
(case testInterface test of
445-
TestSuiteExeV10 _ fp ->
446-
[Right fp]
447-
TestSuiteLibV09 _ mn ->
448-
[Left mn]
449-
TestSuiteUnsupported _ ->
450-
[])
451-
haskellModuleExts
452-
bfiles <- buildFiles ty (Just $ testName test) dir build
453-
case ty of
454-
AllFiles -> return (concat [bfiles,exposed])
455-
Modules -> return (concat [bfiles])
443+
rfiles <- resolveFilesAndDeps
444+
ty
445+
(Just $ testName test)
446+
(dirs ++ [dir])
447+
names
448+
haskellModuleExts
449+
cfiles <- buildCSources ty build
450+
return (rfiles ++ cfiles)
456451
where
452+
names =
453+
case ty of
454+
AllFiles -> concat [bnames,exposed]
455+
Modules -> concat [bnames]
456+
exposed =
457+
case testInterface test of
458+
TestSuiteExeV10 _ fp ->
459+
[Right fp]
460+
TestSuiteLibV09 _ mn ->
461+
[Left mn]
462+
TestSuiteUnsupported _ ->
463+
[]
464+
bnames = map Left (otherModules build)
457465
build = testBuildInfo test
458466

459467
-- | Get all files referenced by the executable.
@@ -462,53 +470,51 @@ executableFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs F
462470
executableFiles ty exe =
463471
do dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
464472
dir <- asks (parent . fst)
465-
exposed <-
466-
resolveFilesAndDeps
473+
rfiles <- resolveFilesAndDeps
467474
ty
468475
(Just $ exeName exe)
469476
(dirs ++ [dir])
470-
[Right (modulePath exe)]
477+
names
471478
haskellModuleExts
472-
bfiles <- buildFiles ty (Just $ exeName exe) dir build
473-
case ty of
474-
AllFiles -> return (concat [bfiles,exposed])
475-
Modules -> return (concat [bfiles])
476-
where build = buildInfo exe
479+
cfiles <- buildCSources ty build
480+
return (rfiles ++ cfiles)
481+
where
482+
names =
483+
case ty of
484+
AllFiles -> concat [bnames,exposed]
485+
Modules -> concat [bnames]
486+
bnames = map Left (otherModules build)
487+
exposed = [Right (modulePath exe)]
488+
build = buildInfo exe
477489

478490
-- | Get all files referenced by the library.
479491
libraryFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File, Path Abs Dir) m)
480492
=> CabalFileType -> Library -> m [Path Abs File]
481493
libraryFiles ty lib =
482494
do dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
483495
dir <- asks (parent . fst)
484-
exposed <- resolveFilesAndDeps
485-
ty
486-
Nothing
487-
(dirs ++ [dir])
488-
(map Left (exposedModules lib))
489-
haskellModuleExts
490-
bfiles <- buildFiles ty Nothing dir build
491-
case ty of
492-
AllFiles -> return (concat [bfiles,exposed])
493-
Modules -> return (concat [bfiles,exposed])
494-
where build = libBuildInfo lib
495-
496-
-- | Get all files in a build.
497-
buildFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File, Path Abs Dir) m)
498-
=> CabalFileType -> Maybe (String) -> Path Abs Dir -> BuildInfo -> m [Path Abs File]
499-
buildFiles ty component dir build = do
500-
dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
501-
other <-
502-
resolveFilesAndDeps
503-
ty
504-
component
505-
(dirs ++ [dir])
506-
(map Left (otherModules build))
507-
haskellModuleExts
508-
cSources' <- mapMaybeM resolveFileOrWarn (cSources build)
509-
case ty of
510-
Modules -> return other
511-
AllFiles -> return (other ++ cSources')
496+
rfiles <- resolveFilesAndDeps
497+
ty
498+
Nothing
499+
(dirs ++ [dir])
500+
names
501+
haskellModuleExts
502+
cfiles <- buildCSources ty build
503+
return (rfiles ++ cfiles)
504+
where
505+
names =
506+
case ty of
507+
AllFiles -> concat [bnames,exposed]
508+
Modules -> concat [bnames,exposed]
509+
exposed = map Left (exposedModules lib)
510+
bnames = map Left (otherModules build)
511+
build = libBuildInfo lib
512+
513+
-- | Get all C sources in a build.
514+
buildCSources :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File, Path Abs Dir) m)
515+
=> CabalFileType -> BuildInfo -> m [Path Abs File]
516+
buildCSources Modules _ = return []
517+
buildCSources AllFiles build = mapMaybeM resolveFileOrWarn (cSources build)
512518

513519
-- | Get all dependencies of a package, including library,
514520
-- executables, tests, benchmarks.
@@ -639,18 +645,24 @@ resolveFilesAndDeps
639645
-> [Text] -- ^ Extentions.
640646
-> m [Path Abs File]
641647
resolveFilesAndDeps ty component dirs names0 exts = do
642-
(moduleFiles,thFiles,_) <- loop names0 S.empty
643-
-- cabalfp <- asks fst
644-
-- forM_ (S.toList (foundModules `S.difference` (S.fromList (lefts names0)))) $
645-
-- \unlistedModule ->
646-
-- $(logWarn) $
647-
-- T.pack $
648-
-- "XXX Warning: module not listed in " ++
649-
-- toFilePath (filename cabalfp) ++
650-
-- (case component of
651-
-- Nothing -> " for library"
652-
-- Just c -> " for " ++ c) ++
653-
-- " (add it to other-modules): " ++ display unlistedModule ++ "."
648+
(moduleFiles,thFiles,foundModules) <- loop names0 S.empty
649+
cabalfp <- asks fst
650+
let unlistedModules =
651+
foundModules `S.difference` (S.fromList (lefts names0))
652+
unless (S.null unlistedModules) $
653+
$(logWarn) $
654+
T.pack $
655+
"Warning: " ++
656+
(if S.size unlistedModules == 1
657+
then "module"
658+
else "modules") ++
659+
" not listed in " ++
660+
toFilePath (filename cabalfp) ++
661+
(case component of
662+
Nothing -> " for library"
663+
Just c -> " for '" ++ c ++ "'") ++
664+
" component (add to other-modules):\n " ++
665+
intercalate "\n " (map display (S.toList unlistedModules))
654666
return (S.toList moduleFiles ++ thFiles)
655667
where
656668
loop [] doneModules = return (S.empty, [], doneModules)
@@ -707,7 +719,6 @@ resolveFilesAndDeps ty component dirs names0 exts = do
707719
decodeUtf8 . C8.dropWhile (/= '"'))) $
708720
filter ("addDependentFile \"" `C8.isPrefixOf`) dumpHI
709721
Modules -> []
710-
--liftIO $ putStrLn $ "XXX dumpHI " ++ show dumpHIPath ++ "\n XXX moduleDeps=" ++ show moduleDeps ++ "\n XXX thDeps=" ++ show thDeps
711722
return
712723
(moduleDeps, thDeps)
713724
getDumpHIDir = do

stack.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ executable stack
179179
ghc-options: -Wall -threaded -rtsopts
180180
other-modules: Plugins
181181
Plugins.Commands
182+
Paths_stack
182183

183184
build-depends: base >=4.7 && < 5
184185
, bytestring >= 0.10.4.0

0 commit comments

Comments
 (0)