1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
module Coolbal.Target.Executable.Make (makeExeTarget) where
import Data.List (find)
import Distribution.Compiler (perCompilerFlavorToList, CompilerFlavor(GHC))
import qualified Distribution.ModuleName as Module
import Distribution.Types.BuildInfo (BuildInfo(..))
import Distribution.Types.Executable (Executable(..))
import Distribution.Types.ExecutableScope (ExecutableScope(ExecutablePublic))
import Distribution.Types.UnqualComponentName (unUnqualComponentName)
import Language.Haskell.Extension (knownLanguages)
import Coolbal.CabalPlan
import Coolbal.DataVersionTag
import Coolbal.Directory
import Coolbal.Options (Flags)
import Coolbal.Target.Executable
makeExeTarget :: Flags -> FilePath -> Executable -> CabalPlan -> IO (Maybe ExeTarget)
makeExeTarget flags projdir exe plan
| exeScope exe == ExecutablePublic
, let bi = buildInfo exe
, buildable bi
, all (null . ($ bi)) [asmSources, cmmSources, cSources, cxxSources, jsSources]
, all (null . ($ bi)) [virtualModules, autogenModules]
, null (defaultExtensions bi)
, all (null . ($ bi)) [extraLibs, extraBundledLibs]
, let name = unUnqualComponentName (exeName exe)
, Just planpkg <- find ((== name) . ppName) (planPackages plan)
, Just language <- defaultLanguage bi
, True <- language `elem` knownLanguages
, Just ghcFlags <- lookup GHC (perCompilerFlavorToList (options bi))
, Just deps <- ppDepends planpkg
= do let ets = ExeTargetStore
{ _etsVersionTag = DataVersionTag
, etsName = unUnqualComponentName (exeName exe)
, etsPkgDbDir = currentHomeDirectory ++ "/.cabal/store/" ++ planCompiler plan ++ "/package.db"
, etsDeps = deps
, etsLanguage = show language
, etsMain = modulePath exe
, etsSrcDirs = hsSourceDirs bi
, etsModules = map Module.components (otherModules bi)
, etsFlags = ghcFlags
}
ebs = exeBuildSetup projdir ets
depgraph <- exeDepGraph flags ets ebs
return (Just (elaborateExeTargetWithEBS ebs (ets { etsModules = depgraph })))
| otherwise = return Nothing
|