Commit fb514630 authored by byorgey's avatar byorgey Committed by Mikhail Glushenkov
Browse files

init: Only add exposed-modules which are in an hs-source-dir

Only those modules found in a directory in hs-source-dirs will be added
to exposed-modules.  If a directory 'src' is found it will be used as
hs-source-dirs (note in this case any .hs files in the root directory
will NOT be added to exposed-modules).  If any directories are specified
on the command line with --source-dir, they will be used.  If no
directories are specified on the command line and there is no directory
named src, the root directory will be used.

Fixes #3484.
parent 9382e60d
......@@ -29,7 +29,7 @@ import System.Directory
( getCurrentDirectory, doesDirectoryExist, doesFileExist, copyFile
, getDirectoryContents, createDirectoryIfMissing )
import System.FilePath
( (</>), (<.>), takeBaseName )
( (</>), (<.>), takeBaseName, equalFilePath )
import Data.Time
( getCurrentTime, utcToLocalTime, toGregorian, localDay, getCurrentTimeZone )
......@@ -381,13 +381,20 @@ guessSourceDir flags = do
then Just "src"
else Nothing
-- | Check whether a potential source file is located in one of the
-- source directories.
isSourceFile :: Maybe [FilePath] -> SourceFileEntry -> Bool
isSourceFile Nothing sf = isSourceFile (Just ["."]) sf
isSourceFile (Just srcDirs) sf = any (equalFilePath (relativeSourcePath sf)) srcDirs
-- | Get the list of exposed modules and extra tools needed to build them.
getModulesBuildToolsAndDeps :: InstalledPackageIndex -> InitFlags -> IO InitFlags
getModulesBuildToolsAndDeps pkgIx flags = do
dir <- maybe getCurrentDirectory return . flagToMaybe $ packageDir flags
-- TODO: really should use guessed source roots.
sourceFiles <- scanForModules dir
sourceFiles0 <- scanForModules dir
let sourceFiles = filter (isSourceFile (sourceDirs flags)) sourceFiles0
Just mods <- return (exposedModules flags)
?>> (return . Just . map moduleName $ sourceFiles)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment