@@ -115,13 +115,13 @@ import Development.IDE.GHC.Compat.CmdLine
115
115
import GHC.Driver.Errors.Types
116
116
import GHC.Driver.Env (hscSetActiveUnitId , hsc_all_home_unit_ids )
117
117
import GHC.Driver.Make (checkHomeUnitsClosed )
118
- #endif
119
118
import GHC.Unit.State
120
- import qualified Data.List.NonEmpty as NE
121
- import GHC.ResponseFile
122
119
import GHC.Unit.Env
123
120
import GHC.Types.Error (errMsgDiagnostic )
124
121
import GHC.Data.Bag
122
+ #endif
123
+ import GHC.ResponseFile
124
+ import qualified Data.List.NonEmpty as NE
125
125
126
126
data Log
127
127
= LogSettingInitialDynFlags
@@ -843,7 +843,7 @@ newComponentCache recorder exts cradlePath cfp hsc_env old_cis new_cis = do
843
843
getSession
844
844
#else
845
845
-- getOptions is enough to initialize units on GHC <9.2
846
- pure $ hscSetFlags df hsc_env { hsc_IC = (hsc_IC hsc_env) { ic_dflags = init_df } }
846
+ pure $ hscSetFlags df hsc_env { hsc_IC = (hsc_IC hsc_env) { ic_dflags = df } }
847
847
#endif
848
848
henv <- newFunc thisEnv uids
849
849
let targetEnv = ([] , Just henv)
@@ -866,9 +866,17 @@ newComponentCache recorder exts cradlePath cfp hsc_env old_cis new_cis = do
866
866
| alreadyIncluded = xs
867
867
| otherwise = let (as,bs) = break inIncludePath xs
868
868
in case bs of
869
- [] -> as
869
+ [] ->
870
+ -- There is no appropriate target to add the file to, so pick one randomly
871
+ case as of
872
+ [] -> []
873
+ ((ctargets,res@ (targetEnv, targetDepends)): xs) ->
874
+ let x = (TargetDetails (TargetFile cfp) targetEnv targetDepends [cfp] : ctargets, res)
875
+ in x: xs
876
+ -- There is a component which could have this file in its include path
877
+ -- pick one of these components
870
878
((ctargets,res@ (targetEnv, targetDepends)): bs) ->
871
- let b = (TargetDetails (TargetFile cfp) targetEnv targetDepends [cfp] : ctargets, res) -- todo what is componentFP used for
879
+ let b = (TargetDetails (TargetFile cfp) targetEnv targetDepends [cfp] : ctargets, res)
872
880
in as ++ (b: bs)
873
881
where
874
882
alreadyIncluded = any (any (cfp == ) . concatMap targetLocations . fst ) xs
@@ -1066,7 +1074,7 @@ setOptions (ComponentOptions theOpts compRoot _) dflags = do
1066
1074
((theOpts',errs,warns),units) <- processCmdLineP unit_flags [] (map noLoc theOpts)
1067
1075
case NE. nonEmpty units of
1068
1076
Just us -> initMulti us
1069
- Nothing -> NE. singleton <$> initOne (map unLoc theOpts')
1077
+ Nothing -> ( NE. :| [] ) <$> initOne (map unLoc theOpts')
1070
1078
where
1071
1079
initMulti unitArgFiles =
1072
1080
forM unitArgFiles $ \ f -> do
0 commit comments