@@ -5,7 +5,8 @@ module Distribution.Simple.GHC.Build where
55import Distribution.Compat.Prelude
66import Prelude ()
77
8- import Control.Monad.IO.Class
8+ import qualified Distribution.Compat.Graph as Graph
9+
910import Distribution.PackageDescription as PD hiding (buildInfo )
1011import Distribution.Simple.Build.Inputs
1112import Distribution.Simple.Flag (Flag )
@@ -25,6 +26,8 @@ import Distribution.Utils.NubList (fromNubListR)
2526import Distribution.Utils.Path
2627
2728import Distribution.Verbosity (VerbosityHandles , mkVerbosity , verbosityHandles )
29+
30+ import Control.Monad.IO.Class
2831import System.FilePath (splitDirectories )
2932
3033{- Note [Build Target Dir vs Target Dir]
@@ -75,7 +78,7 @@ build numJobs verbHandles pkg_descr pbci = do
7578 verbosity = mkVerbosity verbHandles $ buildVerbosity pbci
7679 isLib = buildIsLib pbci
7780 lbi = localBuildInfo pbci
78- bi = buildBI pbci
81+ comp = buildComponent pbci
7982 clbi = buildCLBI pbci
8083 isIndef = componentIsIndefinite clbi
8184 mbWorkDir = mbWorkDirLBI lbi
@@ -118,9 +121,35 @@ build numJobs verbHandles pkg_descr pbci = do
118121 let wantedWays@ (wantedLibWays, wantedFLibWay, wantedExeWay) = buildWays lbi
119122
120123 -- Ways which are needed due to the compiler configuration
121- let doingTH = usesTemplateHaskellOrQQ bi
124+ let doingTH =
125+ -- Does this component, or another component that (transitively) depends
126+ -- on this component, use TemplateHaskell or QuasiQuotes?
127+ --
128+ -- Ticket #7684 showed that we need to take into account intra-package
129+ -- dependencies.
130+ any usesTemplateHaskellOrQQ thisCompAndReverseDepsBuildInfos
131+
132+ -- The BuildInfos for this component and all of the components that
133+ -- transitively depend on it (its reverse dependencies).
134+ thisCompAndReverseDepsBuildInfos =
135+ [ componentBuildInfo revDepComp
136+ | let compUnitId = componentUnitId clbi
137+ , -- 'revClosure' retrieves components that depend on this component.
138+ revDepCLBI <- fromMaybe [clbi] $ Graph. revClosure (componentGraph lbi) [compUnitId]
139+ , -- Use 'lookupComponent' here; don't use any function that goes via
140+ -- 'getComponent' (e.g. mkTargetInfo or unitIdTarget'), as that will
141+ -- tiresomely cause an error for 'detailed-0.9' test-suites because
142+ -- 'testSuiteLibV09AsLibAndExe' creates a stub PackageDescription with
143+ -- most components zeroed out.
144+ --
145+ -- The implementation below means we will get 'Nothing' when the
146+ -- current component is a 'detailed-0.9' test-suite, which is fine
147+ -- as nothing can depend on a test-suite.
148+ Just revDepComp <- [lookupComponent pkg_descr $ componentLocalName revDepCLBI]
149+ ]
150+
122151 defaultGhcWay = compilerBuildWay (buildCompiler pbci)
123- wantedModBuildWays = case buildComponent pbci of
152+ wantedModBuildWays = case comp of
124153 CLib _ -> wantedLibWays isIndef
125154 CFLib fl -> [wantedFLibWay (withDynFLib fl)]
126155 CExe _ -> [wantedExeWay]
@@ -129,7 +158,7 @@ build numJobs verbHandles pkg_descr pbci = do
129158 finalModBuildWays =
130159 wantedModBuildWays
131160 ++ [defaultGhcWay | doingTH && defaultGhcWay `notElem` wantedModBuildWays]
132- compNameStr = showComponentName $ componentName $ buildComponent pbci
161+ compNameStr = showComponentName $ componentName comp
133162
134163 liftIO $ info verbosity (" Wanted module build ways(" ++ compNameStr ++ " ): " ++ show wantedModBuildWays)
135164 liftIO $ info verbosity (" Final module build ways(" ++ compNameStr ++ " ): " ++ show finalModBuildWays)
0 commit comments