Skip to content

Commit 0279264

Browse files
committed
Warnings for unlisted modules (#32,#105)
1 parent 9f3b0bc commit 0279264

File tree

2 files changed

+93
-81
lines changed

2 files changed

+93
-81
lines changed

src/Stack/Package.hs

Lines changed: 92 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -493,22 +493,26 @@ benchmarkFiles :: (MonadLogger m, MonadIO m, MonadThrow m, MonadReader (Path Abs
493493
benchmarkFiles ty bench = do
494494
dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
495495
dir <- asks (parent . fst)
496-
exposed <-
497-
resolveFilesAndDeps
498-
ty
499-
(Just $ benchmarkName bench)
500-
(dirs ++ [dir])
501-
(case benchmarkInterface bench of
502-
BenchmarkExeV10 _ fp ->
503-
[Right fp]
504-
BenchmarkUnsupported _ ->
505-
[])
506-
haskellModuleExts
507-
bfiles <- buildFiles ty (Just $ benchmarkName bench) dir build
508-
case ty of
509-
AllFiles -> return (concat [bfiles,exposed])
510-
Modules -> return (concat [bfiles])
496+
rfiles <- resolveFilesAndDeps
497+
ty
498+
(Just $ benchmarkName bench)
499+
(dirs ++ [dir])
500+
names
501+
haskellModuleExts
502+
cfiles <- buildCSources ty build
503+
return (rfiles ++ cfiles)
511504
where
505+
names =
506+
case ty of
507+
AllFiles -> concat [bnames,exposed]
508+
Modules -> concat [bnames]
509+
exposed =
510+
case benchmarkInterface bench of
511+
BenchmarkExeV10 _ fp ->
512+
[Right fp]
513+
BenchmarkUnsupported _ ->
514+
[]
515+
bnames = map Left (otherModules build)
512516
build = benchmarkBuildInfo bench
513517

514518
-- | Get all files referenced by the test.
@@ -517,24 +521,28 @@ testFiles :: (MonadLogger m, MonadIO m, MonadThrow m, MonadReader (Path Abs File
517521
testFiles ty test = do
518522
dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
519523
dir <- asks (parent . fst)
520-
exposed <-
521-
resolveFilesAndDeps
522-
ty
523-
(Just $ testName test)
524-
(dirs ++ [dir])
525-
(case testInterface test of
526-
TestSuiteExeV10 _ fp ->
527-
[Right fp]
528-
TestSuiteLibV09 _ mn ->
529-
[Left mn]
530-
TestSuiteUnsupported _ ->
531-
[])
532-
haskellModuleExts
533-
bfiles <- buildFiles ty (Just $ testName test) dir build
534-
case ty of
535-
AllFiles -> return (concat [bfiles,exposed])
536-
Modules -> return (concat [bfiles])
524+
rfiles <- resolveFilesAndDeps
525+
ty
526+
(Just $ testName test)
527+
(dirs ++ [dir])
528+
names
529+
haskellModuleExts
530+
cfiles <- buildCSources ty build
531+
return (rfiles ++ cfiles)
537532
where
533+
names =
534+
case ty of
535+
AllFiles -> concat [bnames,exposed]
536+
Modules -> concat [bnames]
537+
exposed =
538+
case testInterface test of
539+
TestSuiteExeV10 _ fp ->
540+
[Right fp]
541+
TestSuiteLibV09 _ mn ->
542+
[Left mn]
543+
TestSuiteUnsupported _ ->
544+
[]
545+
bnames = map Left (otherModules build)
538546
build = testBuildInfo test
539547

540548
-- | Get all files referenced by the executable.
@@ -543,53 +551,51 @@ executableFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs F
543551
executableFiles ty exe =
544552
do dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
545553
dir <- asks (parent . fst)
546-
exposed <-
547-
resolveFilesAndDeps
554+
rfiles <- resolveFilesAndDeps
548555
ty
549556
(Just $ exeName exe)
550557
(dirs ++ [dir])
551-
[Right (modulePath exe)]
558+
names
552559
haskellModuleExts
553-
bfiles <- buildFiles ty (Just $ exeName exe) dir build
554-
case ty of
555-
AllFiles -> return (concat [bfiles,exposed])
556-
Modules -> return (concat [bfiles])
557-
where build = buildInfo exe
560+
cfiles <- buildCSources ty build
561+
return (rfiles ++ cfiles)
562+
where
563+
names =
564+
case ty of
565+
AllFiles -> concat [bnames,exposed]
566+
Modules -> concat [bnames]
567+
bnames = map Left (otherModules build)
568+
exposed = [Right (modulePath exe)]
569+
build = buildInfo exe
558570

559571
-- | Get all files referenced by the library.
560572
libraryFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File, Path Abs Dir) m)
561573
=> CabalFileType -> Library -> m [Path Abs File]
562574
libraryFiles ty lib =
563575
do dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
564576
dir <- asks (parent . fst)
565-
exposed <- resolveFilesAndDeps
566-
ty
567-
Nothing
568-
(dirs ++ [dir])
569-
(map Left (exposedModules lib))
570-
haskellModuleExts
571-
bfiles <- buildFiles ty Nothing dir build
572-
case ty of
573-
AllFiles -> return (concat [bfiles,exposed])
574-
Modules -> return (concat [bfiles,exposed])
575-
where build = libBuildInfo lib
576-
577-
-- | Get all files in a build.
578-
buildFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File, Path Abs Dir) m)
579-
=> CabalFileType -> Maybe (String) -> Path Abs Dir -> BuildInfo -> m [Path Abs File]
580-
buildFiles ty component dir build = do
581-
dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
582-
other <-
583-
resolveFilesAndDeps
584-
ty
585-
component
586-
(dirs ++ [dir])
587-
(map Left (otherModules build))
588-
haskellModuleExts
589-
cSources' <- mapMaybeM resolveFileOrWarn (cSources build)
590-
case ty of
591-
Modules -> return other
592-
AllFiles -> return (other ++ cSources')
577+
rfiles <- resolveFilesAndDeps
578+
ty
579+
Nothing
580+
(dirs ++ [dir])
581+
names
582+
haskellModuleExts
583+
cfiles <- buildCSources ty build
584+
return (rfiles ++ cfiles)
585+
where
586+
names =
587+
case ty of
588+
AllFiles -> concat [bnames,exposed]
589+
Modules -> concat [bnames,exposed]
590+
exposed = map Left (exposedModules lib)
591+
bnames = map Left (otherModules build)
592+
build = libBuildInfo lib
593+
594+
-- | Get all C sources in a build.
595+
buildCSources :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File, Path Abs Dir) m)
596+
=> CabalFileType -> BuildInfo -> m [Path Abs File]
597+
buildCSources Modules _ = return []
598+
buildCSources AllFiles build = mapMaybeM resolveFileOrWarn (cSources build)
593599

594600
-- | Get all dependencies of a package, including library,
595601
-- executables, tests, benchmarks.
@@ -720,18 +726,24 @@ resolveFilesAndDeps
720726
-> [Text] -- ^ Extentions.
721727
-> m [Path Abs File]
722728
resolveFilesAndDeps ty component dirs names0 exts = do
723-
(moduleFiles,thFiles,_) <- loop names0 S.empty
724-
-- cabalfp <- asks fst
725-
-- forM_ (S.toList (foundModules `S.difference` (S.fromList (lefts names0)))) $
726-
-- \unlistedModule ->
727-
-- $(logWarn) $
728-
-- T.pack $
729-
-- "XXX Warning: module not listed in " ++
730-
-- toFilePath (filename cabalfp) ++
731-
-- (case component of
732-
-- Nothing -> " for library"
733-
-- Just c -> " for " ++ c) ++
734-
-- " (add it to other-modules): " ++ display unlistedModule ++ "."
729+
(moduleFiles,thFiles,foundModules) <- loop names0 S.empty
730+
cabalfp <- asks fst
731+
let unlistedModules =
732+
foundModules `S.difference` (S.fromList (lefts names0))
733+
unless (S.null unlistedModules) $
734+
$(logWarn) $
735+
T.pack $
736+
"Warning: " ++
737+
(if S.size unlistedModules == 1
738+
then "module"
739+
else "modules") ++
740+
" not listed in " ++
741+
toFilePath (filename cabalfp) ++
742+
(case component of
743+
Nothing -> " for library"
744+
Just c -> " for '" ++ c ++ "'") ++
745+
" component (add to other-modules):\n " ++
746+
intercalate "\n " (map display (S.toList unlistedModules))
735747
return (S.toList moduleFiles ++ thFiles)
736748
where
737749
loop [] doneModules = return (S.empty, [], doneModules)
@@ -788,7 +800,6 @@ resolveFilesAndDeps ty component dirs names0 exts = do
788800
decodeUtf8 . C8.dropWhile (/= '"'))) $
789801
filter ("addDependentFile \"" `C8.isPrefixOf`) dumpHI
790802
Modules -> []
791-
--liftIO $ putStrLn $ "XXX dumpHI " ++ show dumpHIPath ++ "\n XXX moduleDeps=" ++ show moduleDeps ++ "\n XXX thDeps=" ++ show thDeps
792803
return
793804
(moduleDeps, thDeps)
794805
getDumpHIDir = do

stack.cabal

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

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

0 commit comments

Comments
 (0)