Skip to content

Commit a275708

Browse files
committed
Filter out files that are not ending in .c from c-sources
fixes #9190
1 parent 9faa4db commit a275708

File tree

2 files changed

+58
-52
lines changed

2 files changed

+58
-52
lines changed

Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ tests = testGroup "Distribution.Utils.Structured"
2929
, testCase "GenericPackageDescription" $
3030
md5Check (Proxy :: Proxy GenericPackageDescription) 0x8d8f340f10a58b8d8a87bf42213dac89
3131
, testCase "LocalBuildInfo" $
32-
md5Check (Proxy :: Proxy LocalBuildInfo) 0xbb22c3258d3092f31e992bc093d09170
32+
md5Check (Proxy :: Proxy LocalBuildInfo) 0x618ab257e99d0b21c617e1f8c39a5a4b
3333
#endif
3434
]
3535

Cabal/src/Distribution/Simple/GHC.hs

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -707,33 +707,36 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
707707
-- build any C sources
708708
unless (not has_code || null (cSources libBi)) $ do
709709
info verbosity "Building C Sources..."
710-
sequence_
711-
[ do let baseCcOpts = Internal.componentCcGhcOptions verbosity implInfo
712-
lbi libBi clbi relLibTargetDir filename
713-
vanillaCcOpts = if isGhcDynamic
714-
-- Dynamic GHC requires C sources to be built
715-
-- with -fPIC for REPL to work. See #2207.
716-
then baseCcOpts { ghcOptFPic = toFlag True }
717-
else baseCcOpts
718-
profCcOpts = vanillaCcOpts `mappend` mempty {
719-
ghcOptProfilingMode = toFlag True,
720-
ghcOptObjSuffix = toFlag "p_o"
721-
}
722-
sharedCcOpts = vanillaCcOpts `mappend` mempty {
723-
ghcOptFPic = toFlag True,
724-
ghcOptDynLinkMode = toFlag GhcDynamicOnly,
725-
ghcOptObjSuffix = toFlag "dyn_o"
726-
}
727-
odir = fromFlag (ghcOptObjDir vanillaCcOpts)
728-
createDirectoryIfMissingVerbose verbosity True odir
729-
let runGhcProgIfNeeded ccOpts = do
730-
needsRecomp <- checkNeedsRecompilation filename ccOpts
731-
when needsRecomp $ runGhcProg ccOpts
732-
runGhcProgIfNeeded vanillaCcOpts
733-
unless forRepl $
734-
whenSharedLib forceSharedLib (runGhcProgIfNeeded sharedCcOpts)
735-
unless forRepl $ whenProfLib (runGhcProgIfNeeded profCcOpts)
736-
| filename <- cSources libBi]
710+
let (cSrcs', others) = partition (\filepath -> ".c"`isSuffixOf` filepath) (cSources libBi)
711+
unless (null others) $ do
712+
let files = intercalate ", " others
713+
warn verbosity $ "The following files listed in c-sources will not be used: " <> files
714+
forM_ cSrcs' $ \filename -> do
715+
let baseCcOpts = Internal.componentCcGhcOptions verbosity implInfo
716+
lbi libBi clbi relLibTargetDir filename
717+
vanillaCcOpts = if isGhcDynamic
718+
-- Dynamic GHC requires C sources to be built
719+
-- with -fPIC for REPL to work. See #2207.
720+
then baseCcOpts { ghcOptFPic = toFlag True }
721+
else baseCcOpts
722+
profCcOpts = vanillaCcOpts `mappend` mempty {
723+
ghcOptProfilingMode = toFlag True,
724+
ghcOptObjSuffix = toFlag "p_o"
725+
}
726+
sharedCcOpts = vanillaCcOpts `mappend` mempty {
727+
ghcOptFPic = toFlag True,
728+
ghcOptDynLinkMode = toFlag GhcDynamicOnly,
729+
ghcOptObjSuffix = toFlag "dyn_o"
730+
}
731+
odir = fromFlag (ghcOptObjDir vanillaCcOpts)
732+
createDirectoryIfMissingVerbose verbosity True odir
733+
let runGhcProgIfNeeded ccOpts = do
734+
needsRecomp <- checkNeedsRecompilation filename ccOpts
735+
when needsRecomp $ runGhcProg ccOpts
736+
runGhcProgIfNeeded vanillaCcOpts
737+
unless forRepl $
738+
whenSharedLib forceSharedLib (runGhcProgIfNeeded sharedCcOpts)
739+
unless forRepl $ whenProfLib (runGhcProgIfNeeded profCcOpts)
737740

738741
-- build any JS sources
739742
unless (not has_code || not hasJsSupport || null (jsSources libBi)) $ do
@@ -1528,31 +1531,34 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
15281531

15291532
-- build any C sources
15301533
unless (null cSrcs) $ do
1531-
info verbosity "Building C Sources..."
1532-
sequence_
1533-
[ do let baseCcOpts = Internal.componentCcGhcOptions verbosity implInfo
1534+
info verbosity "Building C Sources..."
1535+
let (cSrcs', others) = partition (\filepath -> ".c"`isSuffixOf` filepath) cSrcs
1536+
unless (null others) $ do
1537+
let files = intercalate ", " others
1538+
warn verbosity $ "The following files listed in c-sources will not be used: " <> files
1539+
forM_ cSrcs' $ \filename -> do
1540+
let baseCcOpts = Internal.componentCcGhcOptions verbosity implInfo
15341541
lbi bnfo clbi tmpDir filename
1535-
vanillaCcOpts = if isGhcDynamic
1536-
-- Dynamic GHC requires C sources to be built
1537-
-- with -fPIC for REPL to work. See #2207.
1538-
then baseCcOpts { ghcOptFPic = toFlag True }
1539-
else baseCcOpts
1540-
profCcOpts = vanillaCcOpts `mappend` mempty {
1541-
ghcOptProfilingMode = toFlag True
1542-
}
1543-
sharedCcOpts = vanillaCcOpts `mappend` mempty {
1544-
ghcOptFPic = toFlag True,
1545-
ghcOptDynLinkMode = toFlag GhcDynamicOnly
1546-
}
1547-
opts | needProfiling = profCcOpts
1548-
| needDynamic = sharedCcOpts
1549-
| otherwise = vanillaCcOpts
1550-
odir = fromFlag (ghcOptObjDir opts)
1551-
createDirectoryIfMissingVerbose verbosity True odir
1552-
needsRecomp <- checkNeedsRecompilation filename opts
1553-
when needsRecomp $
1554-
runGhcProg opts
1555-
| filename <- cSrcs ]
1542+
let vanillaCcOpts = if isGhcDynamic
1543+
-- Dynamic GHC requires C sources to be built
1544+
-- with -fPIC for REPL to work. See #2207.
1545+
then baseCcOpts { ghcOptFPic = toFlag True }
1546+
else baseCcOpts
1547+
let profCcOpts = vanillaCcOpts `mappend` mempty {
1548+
ghcOptProfilingMode = toFlag True
1549+
}
1550+
let sharedCcOpts = vanillaCcOpts `mappend` mempty {
1551+
ghcOptFPic = toFlag True,
1552+
ghcOptDynLinkMode = toFlag GhcDynamicOnly
1553+
}
1554+
let opts | needProfiling = profCcOpts
1555+
| needDynamic = sharedCcOpts
1556+
| otherwise = vanillaCcOpts
1557+
let odir = fromFlag (ghcOptObjDir opts)
1558+
createDirectoryIfMissingVerbose verbosity True odir
1559+
needsRecomp <- checkNeedsRecompilation filename opts
1560+
when needsRecomp $
1561+
runGhcProg opts
15561562

15571563
-- TODO: problem here is we need the .c files built first, so we can load them
15581564
-- with ghci, but .c files can depend on .h files generated by ghc by ffi

0 commit comments

Comments
 (0)