Skip to content

Commit

Permalink
Separate out module files vs data files (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdone committed Aug 15, 2015
1 parent 6ac73da commit 1f0d455
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 49 deletions.
5 changes: 3 additions & 2 deletions src/Stack/Build/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,10 @@ loadLocalPackage bopts targets (name, (lpv, gpkg)) = do
, lptbBenches = benches
}
mbuildCache <- tryGetBuildCache $ lpvRoot lpv
(componentFiles,mainFiles,extraFiles) <- getPackageFiles (packageFiles pkg) (lpvCabalFP lpv)
(modFiles,otherFiles,mainFiles,extraFiles) <- getPackageFiles (packageFiles pkg) (lpvCabalFP lpv)
let files =
mconcat (M.elems componentFiles) <>
mconcat (M.elems modFiles) <>
mconcat (M.elems otherFiles) <>
Set.map mainIsFile (mconcat (M.elems mainFiles)) <>
extraFiles
(isDirty, newBuildCache) <- checkBuildCache
Expand Down
8 changes: 4 additions & 4 deletions src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ data GhciPkgInfo = GhciPkgInfo
, ghciPkgOpts :: [String]
, ghciPkgDir :: Path Abs Dir
, ghciPkgModules :: Set ModuleName
, ghciPkgFiles :: Set (Path Abs File)
, ghciPkgModFiles :: Set (Path Abs File) -- ^ Module file paths.
, ghciPkgMainIs :: Map NamedComponent (Set (Path Abs File))
}

Expand Down Expand Up @@ -243,7 +243,7 @@ makeGhciPkgInfo sourceMap locals name cabalfp components = do
(componentsOpts,generalOpts) <-
getPackageOpts (packageOpts pkg) sourceMap locals cabalfp
componentsModules <- getPackageModules (packageModules pkg) cabalfp
(componentModFiles,mainIsFiles,_) <-
(componentModFiles,_,mainIsFiles,_) <-
getPackageFiles (packageFiles pkg) cabalfp
let filterWithinWantedComponents m =
M.elems
Expand All @@ -263,8 +263,8 @@ makeGhciPkgInfo sourceMap locals name cabalfp components = do
, ghciPkgDir = parent cabalfp
, ghciPkgModules = mconcat
(filterWithinWantedComponents componentsModules)
, ghciPkgFiles =
mconcat (filterWithinWantedComponents componentModFiles)
, ghciPkgModFiles = mconcat
(filterWithinWantedComponents componentModFiles)
, ghciPkgMainIs = M.map (S.map mainIsFile) mainIsFiles
}
where
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Ide.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ide targets useropts = do
map ("--ghc-option=" ++) (ghciPkgOpts pkg)
, mapMaybe
(fmap toFilePath . stripDir pwd)
(S.toList (ghciPkgFiles pkg) <>
(S.toList (ghciPkgModFiles pkg) <>
if paths_foo_exists
then [paths_foo]
else []))
Expand Down
86 changes: 44 additions & 42 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ resolvePackage packageConfig gpkg =
, packageFiles = GetPackageFiles $
\cabalfp ->
do distDir <- distDirFromDir (parent cabalfp)
(_,files,mains,extra) <-
(_,moduleFiles,files,mains,extra) <-
runReaderT
(packageDescModulesAndFiles pkg)
(cabalfp, buildDir distDir)
return (files, mains, S.singleton cabalfp <> extra)
return (moduleFiles, files, mains, S.singleton cabalfp <> extra)
, packageModules = GetPackageModules $
\cabalfp ->
do distDir <- distDirFromDir (parent cabalfp)
(modules,_,_,_) <-
(modules,_,_,_,_) <-
runReaderT
(packageDescModulesAndFiles pkg)
(cabalfp, buildDir distDir)
Expand Down Expand Up @@ -360,50 +360,52 @@ allBuildInfo' pkg_descr = [ bi | Just lib <- [library pkg_descr]
packageDescModulesAndFiles
:: (MonadLogger m, MonadIO m, MonadThrow m, MonadReader (Path Abs File, Path Abs Dir) m, MonadCatch m)
=> PackageDescription
-> m (Map NamedComponent (Set ModuleName), Map NamedComponent (Set (Path Abs File)), Map NamedComponent (Set MainIs), Set (Path Abs File))
-> m (Map NamedComponent (Set ModuleName), Map NamedComponent (Set (Path Abs File)), Map NamedComponent (Set (Path Abs File)), Map NamedComponent (Set MainIs), Set (Path Abs File))
packageDescModulesAndFiles pkg = do
(libraryMods,libFiles,_) <-
(libraryMods,libModFiles,libOtherFiles,_) <-
maybe
(return (M.empty, M.empty, M.empty))
(return (M.empty, M.empty, M.empty, M.empty))
(asModuleAndFileMap libComponent libraryFiles)
(library pkg)
(executableMods,exeFiles,exeMainIs) <-
(executableMods,exeModFiles,exeOtherFiles,exeMainIs) <-
liftM
foldTriples
(mapM
(asModuleAndFileMap exeComponent executableFiles)
(executables pkg))
(testMods,testFps,testMainIs) <-
(testMods,testModFps,testOtherFps,testMainIs) <-
liftM
foldTriples
(mapM (asModuleAndFileMap testComponent testFiles) (testSuites pkg))
(benchModules,benchFiles,benchMainIs) <-
(benchModules,benchModFiles,benchOtherFiles,benchMainIs) <-
liftM
foldTriples
(mapM
(asModuleAndFileMap benchComponent benchmarkFiles)
(benchmarks pkg))
dfiles <- resolveGlobFiles (map (dataDir pkg FilePath.</>) (dataFiles pkg))
let modules = libraryMods <> executableMods <> testMods <> benchModules
files = libFiles <> exeFiles <> testFps <> benchFiles
moduleFiles = libModFiles <> exeModFiles <> testModFps <> benchModFiles
otherFiles = libOtherFiles <> exeOtherFiles <> testOtherFps <> benchOtherFiles
mains = exeMainIs <> benchMainIs <> testMainIs
return (modules, files, mains, dfiles)
return (modules, moduleFiles, otherFiles, mains, dfiles)
where
libComponent = const CLib
exeComponent = CExe . T.pack . exeName
testComponent = CTest . T.pack . testName
benchComponent = CBench . T.pack . benchmarkName
asModuleAndFileMap label f lib = do
(a,b,c) <- f lib
(a,b,c, d) <- f lib
return
( M.singleton (label lib) a
, M.singleton (label lib) b
, M.singleton (label lib) c)
, M.singleton (label lib) c
, M.singleton (label lib) d)
foldTriples =
foldl'
(\(a,b,c) (x,y,z) ->
(a <> x, b <> y, c <> z))
(M.empty, M.empty, M.empty)
(\(a,b,c,d) (x,y,z,k) ->
(a <> x, b <> y, c <> z, d <> k))
(M.empty, M.empty, M.empty, M.empty)

-- | Resolve globbing of files (e.g. data files) to absolute paths.
resolveGlobFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File, Path Abs Dir) m,MonadCatch m)
Expand Down Expand Up @@ -469,19 +471,19 @@ matchDirFileGlob_ dir filepath = case parseFileGlob filepath of

-- | Get all files referenced by the benchmark.
benchmarkFiles :: (MonadLogger m, MonadIO m, MonadThrow m, MonadReader (Path Abs File, Path Abs Dir) m)
=> Benchmark -> m (Set ModuleName,Set (Path Abs File),Set MainIs)
=> Benchmark -> m (Set ModuleName,Set (Path Abs File),Set (Path Abs File),Set MainIs)
benchmarkFiles bench = do
dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
dir <- asks (parent . fst)
(rmodules,rfiles) <-
(rmodules,modFiles,thFiles) <-
resolveFilesAndDeps
(Just $ benchmarkName bench)
(dirs ++ [dir])
bnames
haskellModuleExts
mainFiles <- resolveFiles (dirs ++ [dir]) exposed haskellModuleExts
cfiles <- buildCSources build
return (rmodules, rfiles <> cfiles, S.map MainIs (S.fromList mainFiles))
return (rmodules, modFiles, cfiles <> thFiles, S.map MainIs (S.fromList mainFiles))
where
exposed =
case benchmarkInterface bench of
Expand All @@ -491,20 +493,22 @@ benchmarkFiles bench = do
build = benchmarkBuildInfo bench

-- | Get all files referenced by the test.
testFiles :: (MonadLogger m, MonadIO m, MonadThrow m, MonadReader (Path Abs File, Path Abs Dir) m)
=> TestSuite -> m (Set ModuleName,Set (Path Abs File),Set MainIs)
testFiles
:: (MonadLogger m, MonadIO m, MonadThrow m, MonadReader (Path Abs File, Path Abs Dir) m)
=> TestSuite
-> m (Set ModuleName, Set (Path Abs File), Set (Path Abs File), Set MainIs)
testFiles test = do
dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
dir <- asks (parent . fst)
(modules,rfiles) <-
(modules,modFiles,thFiles) <-
resolveFilesAndDeps
(Just $ testName test)
(dirs ++ [dir])
bnames
haskellModuleExts
mainFiles <- resolveFiles (dirs ++ [dir]) exposed haskellModuleExts
cfiles <- buildCSources build
return (modules, rfiles <> cfiles, S.map MainIs (S.fromList mainFiles))
return (modules, modFiles, cfiles <> thFiles, S.map MainIs (S.fromList mainFiles))
where
exposed =
case testInterface test of
Expand All @@ -515,12 +519,14 @@ testFiles test = do
build = testBuildInfo test

-- | Get all files referenced by the executable.
executableFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File, Path Abs Dir) m)
=> Executable -> m (Set ModuleName,Set (Path Abs File),Set MainIs)
executableFiles
:: (MonadLogger m, MonadIO m, MonadThrow m, MonadReader (Path Abs File, Path Abs Dir) m)
=> Executable
-> m (Set ModuleName, Set (Path Abs File), Set (Path Abs File), Set MainIs)
executableFiles exe = do
dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
dir <- asks (parent . fst)
(modules,rfiles) <-
(modules,modFiles,thFiles) <-
resolveFilesAndDeps
(Just $ exeName exe)
(dirs ++ [dir])
Expand All @@ -529,26 +535,22 @@ executableFiles exe = do
mainFiles <-
resolveFiles (dirs ++ [dir]) [Right (modulePath exe)] haskellModuleExts
cfiles <- buildCSources build
return (modules, rfiles <> cfiles, S.map MainIs (S.fromList mainFiles))
return (modules, modFiles, cfiles <> thFiles, S.map MainIs (S.fromList mainFiles))
where
build = buildInfo exe

-- | Get all files referenced by the library.
libraryFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File, Path Abs Dir) m)
=> Library -> m (Set ModuleName,Set (Path Abs File), Set MainIs)
libraryFiles lib =
do dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
dir <- asks (parent . fst)
(modules,rfiles) <- resolveFilesAndDeps
Nothing
(dirs ++ [dir])
names
haskellModuleExts
cfiles <- buildCSources build
return (modules,rfiles <> cfiles, mempty)
=> Library -> m (Set ModuleName,Set (Path Abs File),Set (Path Abs File), Set MainIs)
libraryFiles lib = do
dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
dir <- asks (parent . fst)
(modules,modFiles,thFiles) <-
resolveFilesAndDeps Nothing (dirs ++ [dir]) names haskellModuleExts
cfiles <- buildCSources build
return (modules, modFiles, cfiles <> thFiles, mempty)
where
names =
concat [bnames,exposed]
names = concat [bnames, exposed]
exposed = map Left (exposedModules lib)
bnames = map Left (otherModules build)
build = libBuildInfo lib
Expand Down Expand Up @@ -685,11 +687,11 @@ resolveFilesAndDeps
-> [Path Abs Dir] -- ^ Directories to look in.
-> [Either ModuleName String] -- ^ Base names.
-> [Text] -- ^ Extentions.
-> m (Set ModuleName,Set (Path Abs File))
-> m (Set ModuleName,Set (Path Abs File),Set (Path Abs File))
resolveFilesAndDeps component dirs names0 exts = do
(moduleFiles,thFiles,foundModules) <- loop names0 S.empty
warnUnlisted component (lefts names0) foundModules
return (foundModules, moduleFiles <> S.fromList thFiles)
return (foundModules, moduleFiles, S.fromList thFiles)
where
loop [] doneModules = return (S.empty, [], doneModules)
loop names doneModules0 = do
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Types/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ newtype GetPackageFiles = GetPackageFiles
{ getPackageFiles :: forall m env. (MonadIO m, MonadLogger m, MonadThrow m, MonadCatch m, MonadReader env m, HasPlatform env, HasEnvConfig env)
=> Path Abs File
-> m (Map NamedComponent (Set (Path Abs File))
,Map NamedComponent (Set (Path Abs File))
,Map NamedComponent (Set MainIs)
,Set (Path Abs File))
}
Expand Down

0 comments on commit 1f0d455

Please sign in to comment.