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