diff options
author | Zubin Duggal <zubin.duggal@gmail.com> | 2021-11-19 18:35:04 +0530 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2022-02-20 19:06:19 +0000 |
commit | 2f0ceecc42789558c648c6dcff431d3c8ac3aa46 (patch) | |
tree | 1f0e5d7d7eea7c1e930c2e56fb249a7561f00ef6 /hadrian/src | |
parent | 6b468f7f6185e68ccdea547beb090092b77cf87e (diff) | |
download | haskell-2f0ceecc42789558c648c6dcff431d3c8ac3aa46.tar.gz |
hadrian: detect if 'main' is not a haskell file and add it to appropriate list of sources
Diffstat (limited to 'hadrian/src')
-rw-r--r-- | hadrian/src/Hadrian/Haskell/Cabal/Parse.hs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs b/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs index d6dc842d1b..4e3bd5be17 100644 --- a/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs +++ b/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs @@ -194,6 +194,8 @@ registerPackage context@Context {..} = do traced "cabal-register" $ C.defaultMainWithHooksNoReadArgs C.autoconfUserHooks gpd [ "register", "--builddir", ctxPath, v ] +-- | What type of file is Main +data MainSourceType = HsMain | CppMain | CMain -- | Parse the 'ContextData' of a given 'Context'. resolveContextData :: Context -> Action ContextData @@ -270,10 +272,18 @@ resolveContextData context@Context {..} = do (buildInfo, modules, mainIs) = biModules pd' + classifyMain :: FilePath -> MainSourceType + classifyMain fp + | takeExtension fp `elem` [".hs", ".lhs"] = HsMain + | takeExtension fp `elem` [".cpp", ".cxx", ".c++"]= CppMain + | otherwise = CMain + + main_src = fmap (first C.display) mainIs + in return $ ContextData { dependencies = deps , componentId = C.localCompatPackageKey lbi' - , mainIs = fmap (first C.display) mainIs + , mainIs = main_src , modules = map C.display modules , otherModules = map C.display $ C.otherModules buildInfo , srcDirs = @@ -289,8 +299,8 @@ resolveContextData context@Context {..} = do , extraLibs = C.extraLibs buildInfo , extraLibDirs = C.extraLibDirs buildInfo , asmSrcs = C.asmSources buildInfo - , cSrcs = C.cSources buildInfo - , cxxSrcs = C.cxxSources buildInfo + , cSrcs = C.cSources buildInfo ++ [ ms | Just (_,ms) <- pure main_src, CMain <- pure (classifyMain ms)] + , cxxSrcs = C.cxxSources buildInfo ++ [ ms | Just (_,ms) <- pure main_src, CppMain <- pure (classifyMain ms)] , cmmSrcs = C.cmmSources buildInfo , hcOpts = C.programDefaultArgs ghcProg ++ C.hcOptions C.GHC buildInfo |