summaryrefslogtreecommitdiff
path: root/Coolbal/Target/Executable.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2021-02-17 16:01:53 +0100
committerTom Smeding <tom@tomsmeding.com>2021-02-17 16:01:53 +0100
commit1a7c345d3d530c566840c72f59a932f292cefd09 (patch)
treea9a5d4d96b6ae0fcd0f632f427b52ed0c9fe954a /Coolbal/Target/Executable.hs
Initial
Diffstat (limited to 'Coolbal/Target/Executable.hs')
-rw-r--r--Coolbal/Target/Executable.hs40
1 files changed, 40 insertions, 0 deletions
diff --git a/Coolbal/Target/Executable.hs b/Coolbal/Target/Executable.hs
new file mode 100644
index 0000000..2e62953
--- /dev/null
+++ b/Coolbal/Target/Executable.hs
@@ -0,0 +1,40 @@
+module Coolbal.Target.Executable (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.Directory
+import Coolbal.Target
+
+
+makeExeTarget :: Executable -> CabalPlan -> Maybe ExeTarget
+makeExeTarget 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@Configured{} <- find ((== name) . ppName) (planPackages plan)
+ , Just language <- defaultLanguage bi
+ , True <- language `elem` knownLanguages
+ , Just flags <- lookup GHC (perCompilerFlavorToList (options bi))
+ = Just (ExeTarget
+ { exeTargetName = unUnqualComponentName (exeName exe)
+ , exeTargetPkgDbDir = currentHomeDirectory ++ "/.cabal/store/" ++ planCompiler plan ++ "/package.db"
+ , exeTargetDeps = ppDepends planpkg
+ , exeTargetLanguage = show language
+ , exeTargetMain = modulePath exe
+ , exeTargetModules = map Module.components (otherModules bi)
+ , exeTargetFlags = flags
+ })
+ | otherwise = Nothing