summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZubin Duggal <zubin.duggal@gmail.com>2021-11-19 18:35:04 +0530
committerZubin Duggal <zubin.duggal@gmail.com>2022-05-13 13:24:50 +0530
commit5d4a13031941c952fa78b650be368dcbdcd57f19 (patch)
tree29124e720ff7ee5e100fc076295fce34c479245d
parent7b3c91b85e6fe6e69af9aaab8b25386e432d51d8 (diff)
downloadhaskell-5d4a13031941c952fa78b650be368dcbdcd57f19.tar.gz
hadrian: detect if 'main' is not a haskell file and add it to appropriate list of sources
(cherry picked from commit 2f0ceecc42789558c648c6dcff431d3c8ac3aa46)
-rw-r--r--driver/ghci/ghci-wrapper.cabal.in1
-rw-r--r--hadrian/src/Hadrian/Haskell/Cabal/Parse.hs16
-rw-r--r--utils/hp2ps/hp2ps.cabal2
-rw-r--r--utils/touchy/touchy.cabal1
-rw-r--r--utils/unlit/unlit.cabal3
5 files changed, 16 insertions, 7 deletions
diff --git a/driver/ghci/ghci-wrapper.cabal.in b/driver/ghci/ghci-wrapper.cabal.in
index 2616223ada..5a422aab9b 100644
--- a/driver/ghci/ghci-wrapper.cabal.in
+++ b/driver/ghci/ghci-wrapper.cabal.in
@@ -24,6 +24,5 @@ Executable ghci
buildable: False
Include-Dirs: ../utils
C-Sources:
- ghci.c
-- the following get copied from ../utils by hadrian
getLocation.c isMinTTY.c cwrapper.c
diff --git a/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs b/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
index 31e3fd70be..b017fb3701 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
@@ -265,10 +267,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 =
@@ -284,8 +294,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
diff --git a/utils/hp2ps/hp2ps.cabal b/utils/hp2ps/hp2ps.cabal
index 1b48694564..d317ac707d 100644
--- a/utils/hp2ps/hp2ps.cabal
+++ b/utils/hp2ps/hp2ps.cabal
@@ -15,7 +15,7 @@ Executable hp2ps
Main-Is: Main.c
extra-libraries: m
C-Sources:
- AreaBelow.c Curves.c Error.c Main.c
+ AreaBelow.c Curves.c Error.c
Reorder.c TopTwenty.c AuxFile.c Deviation.c
HpFile.c Marks.c Scale.c TraceElement.c
Axes.c Dimensions.c Key.c PsFile.c Shade.c
diff --git a/utils/touchy/touchy.cabal b/utils/touchy/touchy.cabal
index 21a774b1fa..5c28c664fc 100644
--- a/utils/touchy/touchy.cabal
+++ b/utils/touchy/touchy.cabal
@@ -13,4 +13,3 @@ build-type: Simple
Executable touchy
Default-Language: Haskell2010
Main-Is: touchy.c
- C-Sources: touchy.c
diff --git a/utils/unlit/unlit.cabal b/utils/unlit/unlit.cabal
index e49fd8558b..0707d5d95a 100644
--- a/utils/unlit/unlit.cabal
+++ b/utils/unlit/unlit.cabal
@@ -9,9 +9,10 @@ Synopsis: Literate program filter
Description: XXX
Category: Development
build-type: Simple
+extra-source-files: fs.h
Executable unlit
Default-Language: Haskell2010
Main-Is: unlit.c
- C-Sources: unlit.c, fs.c
+ C-Sources: fs.c
Includes: fs.h