summaryrefslogtreecommitdiff
path: root/Coolbal/Target/Executable/Make.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2021-07-11 17:56:34 +0200
committerTom Smeding <tom@tomsmeding.com>2021-07-11 17:56:34 +0200
commitf57e800a1d1a8e9f2bed34428f7f58a375f178fb (patch)
tree7164b0a9bcf03703a6a7f44f5fa04e5847d876e5 /Coolbal/Target/Executable/Make.hs
parent317f1e27688a082926f39ec897f5a38d01a07ce7 (diff)
WIP splitting of Target module and towards parallel buildsHEADmaster
Diffstat (limited to 'Coolbal/Target/Executable/Make.hs')
-rw-r--r--Coolbal/Target/Executable/Make.hs48
1 files changed, 48 insertions, 0 deletions
diff --git a/Coolbal/Target/Executable/Make.hs b/Coolbal/Target/Executable/Make.hs
new file mode 100644
index 0000000..5bbb80e
--- /dev/null
+++ b/Coolbal/Target/Executable/Make.hs
@@ -0,0 +1,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